Compare commits
No commits in common. "dfa5588514bc46d03b6fe8ca2ea524c53543aeed" and "56ee3602b500f6588dabb26d484c23c95ac6f62d" have entirely different histories.
dfa5588514
...
56ee3602b5
@ -3,11 +3,11 @@ grammar Decaf;
|
|||||||
program: classdecl+;
|
program: classdecl+;
|
||||||
|
|
||||||
//class identifier{...}
|
//class identifier{...}
|
||||||
classdecl: AccessModifierPublic? 'class' Identifier OpenCurlyBracket (constuctorDecl|fieldDecl|methodDecl)*(MainMethodDecl block)? ClosedCurlyBracket;
|
classdecl: AccessModifierPublic? 'class' Identifier OpenCurlyBracket (constuctorDecl|fieldDecl|methodDecl)* ClosedCurlyBracket;
|
||||||
constuctorDecl: AccessModifierPublic? Identifier OpenRoundBracket parameterList? ClosedRoundBracket block; //Method without
|
constuctorDecl: AccessModifierPublic? Identifier OpenRoundBracket parameterList? ClosedRoundBracket block; //Maybe not needed
|
||||||
|
|
||||||
//Method and FieldVar
|
//Method and FieldVar
|
||||||
methodDecl: AccessModifierPublic? (type | Void) Identifier OpenRoundBracket parameterList? ClosedRoundBracket block;
|
methodDecl: MainMethodDecl block | AccessModifierPublic? (type | Void) Identifier OpenRoundBracket parameterList? ClosedRoundBracket block;
|
||||||
fieldDecl: AccessModifierPublic? type Identifier Semicolon;
|
fieldDecl: AccessModifierPublic? type Identifier Semicolon;
|
||||||
|
|
||||||
//Parameters
|
//Parameters
|
||||||
@ -17,20 +17,16 @@ 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 | assignableExpr | stmtExpr | OpenRoundBracket subExpression ClosedRoundBracket;
|
subExpression: This | Identifier | instVar | value | stmtExpr | notExpr | OpenRoundBracket expression ClosedRoundBracket;
|
||||||
|
notExpr: Not expression;
|
||||||
assignableExpr: Identifier | instVar;
|
assignableExpr: Identifier | instVar;
|
||||||
instVar: subReceiver? receivingMethod* Identifier;
|
instVar: This Dot Identifier | (This Dot)? (Identifier Dot)+ 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)*?;
|
||||||
|
|
||||||
subReceiver: ((This | newDecl | Identifier) Dot);
|
binaryExpr: calcExpr | nonCalcExpr;
|
||||||
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;
|
||||||
@ -48,14 +44,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 statement;
|
whileStmt: While OpenRoundBracket expression ClosedRoundBracket block;
|
||||||
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;
|
||||||
|
|
||||||
@ -63,7 +59,11 @@ 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,6 +102,7 @@ This : 'this';
|
|||||||
While : 'while';
|
While : 'while';
|
||||||
If : 'if';
|
If : 'if';
|
||||||
Else : 'else';
|
Else : 'else';
|
||||||
|
For : 'for';
|
||||||
Return : 'return';
|
Return : 'return';
|
||||||
New : 'new';
|
New : 'new';
|
||||||
|
|
||||||
@ -111,12 +112,6 @@ 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]?'\'';
|
||||||
|
Loading…
Reference in New Issue
Block a user