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)* '}';
var : type id ';' | type id '=' expr';';
var : type id ';' | type id assignSign expr';';
assignSign : '=' | '+=' | '-=' | '*=';
returntype : type | VOID;
type : INT | BOOL | CHAR;
@ -26,23 +27,29 @@ stmt : 'if' '(' expr ')' block ('else' block)? #If
| stmtexpr #StatementExpressionstmt
;
stmtexpr : id '=' expr ';' #Assign
stmtexpr : id assignSign expr ';' #Assignment
| methCall ';' #MethodCall
| NEW type '(' args? ')' #New
;
expr : expr binaryOp expr #BinaryOperation
| unaryOp expr #UnaryOperation
| literal #Constant
| '(' expr ')' #Expression
| methCall #MethodCallExpression
| id #Identifier
| fieldId #Identifier
| stmtexpr #StatementExpressionexpr
| NULL #Null
;
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)*;
literal : NUMBER | BOOLEANLITERAL | CHARLITERAL;
@ -52,6 +59,7 @@ id : IDENTIFIER;
PUBLIC : 'public';
NEW : 'new';
NULL : 'null';
SUB : '-';
ADD : '+';
@ -64,6 +72,7 @@ EQ : '==';
NE : '!=';
AND : '&&';
OR : '||';
NOT : '!';
INT : 'int';

View File

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