Updated grammar

This commit is contained in:
Boolean-True 2024-05-02 13:29:00 +02:00
parent eea1af45a4
commit 9738fee630

View File

@ -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