Decaf Changes - Plümi Patch

This commit is contained in:
David Mueller 2024-05-08 13:54:32 +02:00
parent 34b33d7353
commit 7cbde86ca3

View File

@ -3,11 +3,11 @@ grammar Decaf;
program: classdecl+;
//class identifier{...}
classdecl: AccessModifierPublic? 'class' Identifier OpenCurlyBracket (constuctorDecl|fieldDecl|methodDecl)* ClosedCurlyBracket;
constuctorDecl: AccessModifierPublic? Identifier OpenRoundBracket parameterList? ClosedRoundBracket block; //Maybe not needed
classdecl: AccessModifierPublic? 'class' Identifier OpenCurlyBracket (constuctorDecl|fieldDecl|methodDecl)*(MainMethodDecl block)? ClosedCurlyBracket;
constuctorDecl: AccessModifierPublic? Identifier OpenRoundBracket parameterList? ClosedRoundBracket block; //Method without
//Method and FieldVar
methodDecl: MainMethodDecl block | AccessModifierPublic? (type | Void) Identifier OpenRoundBracket parameterList? ClosedRoundBracket block;
methodDecl: AccessModifierPublic? (type | Void) Identifier OpenRoundBracket parameterList? ClosedRoundBracket block;
fieldDecl: AccessModifierPublic? type Identifier Semicolon;
//Parameters
@ -17,16 +17,20 @@ parameter: type Identifier;
//property, object.a, 3+1, a = 3
expression: subExpression | binaryExpr;
//subExpression to dissolve left-recusion
subExpression: This | Identifier | instVar | value | stmtExpr | notExpr | OpenRoundBracket expression ClosedRoundBracket;
notExpr: Not expression;
subExpression: This | assignableExpr | stmtExpr | OpenRoundBracket subExpression ClosedRoundBracket;
assignableExpr: Identifier | instVar;
instVar: This Dot Identifier | (This Dot)? (Identifier Dot)+ Identifier;
instVar: subReceiver? receivingMethod* Identifier;
//.trim().toLength().toLowerCase().count ...
methodCall: receiver? receivingMethod* Identifier OpenRoundBracket argumentList ClosedRoundBracket;
argumentList: expression? | expression (Comma expression)*?;
argumentList: expression? | expression (Comma expression)+;
binaryExpr: calcExpr | nonCalcExpr;
subReceiver: ((This | newDecl | Identifier) Dot);
receiver: ((This | instVar | newDecl | Identifier) Dot);
receivingMethod: Identifier OpenRoundBracket argumentList ClosedRoundBracket Dot;
binaryExpr: calcExpr | nonCalcExpr| value | Not binaryExpr;
calcExpr: calcExpr LineOperator dotExpr | dotExpr;
dotExpr: dotExpr DotOperator dotSubExpr | dotSubExpr;
@ -44,14 +48,14 @@ statement: returnStmt Semicolon | localVarDecl Semicolon | block | whileStmt | i
returnStmt: Return (expression)?;
localVarDecl: type Identifier (Assign expression)?;
block: OpenCurlyBracket statement* ClosedCurlyBracket;
whileStmt: While OpenRoundBracket expression ClosedRoundBracket block;
whileStmt: While OpenRoundBracket expression ClosedRoundBracket statement;
ifElseStmt: ifStmt elseStmt?;
ifStmt: If OpenRoundBracket expression ClosedRoundBracket statement;
elseStmt: Else statement;
assign: assignableExpr Assign expression;
newDecl: New Identifier OpenRoundBracket argumentList ClosedRoundBracket;
receiver: ((This | instVar | newDecl | Identifier) Dot);
receivingMethod: Identifier OpenRoundBracket argumentList ClosedRoundBracket Dot;
type: Int | Boolean | Char | Identifier;
value: IntValue | BooleanValue | CharValue | NullValue;
@ -59,11 +63,7 @@ value: IntValue | BooleanValue | CharValue | NullValue;
AccessModifierPublic : 'public' ;
MainMethodDecl : 'public static void main(String[] args)';
//Types
Void : 'void';
Int : 'int';
Boolean : 'bool';
Char : 'char';
//Operators
DotOperator : Multipilkation | Division | Modulo;
@ -102,7 +102,6 @@ This : 'this';
While : 'while';
If : 'if';
Else : 'else';
For : 'for';
Return : 'return';
New : 'new';
@ -112,6 +111,12 @@ fragment Numeric: [0-9];
fragment ValidIdentSymbols : Alpabetic|Numeric|'$'|'_';
Identifier: Alpabetic ValidIdentSymbols*;
//Types
Void : 'void';
Int : 'int';
Boolean : 'bool';
Char : 'char';
//Values
IntValue : ('+'|'-')*[0-9]+;
CharValue: '\''~[\r\n]?'\'';