summaryrefslogtreecommitdiff
path: root/Compiler/CGrammar.g4
diff options
context:
space:
mode:
authorMelodi <62381002+Melodi17@users.noreply.github.com>2025-08-09 00:16:57 +1000
committerMelodi <62381002+Melodi17@users.noreply.github.com>2025-08-09 00:16:57 +1000
commitd36d51429d604f0ab3b2076c4c05e28ebf9b52c5 (patch)
tree9a3755684359aa041bf391f4ef5d3f30837a2271 /Compiler/CGrammar.g4
parente62b66dd08ca445d1f7e5b802a503ad3ec83b2df (diff)
updated block syntax and removed body grammar, fixed issue with if requiring an else branch
Diffstat (limited to 'Compiler/CGrammar.g4')
-rw-r--r--Compiler/CGrammar.g48
1 files changed, 2 insertions, 6 deletions
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
;