Merge branch 'refs/heads/main' into testsuites

This commit is contained in:
JonathanFleischmann 2024-05-02 11:18:13 +02:00
commit db80632604
2 changed files with 14 additions and 6 deletions

View File

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

View File

@ -11,6 +11,5 @@ public enum Operator {
EQ, EQ,
NE, NE,
AND, AND,
OR, OR
NOT
} }