2025-09-27 17:07:46 -06:00
|
|
|
parser grammar ExprParser;
|
|
|
|
|
|
|
|
|
|
options {
|
|
|
|
|
tokenVocab=ExprLexer;
|
|
|
|
|
}
|
2025-09-27 23:07:32 -06:00
|
|
|
prog: compilationUnit EOF;
|
2025-09-27 17:07:46 -06:00
|
|
|
identifier: IDENTIFIER;
|
|
|
|
|
|
|
|
|
|
qualifiedIdentifier: identifier (Dot identifier)*;
|
|
|
|
|
|
|
|
|
|
literal: IntegerLiteral
|
|
|
|
|
| FloatingPointLiteral
|
|
|
|
|
| CharacterLiteral
|
|
|
|
|
| StringLiteral
|
|
|
|
|
| BooleanLiteral
|
|
|
|
|
| NullLiteral;
|
2025-09-27 23:07:32 -06:00
|
|
|
//Section 15.26: Assignment Operators
|
|
|
|
|
expression: unaryExpr assignmentOperator expression | conditionalExpr ;
|
|
|
|
|
|
|
|
|
|
//Highest Prescedence _Expr = expression
|
|
|
|
|
//CI cha 6
|
|
|
|
|
conditionalExpr: logicalOrExpr Question conditionalExpr Colon conditionalExpr | logicalOrExpr;
|
|
|
|
|
|
|
|
|
|
logicalOrExpr: logicalAndExpr (ConditionalOR logicalAndExpr)*;
|
|
|
|
|
|
|
|
|
|
logicalAndExpr: equalityExpr (ConditionalAND equalityExpr)*;
|
|
|
|
|
|
|
|
|
|
equalityExpr: relationalExpr ((EqualTo | NotEqualTo) relationalExpr)*;
|
|
|
|
|
|
|
|
|
|
relationalExpr: additiveExpr((LessThan | GreaterThan | LessThanEqualTo | GreaterThanEqualTo) additiveExpr | InstanceOf type)*;
|
|
|
|
|
|
|
|
|
|
additiveExpr: multiplicativeExpr((Addition | Subtraction) multiplicativeExpr)*;
|
|
|
|
|
multiplicativeExpr: unaryExpr((Multiplication | Division | Remainder) unaryExpr)*;
|
|
|
|
|
|
|
|
|
|
unaryExpr:postfixExpr |(Addition | Subtraction | LogicalComplement | BitwiseComplement | Increment | Decrement) unaryExpr | parExpression type unaryExpr;
|
|
|
|
|
|
|
|
|
|
postfixExpr: primaryExpr (Increment| Decrement| Dot IDENTIFIER | SquareBracketLeft expression SquareBracketRight | arguments)*;
|
|
|
|
|
|
|
|
|
|
primaryExpr: parExpression
|
|
|
|
|
| IntegerLiteral
|
|
|
|
|
| FloatingPointLiteral
|
|
|
|
|
| StringLiteral
|
|
|
|
|
| CharacterLiteral
|
|
|
|
|
| BooleanLiteral
|
|
|
|
|
| NullLiteral
|
|
|
|
|
| IDENTIFIER
|
|
|
|
|
| This
|
|
|
|
|
| Super (Dot IDENTIFIER)?
|
|
|
|
|
| New type arguments
|
|
|
|
|
| primitiveType (SquareBracketLeft SquareBracketRight)* Dot Class
|
|
|
|
|
| type Dot Class;
|
2025-09-27 17:07:46 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
assignmentOperator: Assignment
|
|
|
|
|
| AddAssign
|
|
|
|
|
| SubtractAssign
|
|
|
|
|
| MultiplyAssign
|
|
|
|
|
| DivideAssign
|
|
|
|
|
| BitwiseANDAssign
|
|
|
|
|
| BitwiseORAssign
|
|
|
|
|
| BitwiseXORAssign
|
|
|
|
|
| RemainderAssign
|
|
|
|
|
| LeftShiftAssign
|
|
|
|
|
| SignedRightShiftAssign
|
|
|
|
|
| UnsignedRightShiftAssign;
|
|
|
|
|
|
2025-09-27 23:07:32 -06:00
|
|
|
type: identifier (Dot identifier)* bracketsOpt | primitiveType;
|
2025-09-27 17:07:46 -06:00
|
|
|
|
|
|
|
|
statementExpression: expression;
|
|
|
|
|
|
|
|
|
|
constantExpression: expression;
|
|
|
|
|
|
2025-09-27 23:07:32 -06:00
|
|
|
identifierSuffix: SquareBracketLeft SquareBracketRight bracketsOpt Dot Class
|
|
|
|
|
|SquareBracketLeft expression SquareBracketRight
|
2025-09-27 17:07:46 -06:00
|
|
|
|arguments
|
2025-09-27 23:07:32 -06:00
|
|
|
|Dot (Class | This | Super arguments New innerCreator);
|
2025-09-27 17:07:46 -06:00
|
|
|
|
|
|
|
|
postfixOp: Increment | Decrement;
|
|
|
|
|
|
2025-09-27 23:07:32 -06:00
|
|
|
primitiveType: Byte | Short| Char | Int| Long| Float| Double| Boolean;
|
|
|
|
|
//Method arguments
|
2025-09-27 17:07:46 -06:00
|
|
|
argumentsOpt: (arguments)?;
|
|
|
|
|
|
|
|
|
|
arguments: ParenthesesLeft (expression (Comma expression)*)? ParenthesesRight;
|
|
|
|
|
|
|
|
|
|
bracketsOpt: (SquareBracketLeft SquareBracketRight)*;
|
|
|
|
|
|
|
|
|
|
creator: qualifiedIdentifier ( arrayCreatorRest | classCreatorRest);
|
|
|
|
|
|
|
|
|
|
innerCreator: identifier classCreatorRest;
|
|
|
|
|
|
|
|
|
|
arrayCreatorRest: SquareBracketLeft SquareBracketRight bracketsOpt arrayInitializer
|
2025-09-27 23:07:32 -06:00
|
|
|
| SquareBracketLeft expression SquareBracketRight (SquareBracketLeft expression SquareBracketRight)*;
|
2025-09-27 17:07:46 -06:00
|
|
|
classCreatorRest: arguments (classBody)?;
|
|
|
|
|
|
|
|
|
|
arrayInitializer: CurlyBracketLeft (variableInitializer(Comma variableInitializer)*(Comma)?)? CurlyBracketRight;
|
|
|
|
|
|
|
|
|
|
variableInitializer: arrayInitializer
|
|
|
|
|
|expression;
|
|
|
|
|
|
|
|
|
|
parExpression: ParenthesesLeft expression ParenthesesRight;
|
|
|
|
|
|
|
|
|
|
block: CurlyBracketLeft blockStatements CurlyBracketRight;
|
|
|
|
|
|
|
|
|
|
blockStatements: (blockStatement)*;
|
|
|
|
|
|
|
|
|
|
blockStatement: localVariableDeclarationStatement
|
|
|
|
|
|classOrInterfaceDeclaration
|
2025-09-27 23:07:32 -06:00
|
|
|
|(identifier Colon)? statement;
|
|
|
|
|
|
|
|
|
|
localVariableDeclarationStatement: (Final)? type variableDeclarators;
|
|
|
|
|
|
|
|
|
|
statement:completeIf | If parExpression statementIncompleteIf;
|
|
|
|
|
|
|
|
|
|
statementIncompleteIf: block
|
|
|
|
|
| If parExpression completeIf Else statementIncompleteIf
|
|
|
|
|
| For ParenthesesLeft forInit? Semicolon (expression)? Semicolon forUpdate? ParenthesesRight statement
|
|
|
|
|
| While parExpression statement
|
|
|
|
|
| Do statement While parExpression Semicolon
|
|
|
|
|
| Try block catches
|
|
|
|
|
| Try block Finally block
|
|
|
|
|
| Try block catches Finally block
|
|
|
|
|
| switchStatement
|
|
|
|
|
| Synchronized parExpression block
|
|
|
|
|
| Return (expression)? Semicolon
|
|
|
|
|
| Throw expression Semicolon
|
|
|
|
|
| Break (identifier)? Semicolon
|
|
|
|
|
| Continue (identifier)? Semicolon
|
|
|
|
|
| statementExpression Semicolon
|
|
|
|
|
| Semicolon;
|
|
|
|
|
//solve ambiguity over If()else. aka (Dangling else).
|
|
|
|
|
//this will do the longest check by looking for an else section, fincding the closest else!
|
|
|
|
|
completeIf: If parExpression completeIf Else completeIf | statementIncompleteIf;
|
|
|
|
|
|
|
|
|
|
catches: catchClause (catchClause)*;
|
2025-09-27 17:07:46 -06:00
|
|
|
|
|
|
|
|
catchClause: Catch ParenthesesLeft formalParameter ParenthesesRight block;
|
|
|
|
|
|
|
|
|
|
switchStatement: Switch parExpression CurlyBracketLeft CurlyBracketRight
|
2025-09-27 23:07:32 -06:00
|
|
|
| Switch parExpression CurlyBracketLeft switchBlockStatementGroups? CurlyBracketRight;
|
2025-09-27 17:07:46 -06:00
|
|
|
|
2025-09-27 23:07:32 -06:00
|
|
|
switchBlockStatementGroups: (switchBlockStatementGroup)*;
|
2025-09-27 17:07:46 -06:00
|
|
|
|
|
|
|
|
switchBlockStatementGroup: switchLabel blockStatements;
|
|
|
|
|
|
|
|
|
|
switchLabel: Case constantExpression Colon
|
|
|
|
|
| Default Colon;
|
|
|
|
|
moreStatementExpressions: (Comma statementExpression)*;
|
|
|
|
|
|
|
|
|
|
forInit: statementExpression moreStatementExpressions
|
|
|
|
|
| (Final)? type variableDeclarators;
|
|
|
|
|
|
|
|
|
|
forUpdate: statementExpression moreStatementExpressions;
|
|
|
|
|
|
|
|
|
|
modifiersOpt: (modifier)*;
|
|
|
|
|
|
|
|
|
|
modifier: Public
|
|
|
|
|
| Protected
|
|
|
|
|
| Private
|
|
|
|
|
| Static
|
|
|
|
|
| Abstract
|
|
|
|
|
| Final
|
|
|
|
|
| Native
|
|
|
|
|
| Synchronized
|
|
|
|
|
| Transient
|
|
|
|
|
| Volatile
|
|
|
|
|
| Strictfp;
|
|
|
|
|
|
|
|
|
|
variableDeclarators: variableDeclarator (Comma variableDeclarator)*;
|
|
|
|
|
|
|
|
|
|
variableDeclaratorsRest: variableDeclaratorRest (Comma variableDeclarator)*;
|
|
|
|
|
|
|
|
|
|
constantDeclaratorsRest: constantDeclaratorRest (Comma constantDeclarator)*;
|
|
|
|
|
|
2025-09-27 23:07:32 -06:00
|
|
|
variableDeclarator: identifier variableDeclaratorsRest;
|
2025-09-27 17:07:46 -06:00
|
|
|
|
|
|
|
|
constantDeclarator: identifier constantDeclaratorRest;
|
|
|
|
|
|
|
|
|
|
variableDeclaratorRest: bracketsOpt (Assignment variableInitializer)?;
|
|
|
|
|
|
|
|
|
|
constantDeclaratorRest: bracketsOpt Assignment variableInitializer;
|
|
|
|
|
|
|
|
|
|
variableDeclaratorId: identifier bracketsOpt;
|
|
|
|
|
|
2025-09-27 23:07:32 -06:00
|
|
|
compilationUnit: (Package qualifiedIdentifier Semicolon)? (importDeclaration)*(typeDeclaration)*;
|
2025-09-27 17:07:46 -06:00
|
|
|
|
|
|
|
|
importDeclaration: Import identifier (Dot identifier)* (Dot Multiplication)? Semicolon;
|
|
|
|
|
|
2025-09-27 23:07:32 -06:00
|
|
|
typeDeclaration: classOrInterfaceDeclaration | Semicolon;
|
2025-09-27 17:07:46 -06:00
|
|
|
|
|
|
|
|
classOrInterfaceDeclaration: modifiersOpt (classDeclaration | interfaceDeclaration);
|
|
|
|
|
|
|
|
|
|
classDeclaration: Class identifier (Extends type)? (Implements typeList)? classBody;
|
|
|
|
|
|
|
|
|
|
interfaceDeclaration: Interface identifier (Extends typeList)? interfaceBody;
|
|
|
|
|
|
|
|
|
|
typeList: type (Comma type)*;
|
|
|
|
|
|
|
|
|
|
classBody: CurlyBracketLeft (classBodyDeclaration)* CurlyBracketRight;
|
|
|
|
|
|
|
|
|
|
interfaceBody: CurlyBracketLeft (interfaceBodyDeclaration)* CurlyBracketRight;
|
|
|
|
|
|
|
|
|
|
classBodyDeclaration: Semicolon
|
|
|
|
|
| (Static)? block
|
|
|
|
|
| modifiersOpt memberDecl;
|
|
|
|
|
memberDecl: methodOrFieldDecl
|
|
|
|
|
| Void identifier methodDeclaratorRest
|
|
|
|
|
| identifier constructorDeclaratorRest
|
|
|
|
|
| classOrInterfaceDeclaration;
|
|
|
|
|
|
|
|
|
|
methodOrFieldDecl: type identifier methodOrFieldRest;
|
|
|
|
|
|
2025-09-27 23:07:32 -06:00
|
|
|
methodOrFieldRest: variableDeclaratorRest
|
2025-09-27 17:07:46 -06:00
|
|
|
|methodDeclaratorRest;
|
|
|
|
|
|
|
|
|
|
interfaceBodyDeclaration: Semicolon
|
|
|
|
|
| modifiersOpt interfaceMemberDecl;
|
|
|
|
|
|
|
|
|
|
interfaceMemberDecl: interfaceMethodOrFieldDecl
|
|
|
|
|
| Void identifier voidInterfaceMethodDeclaratorRest
|
|
|
|
|
| classOrInterfaceDeclaration;
|
|
|
|
|
|
|
|
|
|
interfaceMethodOrFieldDecl: type identifier interfaceMethodOrFieldRest;
|
|
|
|
|
|
|
|
|
|
interfaceMethodOrFieldRest: constantDeclaratorRest Semicolon
|
|
|
|
|
| interfaceMethodDeclaratorRest;
|
|
|
|
|
|
|
|
|
|
methodDeclaratorRest: formalParameters bracketsOpt (Throws qualifiedIdentifierList)?(methodBody | Semicolon);
|
|
|
|
|
|
|
|
|
|
voidMethodDeclaratorRest: formalParameters (Throws qualifiedIdentifierList)? (methodBody | Semicolon);
|
|
|
|
|
|
|
|
|
|
interfaceMethodDeclaratorRest: formalParameters bracketsOpt (Throws qualifiedIdentifierList)? Semicolon;
|
|
|
|
|
|
2025-09-27 23:07:32 -06:00
|
|
|
voidInterfaceMethodDeclaratorRest: formalParameters (Throws qualifiedIdentifierList)?;
|
2025-09-27 17:07:46 -06:00
|
|
|
|
|
|
|
|
constructorDeclaratorRest: formalParameters (Throws qualifiedIdentifierList)? methodBody;
|
|
|
|
|
|
|
|
|
|
qualifiedIdentifierList: qualifiedIdentifier (Comma qualifiedIdentifier)*;
|
|
|
|
|
|
|
|
|
|
formalParameters: ParenthesesLeft (formalParameter (Comma formalParameter)*)? ParenthesesRight;
|
|
|
|
|
|
|
|
|
|
formalParameter: (Final)? type variableDeclaratorId;
|
|
|
|
|
|
2025-09-27 23:07:32 -06:00
|
|
|
methodBody: block;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|