From 5cb0e18a874c397d8a331c328705a31bd9da8594 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Tue, 14 Jan 2025 23:15:27 +0100 Subject: [PATCH] Add current grammar --- README => README.md | 53 +++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 14 deletions(-) rename README => README.md (51%) diff --git a/README b/README.md similarity index 51% rename from README rename to README.md index 10ec738..58f49a7 100644 --- a/README +++ b/README.md @@ -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; +```