2025-09-25 21:49:56 -06:00
|
|
|
parser grammar ExprSyntactic;
|
|
|
|
|
|
|
|
|
|
options {
|
|
|
|
|
tokenVocab=ExprLexer;
|
|
|
|
|
}
|
2025-09-27 19:55:27 -06:00
|
|
|
prog: compilationUnit EOF;
|
2025-09-25 21:49:56 -06:00
|
|
|
identifier: IDENTIFIER;
|
|
|
|
|
|
2025-09-26 19:21:46 -06:00
|
|
|
qualifiedIdentifier: identifier (Dot identifier)*;
|
2025-09-25 21:49:56 -06:00
|
|
|
|
|
|
|
|
literal: IntegerLiteral
|
|
|
|
|
| FloatingPointLiteral
|
|
|
|
|
| CharacterLiteral
|
|
|
|
|
| StringLiteral
|
|
|
|
|
| BooleanLiteral
|
|
|
|
|
| NullLiteral;
|
|
|
|
|
|
2025-09-27 19:55:27 -06:00
|
|
|
expression: unaryExpr assignmentOperator expression | conditionalExpr ;
|
|
|
|
|
|
|
|
|
|
//Highest Prescedence _Expr = expression
|
|
|
|
|
//assignmentExpr: unaryExpr assignmentOperator assignmentExpr | conditionalExpr;
|
|
|
|
|
|
|
|
|
|
conditionalExpr: logicalOrExpr '?' conditionalExpr ':' conditionalExpr |logicalOrExpr;
|
|
|
|
|
|
|
|
|
|
logicalOrExpr: logicalAndExpr ('||' logicalAndExpr)*;
|
|
|
|
|
|
|
|
|
|
logicalAndExpr: equalityExpr ('&&' equalityExpr)*;
|
|
|
|
|
|
|
|
|
|
equalityExpr: relationalExpr (('==' | '!=') relationalExpr)*;
|
|
|
|
|
|
|
|
|
|
relationalExpr: additiveExpr(('<' | '>' | '<=' | '>=') additiveExpr | 'instanceof' type)*;
|
|
|
|
|
|
|
|
|
|
additiveExpr: multiplicativeExpr(('+' | '-') multiplicativeExpr)*;
|
|
|
|
|
multiplicativeExpr: unaryExpr(('*' | '/' | '%') unaryExpr)*;
|
|
|
|
|
|
|
|
|
|
unaryExpr:postfixExpr |('+' | '-' | '!' | '~' | '++' | '--') unaryExpr | parExpression type unaryExpr;
|
|
|
|
|
|
|
|
|
|
postfixExpr: primaryExpr ('++'| '--'| '.' IDENTIFIER | '[' expression ']' | arguments)*;
|
|
|
|
|
|
|
|
|
|
primaryExpr: parExpression
|
|
|
|
|
| IntegerLiteral
|
|
|
|
|
| FloatingPointLiteral
|
|
|
|
|
| StringLiteral
|
|
|
|
|
| CharacterLiteral
|
|
|
|
|
| BooleanLiteral
|
|
|
|
|
| NullLiteral
|
|
|
|
|
| IDENTIFIER
|
|
|
|
|
| 'this'
|
|
|
|
|
| 'super' ('.' IDENTIFIER)?
|
|
|
|
|
| 'new' type arguments
|
|
|
|
|
| primitiveType ('[' ']')* '.' 'class'
|
|
|
|
|
| type '.' 'class';
|
2025-09-27 15:55:38 -06:00
|
|
|
|
|
|
|
|
|
2025-09-25 21:49:56 -06:00
|
|
|
assignmentOperator: Assignment
|
|
|
|
|
| AddAssign
|
|
|
|
|
| SubtractAssign
|
|
|
|
|
| MultiplyAssign
|
|
|
|
|
| DivideAssign
|
|
|
|
|
| BitwiseANDAssign
|
|
|
|
|
| BitwiseORAssign
|
|
|
|
|
| BitwiseXORAssign
|
|
|
|
|
| RemainderAssign
|
|
|
|
|
| LeftShiftAssign
|
2025-09-27 14:11:33 -06:00
|
|
|
| SignedRightShiftAssign
|
|
|
|
|
| UnsignedRightShiftAssign;
|
2025-09-25 21:49:56 -06:00
|
|
|
|
2025-09-26 19:21:46 -06:00
|
|
|
type: identifier (Dot identifier)* bracketsOpt
|
2025-09-27 19:55:27 -06:00
|
|
|
| primitiveType;
|
2025-09-25 21:49:56 -06:00
|
|
|
|
|
|
|
|
statementExpression: expression;
|
|
|
|
|
|
|
|
|
|
constantExpression: expression;
|
|
|
|
|
|
2025-09-27 19:55:27 -06:00
|
|
|
//expression1: expression2 (expression1Rest)?;
|
|
|
|
|
//
|
|
|
|
|
//expression1Rest: Question expression Colon expression1;
|
|
|
|
|
//
|
|
|
|
|
//expression2: expression3 expression2Rest?;
|
|
|
|
|
//
|
|
|
|
|
//expression2Rest: (infixop expression3)+
|
|
|
|
|
// | InstanceOf type;
|
|
|
|
|
|
|
|
|
|
//infixop: ConditionalOR
|
|
|
|
|
// | ConditionalAND
|
|
|
|
|
// | BitwiseOR
|
|
|
|
|
// | BitwiseXOR
|
|
|
|
|
// | BitwiseAND
|
|
|
|
|
// | EqualTo
|
|
|
|
|
// | NotEqualTo
|
|
|
|
|
// | LessThan
|
|
|
|
|
// | GreaterThan
|
|
|
|
|
// | LessThanEqualTo
|
|
|
|
|
// | GreaterThanEqualTo
|
|
|
|
|
// | LeftShift
|
|
|
|
|
// | SignedRightShift
|
|
|
|
|
// | UnsignedRightShift
|
|
|
|
|
// | Addition
|
|
|
|
|
// | Subtraction
|
|
|
|
|
// | Multiplication
|
|
|
|
|
// | Division
|
|
|
|
|
// | Remainder;
|
|
|
|
|
|
|
|
|
|
//expression3: prefixOp expression3 // Recursion
|
|
|
|
|
// | ParenthesesLeft type ParenthesesRight expression3
|
|
|
|
|
// | primary (selector)* (postfixOp)*;
|
|
|
|
|
|
|
|
|
|
//primary: (expression)
|
|
|
|
|
// | This (arguments)?
|
|
|
|
|
// | Super superSuffix
|
|
|
|
|
// | literal
|
|
|
|
|
// | New creator
|
|
|
|
|
// | identifier (Dot identifier)* (identifierSuffix)?
|
|
|
|
|
// | primitiveType bracketsOpt Dot Class
|
|
|
|
|
// | Void Dot Class;
|
2025-09-27 13:28:28 -06:00
|
|
|
|
2025-09-26 23:52:51 -06:00
|
|
|
identifierSuffix: SquareBracketLeft SquareBracketRight bracketsOpt Dot Class //Case []...'.'class
|
|
|
|
|
|SquareBracketLeft expression SquareBracketRight //arr[5]
|
|
|
|
|
|arguments
|
|
|
|
|
|Dot (Class | This | Super arguments New innerCreator);
|
2025-09-25 23:06:20 -06:00
|
|
|
|
2025-09-27 19:55:27 -06:00
|
|
|
//prefixOp: Increment
|
|
|
|
|
// | Decrement
|
|
|
|
|
// | LogicalComplement
|
|
|
|
|
// | BitWiseComplement
|
|
|
|
|
// | Addition
|
|
|
|
|
// | Subtraction;
|
2025-09-25 23:06:20 -06:00
|
|
|
|
|
|
|
|
postfixOp: Increment | Decrement;
|
|
|
|
|
|
2025-09-27 19:55:27 -06:00
|
|
|
//selector: Dot identifier (arguments)?
|
|
|
|
|
// | Dot This
|
|
|
|
|
// | Dot Super superSuffix
|
|
|
|
|
// | Dot New innerCreator
|
|
|
|
|
// | SquareBracketLeft expression SquareBracketRight;
|
|
|
|
|
|
|
|
|
|
//superSuffix: arguments
|
|
|
|
|
// | Dot identifier (arguments)?;
|
2025-09-25 23:06:20 -06:00
|
|
|
|
2025-09-27 19:55:27 -06:00
|
|
|
primitiveType: Byte
|
2025-09-25 23:06:20 -06:00
|
|
|
| Short
|
|
|
|
|
| Char
|
|
|
|
|
| Int
|
|
|
|
|
| Long
|
|
|
|
|
| Float
|
|
|
|
|
| Double
|
|
|
|
|
| Boolean;
|
2025-09-27 19:55:27 -06:00
|
|
|
//Method arguments
|
2025-09-26 19:21:46 -06:00
|
|
|
argumentsOpt: (arguments)?;
|
2025-09-25 23:06:20 -06:00
|
|
|
|
2025-09-27 13:28:28 -06:00
|
|
|
arguments: ParenthesesLeft (expression (Comma expression)*)? ParenthesesRight;
|
2025-09-25 23:06:20 -06:00
|
|
|
|
2025-09-26 23:52:51 -06:00
|
|
|
bracketsOpt: (SquareBracketLeft SquareBracketRight)*;
|
2025-09-25 23:06:20 -06:00
|
|
|
|
|
|
|
|
creator: qualifiedIdentifier ( arrayCreatorRest | classCreatorRest);
|
|
|
|
|
|
|
|
|
|
innerCreator: identifier classCreatorRest;
|
|
|
|
|
|
2025-09-26 23:52:51 -06:00
|
|
|
arrayCreatorRest: SquareBracketLeft SquareBracketRight bracketsOpt arrayInitializer
|
|
|
|
|
| SquareBracketLeft expression SquareBracketRight (SquareBracketLeft expression SquareBracketRight)*;
|
|
|
|
|
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 13:28:28 -06:00
|
|
|
|(identifier Colon)? statement;
|
2025-09-26 23:52:51 -06:00
|
|
|
|
|
|
|
|
localVariableDeclarationStatement: (Final)? type variableDeclarators;
|
|
|
|
|
|
2025-09-27 19:55:27 -06:00
|
|
|
statement
|
|
|
|
|
: matchedStatement // Case 1: All non-ambiguous statements
|
|
|
|
|
| If parExpression statementNoShortIf // Case 2: The 'Dangling' if (ends with an unmatched if)
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
statementNoShortIf: block
|
|
|
|
|
| If parExpression matchedStatement Else statementNoShortIf
|
|
|
|
|
| For ParenthesesLeft forInit? Semicolon (expression)? Semicolon forUpdate? ParenthesesRight statement
|
|
|
|
|
| While parExpression statement
|
|
|
|
|
| Do statement While parExpression Semicolon
|
|
|
|
|
| Try block (catches+ Finally block? | Finally block)
|
|
|
|
|
| Switch parExpression CurlyBracketLeft switchBlockStatementGroups? CurlyBracketRight
|
|
|
|
|
| Synchronized parExpression block
|
|
|
|
|
| Return (expression)? Semicolon
|
|
|
|
|
| Throw expression Semicolon
|
|
|
|
|
| Break (identifier)? Semicolon
|
|
|
|
|
| Continue (identifier)? Semicolon
|
|
|
|
|
| Semicolon
|
|
|
|
|
| statementExpression Semicolon
|
|
|
|
|
| identifier Colon statement;
|
|
|
|
|
|
|
|
|
|
matchedStatement: If parExpression matchedStatement Else matchedStatement
|
|
|
|
|
| statementNoShortIf;
|
2025-09-26 23:52:51 -06:00
|
|
|
|
|
|
|
|
catches: catchClause (catchClause)*;
|
|
|
|
|
|
2025-09-27 14:11:33 -06:00
|
|
|
catchClause: Catch ParenthesesLeft formalParameter ParenthesesRight block;
|
2025-09-26 23:52:51 -06:00
|
|
|
|
2025-09-27 13:28:28 -06:00
|
|
|
switchBlockStatementGroups: (switchBlockStatementGroup)*;
|
2025-09-26 23:52:51 -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;
|
|
|
|
|
|
2025-09-27 13:28:28 -06:00
|
|
|
variableDeclarators: variableDeclarator (Comma variableDeclarator)*;
|
2025-09-26 23:52:51 -06:00
|
|
|
|
2025-09-27 13:28:28 -06:00
|
|
|
variableDeclaratorsRest: variableDeclaratorRest (Comma variableDeclarator)*;
|
2025-09-26 23:52:51 -06:00
|
|
|
|
2025-09-27 13:28:28 -06:00
|
|
|
constantDeclaratorsRest: constantDeclaratorRest (Comma constantDeclarator)*;
|
2025-09-26 23:52:51 -06:00
|
|
|
|
|
|
|
|
variableDeclarator: identifier variableDeclaratorsRest;
|
|
|
|
|
|
|
|
|
|
constantDeclarator: identifier constantDeclaratorRest;
|
|
|
|
|
|
2025-09-27 13:28:28 -06:00
|
|
|
variableDeclaratorRest: bracketsOpt (Assignment variableInitializer)?;
|
|
|
|
|
|
|
|
|
|
constantDeclaratorRest: bracketsOpt Assignment variableInitializer;
|
|
|
|
|
|
|
|
|
|
variableDeclaratorId: identifier bracketsOpt;
|
|
|
|
|
|
2025-09-27 19:55:27 -06:00
|
|
|
compilationUnit: (Package qualifiedIdentifier Semicolon)? (importDeclaration)*(typeDeclaration)*;
|
2025-09-27 13:28:28 -06:00
|
|
|
|
2025-09-27 14:11:33 -06:00
|
|
|
importDeclaration: Import identifier (Dot identifier)* (Dot Multiplication)? Semicolon;
|
2025-09-27 13:28:28 -06:00
|
|
|
|
2025-09-27 19:55:27 -06:00
|
|
|
typeDeclaration: classOrInterfaceDeclaration | Semicolon;
|
2025-09-27 13:28:28 -06:00
|
|
|
|
|
|
|
|
classOrInterfaceDeclaration: modifiersOpt (classDeclaration | interfaceDeclaration);
|
|
|
|
|
|
|
|
|
|
classDeclaration: Class identifier (Extends type)? (Implements typeList)? classBody;
|
|
|
|
|
|
|
|
|
|
interfaceDeclaration: Interface identifier (Extends typeList)? interfaceBody;
|
|
|
|
|
|
2025-09-27 14:11:33 -06:00
|
|
|
typeList: type (Comma type)*;
|
2025-09-27 13:28:28 -06:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
methodOrFieldRest: variableDeclaratorRest
|
|
|
|
|
|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;
|
|
|
|
|
|
|
|
|
|
voidInterfaceMethodDeclaratorRest: formalParameters (Throws qualifiedIdentifierList)?;
|
|
|
|
|
|
|
|
|
|
constructorDeclaratorRest: formalParameters (Throws qualifiedIdentifierList)? methodBody;
|
|
|
|
|
|
2025-09-27 19:55:27 -06:00
|
|
|
qualifiedIdentifierList: qualifiedIdentifier (Comma qualifiedIdentifier)*;
|
2025-09-27 13:28:28 -06:00
|
|
|
|
2025-09-27 14:11:33 -06:00
|
|
|
formalParameters: ParenthesesLeft (formalParameter (Comma formalParameter)*)? ParenthesesRight;
|
2025-09-27 13:28:28 -06:00
|
|
|
|
|
|
|
|
formalParameter: (Final)? type variableDeclaratorId;
|
|
|
|
|
|
|
|
|
|
methodBody: block;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|