Skip to content

Instantly share code, notes, and snippets.

@RaneWallin
Created November 1, 2020 00:28
Show Gist options
  • Save RaneWallin/03b0d9084b4f2b5ea1c8e3e2b70298b8 to your computer and use it in GitHub Desktop.
Save RaneWallin/03b0d9084b4f2b5ea1c8e3e2b70298b8 to your computer and use it in GitHub Desktop.
Backus Normal/Nauer Form example
<program> ::= <statement_list>
<statement_list> ::= <variable_def>
| <assignment_statement>
| <conditional_statement>
| <loop_statement>
| <block_statement>
| <variable_def> <statement_list>
| <assignment_statement> <statement_list>
| <conditional_statement> <statement_list>
| <loop_statement> <statement_list>
| <block_statement> <statement_list>
<variable_def> ::= def <id> : <type>;
<assignment_statement> ::= <id> = <expression_list>;
<expression_list> ::= <math_expression>
| <math_expression> <math_operator> <math_expression>
| <function>
<condition_statement> ::= if [<bool_statement>] then <block_statement>
<bool_statement> ::= !<bool_statement>
| <conditional_expression>
<conditional_expression> ::= <math_expression> <relational_operator> <math_expression>
<math_expression> ::= <digit_list>
| (<math_expression>)
| <math_expression> <math_operator> <math_expression>
<loop_statement> ::= while [<conditional_statement>] <block_statement>
<block_statement> ::= {};
| { <statement_list> };
<math_operator> ::= ‘+’ | ‘-’ | ‘*’ | ‘/’ | ‘^’ | ‘%’
<relational_operator> ::= ‘=’ | ‘!=’ | ‘<’ | ‘>’ | ‘<=’ | ‘>=’
<function> ::= <id>();
<id> ::= <character_list>
<character_list> ::= <character>
| <character> <character_list>
<character> ::= <letter> | <number>
<letter> ::= ‘a’ | ‘b’ | ‘c’ | ‘d’ | ‘e’ | ‘f’ | ‘g’ | ‘h’ | ‘i’ | ‘j’ | ‘k’ | ‘l’
| ‘m’ | ‘n’ | ‘o’ | ‘p’ | ‘q’ | ‘r’ | ‘s’ | ‘t’ | ‘u’ | ‘v’ | ‘x’
| ‘y’ | ‘z’ | ‘A’ | ‘B’ | ‘C’ | ‘D’ | ‘E’ | ‘F’ | ‘G’ | ‘H’ | ‘I’
| ‘J’ | ‘K’ | ‘L’ | ‘M’ | ‘N’ | ‘O’ | ‘P’ | ‘Q’ | ‘R’ | ‘S’
| ‘T’ | ‘U’ | ‘V’ | ‘X’ | ‘Y’ | ‘Z’
<signed_number> ::= ‘-’ <number>
| <number>
<number> ::= ‘0’ | ‘1’ | ‘2’ | ‘3’ | ‘4’ | ‘5’ | ‘6’ | ‘7’ | ‘8’ | ‘9’
<digit_list> ::= <signed_number>
| <signed_number> <digit_list>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment