From d36d51429d604f0ab3b2076c4c05e28ebf9b52c5 Mon Sep 17 00:00:00 2001 From: Melodi <62381002+Melodi17@users.noreply.github.com> Date: Sat, 9 Aug 2025 00:16:57 +1000 Subject: updated block syntax and removed body grammar, fixed issue with if requiring an else branch --- Compiler/CGrammar.g4 | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'Compiler/CGrammar.g4') diff --git a/Compiler/CGrammar.g4 b/Compiler/CGrammar.g4 index aec4694..484cc90 100644 --- a/Compiler/CGrammar.g4 +++ b/Compiler/CGrammar.g4 @@ -14,11 +14,6 @@ function : 'int' name=ID '(' ')' block ; -body - : statement - | block - ; - block : '{' block_item* '}' ; @@ -30,8 +25,9 @@ block_item statement : 'return' expression ';' #returnStatement - | 'if' '(' expression ')' then=body ('else' else=body) #ifStatement + | 'if' '(' expression ')' then=statement ('else' else=statement)? #ifStatement | expression #expressionStatement + | block #blockStatement ; -- cgit v1.3.1