mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 09:08:05 +00:00
Update grammar
This commit is contained in:
parent
a1cc591220
commit
eea1af45a4
@ -4,7 +4,8 @@ program : (class)+;
|
|||||||
|
|
||||||
class : PUBLIC? 'class' id '{' (var | meth)* '}';
|
class : PUBLIC? 'class' id '{' (var | meth)* '}';
|
||||||
|
|
||||||
var : type id ';' | type id '=' expr';';
|
var : type id ';' | type id assignSign expr';';
|
||||||
|
assignSign : '=' | '+=' | '-=' | '*=';
|
||||||
returntype : type | VOID;
|
returntype : type | VOID;
|
||||||
type : INT | BOOL | CHAR;
|
type : INT | BOOL | CHAR;
|
||||||
|
|
||||||
@ -26,23 +27,29 @@ stmt : 'if' '(' expr ')' block ('else' block)? #If
|
|||||||
| stmtexpr #StatementExpressionstmt
|
| stmtexpr #StatementExpressionstmt
|
||||||
;
|
;
|
||||||
|
|
||||||
stmtexpr : id '=' expr ';' #Assign
|
stmtexpr : id assignSign expr ';' #Assignment
|
||||||
| methCall ';' #MethodCall
|
| methCall ';' #MethodCall
|
||||||
| NEW type '(' args? ')' #New
|
| NEW type '(' args? ')' #New
|
||||||
;
|
;
|
||||||
|
|
||||||
expr : expr binaryOp expr #BinaryOperation
|
expr : expr binaryOp expr #BinaryOperation
|
||||||
|
| unaryOp expr #UnaryOperation
|
||||||
| literal #Constant
|
| literal #Constant
|
||||||
| '(' expr ')' #Expression
|
| '(' expr ')' #Expression
|
||||||
| methCall #MethodCallExpression
|
| methCall #MethodCallExpression
|
||||||
| id #Identifier
|
| fieldId #Identifier
|
||||||
| stmtexpr #StatementExpressionexpr
|
| stmtexpr #StatementExpressionexpr
|
||||||
|
| NULL #Null
|
||||||
;
|
;
|
||||||
|
|
||||||
binaryOp : ADD | SUB | MUL | GT | LT | GE | LE | EQ | NE | AND | OR | NOT;
|
binaryOp : ADD | SUB | MUL | GT | LT | GE | LE | EQ | NE | AND | OR | NOT;
|
||||||
|
unaryOp : SUB | NOT;
|
||||||
|
|
||||||
|
fieldId : ('this' '.')? (recipient '.')* id;
|
||||||
|
|
||||||
methCall : id '(' args? ')';
|
methCall : ('this' '.')? (recipient '.')* methName;
|
||||||
|
recipient : methName | id;
|
||||||
|
methName : id '(' args? ')';
|
||||||
args : expr (',' expr)*;
|
args : expr (',' expr)*;
|
||||||
|
|
||||||
literal : NUMBER | BOOLEANLITERAL | CHARLITERAL;
|
literal : NUMBER | BOOLEANLITERAL | CHARLITERAL;
|
||||||
@ -52,6 +59,7 @@ id : IDENTIFIER;
|
|||||||
|
|
||||||
PUBLIC : 'public';
|
PUBLIC : 'public';
|
||||||
NEW : 'new';
|
NEW : 'new';
|
||||||
|
NULL : 'null';
|
||||||
|
|
||||||
SUB : '-';
|
SUB : '-';
|
||||||
ADD : '+';
|
ADD : '+';
|
||||||
@ -64,6 +72,7 @@ EQ : '==';
|
|||||||
NE : '!=';
|
NE : '!=';
|
||||||
AND : '&&';
|
AND : '&&';
|
||||||
OR : '||';
|
OR : '||';
|
||||||
|
|
||||||
NOT : '!';
|
NOT : '!';
|
||||||
|
|
||||||
INT : 'int';
|
INT : 'int';
|
||||||
|
@ -11,6 +11,5 @@ public enum Operator {
|
|||||||
EQ,
|
EQ,
|
||||||
NE,
|
NE,
|
||||||
AND,
|
AND,
|
||||||
OR,
|
OR
|
||||||
NOT
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user