Changes to the Grammar
This commit is contained in:
parent
1cd4d87a94
commit
9166d87afd
4
.idea/compiler.xml
generated
4
.idea/compiler.xml
generated
@ -6,8 +6,10 @@
|
|||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
<outputRelativeToContentRoot value="true" />
|
<outputRelativeToContentRoot value="true" />
|
||||||
<module name="NichtHaskell" />
|
|
||||||
</profile>
|
</profile>
|
||||||
</annotationProcessing>
|
</annotationProcessing>
|
||||||
|
<bytecodeTargetLevel>
|
||||||
|
<module name="NichtHaskell" target="20" />
|
||||||
|
</bytecodeTargetLevel>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
@ -1,4 +1,3 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="MavenProjectsManager">
|
<component name="MavenProjectsManager">
|
||||||
|
@ -3,32 +3,33 @@ 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|localVarDecl|methodDecl)*(MainMethodDecl block)? ClosedCurlyBracket;
|
||||||
constuctorDecl: AccessModifierPublic? Identifier OpenRoundBracket parameterList? ClosedRoundBracket block; //Method without
|
constuctorDecl: AccessModifierPublic? Identifier OpenRoundBracket parameterList? ClosedRoundBracket block;
|
||||||
|
|
||||||
//Method and FieldVar
|
//Method and FieldVar
|
||||||
methodDecl: AccessModifierPublic? (type | Void) Identifier OpenRoundBracket parameterList? ClosedRoundBracket block;
|
methodDecl: AccessModifierPublic? (type | Void) Identifier OpenRoundBracket parameterList? ClosedRoundBracket block;
|
||||||
fieldDecl: AccessModifierPublic? type Identifier Semicolon;
|
|
||||||
|
|
||||||
//Parameters
|
//Parameters
|
||||||
parameterList: parameter(Comma parameter)*;
|
parameterList: parameter(Comma parameter)*;
|
||||||
parameter: type Identifier;
|
parameter: type Identifier;
|
||||||
|
|
||||||
|
argumentList: expression? | expression (Comma expression)+;
|
||||||
//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 | assignableExpr | stmtExpr | OpenRoundBracket subExpression ClosedRoundBracket;
|
||||||
assignableExpr: Identifier | instVar;
|
|
||||||
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)+;
|
|
||||||
|
statement: returnStmt Semicolon | localVarDecl Semicolon | block | whileStmt | ifElseStmt | stmtExpr Semicolon;
|
||||||
|
|
||||||
|
stmtExpr: assign | newDecl | methodCall;
|
||||||
|
|
||||||
|
assignableExpr: Identifier | instVar;
|
||||||
|
|
||||||
subReceiver: ((This | newDecl | Identifier) Dot);
|
subReceiver: ((This | newDecl | Identifier) Dot);
|
||||||
receiver: ((This | instVar | newDecl | Identifier) Dot);
|
|
||||||
receivingMethod: Identifier OpenRoundBracket argumentList ClosedRoundBracket Dot;
|
|
||||||
|
|
||||||
|
instVar: subReceiver? receivingMethod* Identifier;
|
||||||
|
|
||||||
binaryExpr: calcExpr | nonCalcExpr| value | Not binaryExpr;
|
binaryExpr: calcExpr | nonCalcExpr| value | Not binaryExpr;
|
||||||
|
|
||||||
@ -38,15 +39,11 @@ dotSubExpr: IntValue | Identifier | instVar | methodCall | OpenRoundBracket calc
|
|||||||
nonCalcExpr: subExpression nonCalcOperator expression;
|
nonCalcExpr: subExpression nonCalcOperator expression;
|
||||||
nonCalcOperator: LogicalOpertor | ComparisonOperator;
|
nonCalcOperator: LogicalOpertor | ComparisonOperator;
|
||||||
|
|
||||||
//Statement but also expression
|
BooleanValue: 'true'|'false';
|
||||||
//a = expr, new Object(), method(param1)
|
NullValue: 'null';
|
||||||
stmtExpr: assign | newDecl | methodCall;
|
|
||||||
|
|
||||||
//Statements
|
|
||||||
//int a, {...}, while(a > 10){...}, if(...){...} else if{...} else{...}
|
|
||||||
statement: returnStmt Semicolon | localVarDecl Semicolon | block | whileStmt | ifElseStmt | stmtExpr Semicolon;
|
|
||||||
returnStmt: Return (expression)?;
|
returnStmt: Return (expression)?;
|
||||||
localVarDecl: type Identifier (Assign expression)?;
|
localVarDecl: AccessModifierPublic? type Identifier (Assign expression)? Semicolon;
|
||||||
block: OpenCurlyBracket statement* ClosedCurlyBracket;
|
block: OpenCurlyBracket statement* ClosedCurlyBracket;
|
||||||
whileStmt: While OpenRoundBracket expression ClosedRoundBracket statement;
|
whileStmt: While OpenRoundBracket expression ClosedRoundBracket statement;
|
||||||
ifElseStmt: ifStmt elseStmt?;
|
ifElseStmt: ifStmt elseStmt?;
|
||||||
@ -54,6 +51,8 @@ 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;
|
||||||
@ -63,7 +62,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;
|
||||||
@ -105,24 +108,23 @@ Else : 'else';
|
|||||||
Return : 'return';
|
Return : 'return';
|
||||||
New : 'new';
|
New : 'new';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Values
|
||||||
|
IntValue : ('+'|'-')*[0-9]+;
|
||||||
|
CharValue: '\''~[\r\n]?'\'';
|
||||||
|
|
||||||
|
|
||||||
//Identifier
|
//Identifier
|
||||||
fragment Alpabetic : [a-zA-Z];
|
fragment Alpabetic : [a-zA-Z];
|
||||||
fragment Numeric: [0-9];
|
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
|
|
||||||
IntValue : ('+'|'-')*[0-9]+;
|
|
||||||
CharValue: '\''~[\r\n]?'\'';
|
|
||||||
BooleanValue: 'true'|'false';
|
|
||||||
NullValue: 'null';
|
|
||||||
|
|
||||||
//Whitespace? Right into the trash it gooeesss
|
//Whitespace? Right into the trash it gooeesss
|
||||||
WS : [ \t\r\n] -> skip;
|
WS : [ \t\r\n] -> skip;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user