mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 08:48:03 +00:00
Updated grammar
This commit is contained in:
parent
eea1af45a4
commit
9738fee630
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user