Compare commits

..

2 Commits

Author SHA1 Message Date
David Mueller
dfa5588514 Merge remote-tracking branch 'origin/master' 2024-05-08 13:54:52 +02:00
David Mueller
7cbde86ca3 Decaf Changes - Plümi Patch 2024-05-08 13:54:32 +02:00

View File

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