mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 09:08:05 +00:00
Updated grammar
This commit is contained in:
parent
eea1af45a4
commit
9738fee630
@ -2,19 +2,21 @@ grammar Decaf;
|
|||||||
|
|
||||||
program : (class)+;
|
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 : '=' | '+=' | '-=' | '*=';
|
assignSign : '=' | '+=' | '-=' | '*=';
|
||||||
returntype : type | VOID;
|
returntype : type | VOID;
|
||||||
type : INT | BOOL | CHAR;
|
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;
|
mainmeth : PUBLIC 'static' 'void' 'main' '(' 'String[] args' ')' block;
|
||||||
|
constructor: PUBLIC? id '(' params? ')' block;
|
||||||
params : param (',' param)*;
|
params : param (',' param)*;
|
||||||
param : type id;
|
param : type id;
|
||||||
|
|
||||||
block : '{' (var | stmt)* '}';
|
block : '{' (localVar | stmt)* '}';
|
||||||
|
|
||||||
stmt : 'if' '(' expr ')' block ('else' block)? #If
|
stmt : 'if' '(' expr ')' block ('else' block)? #If
|
||||||
| 'for' '(' expr ';' expr ';' expr ')' block #For
|
| 'for' '(' expr ';' expr ';' expr ')' block #For
|
||||||
|
Loading…
Reference in New Issue
Block a user