From 9738fee6300157b941cee794646e2911000f5132 Mon Sep 17 00:00:00 2001 From: Boolean-True Date: Thu, 2 May 2024 13:29:00 +0200 Subject: [PATCH] Updated grammar --- src/main/antlr/Decaf.g4 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/antlr/Decaf.g4 b/src/main/antlr/Decaf.g4 index 13e5881..547838e 100644 --- a/src/main/antlr/Decaf.g4 +++ b/src/main/antlr/Decaf.g4 @@ -2,19 +2,21 @@ grammar Decaf; program : (class)+; -class : PUBLIC? 'class' id '{' (var | meth)* '}'; +class : PUBLIC? 'class' id '{' (field | meth)* '}'; -var : type id ';' | type id assignSign expr';'; +field : type id ';'; +localVar : type id ';'; assignSign : '=' | '+=' | '-=' | '*='; returntype : type | VOID; type : INT | BOOL | CHAR; -meth : PUBLIC? returntype id '(' params? ')' block | mainmeth; +meth : PUBLIC? returntype id '(' params? ')' block | mainmeth | constructor; mainmeth : PUBLIC 'static' 'void' 'main' '(' 'String[] args' ')' block; +constructor: PUBLIC? id '(' params? ')' block; params : param (',' param)*; param : type id; -block : '{' (var | stmt)* '}'; +block : '{' (localVar | stmt)* '}'; stmt : 'if' '(' expr ')' block ('else' block)? #If | 'for' '(' expr ';' expr ';' expr ')' block #For