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