End while and if statements with the end token

This commit is contained in:
2025-01-17 10:11:40 +01:00
parent ef667e3ace
commit a79def50e5
10 changed files with 197 additions and 99 deletions

View File

@ -34,7 +34,7 @@ program = [ "type" type_definitions ";" ]
[ constant_part ]
{ procedure_definition }
[ variable_part ]
compound_statement ".";
"begin" [ statement_list ] "end" ".";
procedure_definition = "proc" ident formal_parameter_list ";" ( block | "extern" ) ";";
@ -45,14 +45,18 @@ block = [ constant_part ]
constant_part = "const" ident "=" integer { "," ident "=" integer } ";";
variable_part = "var" variable_declarations ";";
statement = compound_statement
| ident ":=" expression
statement = ident ":=" expression
| ident actual_parameter_list
| "while" condition "do" statement
| "if" expression "then" statement [ else statement ];
| while_do
| if_then_else;
while_do = "while" condition "do" [ statement_list ] "end";
if_then_else = "if" expression
"then" [ statement_list ]
[ else statement_list ] "end";
statement_list = statement {";" statement };
compound_statement = "begin" [ statement_list ] "end";
condition = "odd" expression |
expression ("="|"#"|"<"|"<="|">"|">=") expression;
@ -86,8 +90,9 @@ variable_declarations = variable_declaration { ";" variable_declaration };
variable_declaration = ident ":" type_expression;
type_expression = "array" integer "of" type_expression
| "^" type_expression
| "pointer" "to" type_expression
| "record" field_list "end"
| "union" field_list "end"
| ident;
field_list = field_declaration { ";" field_declaration };