Add current grammar
This commit is contained in:
parent
3bd4c3af6f
commit
5cb0e18a87
@ -19,39 +19,63 @@ and a possbility to compile Elna programs for different platforms.
|
||||
|
||||
## Grammar
|
||||
|
||||
```ebnf
|
||||
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
||||
letter = "A" | "B" | … | "Z" | "a" | "b" | … | "z";
|
||||
|
||||
ident = letter { letter | digit | "_" };
|
||||
integer = digit { digit };
|
||||
float = integer "." integer;
|
||||
boolean = "true" | "false";
|
||||
|
||||
program = [ "type" type_definitions ";" ]
|
||||
[ "const" ident "=" integer { "," ident "=" integer } ";"]
|
||||
[ constant_part ]
|
||||
{ procedure_definition }
|
||||
[ "var" variable_declarations ";" ]
|
||||
[ variable_part ]
|
||||
compound_statement ".";
|
||||
|
||||
procedure_definition = "procedure" ident formal_parameter_list ";" block ";";
|
||||
procedure_definition = "proc" ident formal_parameter_list ";" block ";";
|
||||
|
||||
block = [ "const" ident "=" integer { "," ident "=" integer } ";" ]
|
||||
[ "var" variable_declarations ";" ]
|
||||
block = [ constant_part ]
|
||||
[ variable_part ]
|
||||
statement;
|
||||
|
||||
statement = [ ident ":=" expression
|
||||
| ident actual_parameter_list
|
||||
| compound_statement
|
||||
| "if" condition "then" statement
|
||||
| "while" condition "do" statement ];
|
||||
constant_part = "const" ident "=" integer { "," ident "=" integer } ";";
|
||||
variable_part = "var" variable_declarations ";";
|
||||
|
||||
compound_statement = "begin" statement {";" statement } "end" ;
|
||||
statement = compound_statement
|
||||
| ident ":=" expression
|
||||
| ident actual_parameter_list
|
||||
| "while" condition "do" statement
|
||||
| "if" expression "then" statement [ else statement ];
|
||||
|
||||
statement_list = statement {";" statement };
|
||||
compound_statement = "begin" [ statement_list ] "end";
|
||||
|
||||
condition = "odd" expression |
|
||||
expression ("="|"#"|"<"|"<="|">"|">=") expression;
|
||||
|
||||
expression = [ "+"|"-"] term { ("+"|"-") term};
|
||||
comparison_operator = "=", "/=", "<", ">", "<=", ">=";
|
||||
unary_prefix = "not", "@";
|
||||
|
||||
term = factor { ("*"|"/") factor };
|
||||
expression = logical_operand { ("and" | "or") logical_operand };
|
||||
logical_operand = comparand { comparison_operator comparand };
|
||||
comparand = summand { ("+" | "-") summand };
|
||||
summand = factor { ("*" | "/") factor };
|
||||
factor = pointer { unary_prefix pointer };
|
||||
|
||||
factor = ident | integer | "(" expression ")";
|
||||
pointer = integer
|
||||
| float
|
||||
| boolean
|
||||
| "'" character "'"
|
||||
| """ { character } """
|
||||
| designator_expression { $$ = $1; }
|
||||
| "(" expression ")";
|
||||
|
||||
designator_expression = designator_expression "[" expression "]"
|
||||
| designator_expression "." ident
|
||||
| designator_expression "^"
|
||||
| ident;
|
||||
|
||||
formal_parameter_list = "(" [ variable_declarations ] ")";
|
||||
|
||||
@ -71,3 +95,4 @@ type_expression = "array" integer "of" type_expression
|
||||
field_list = field_declaration { ";" field_declaration };
|
||||
|
||||
field_declaration = ident ":" type_expression;
|
||||
```
|
Loading…
x
Reference in New Issue
Block a user