2025-09-25 21:49:56 -06:00
|
|
|
parser grammar ExprSyntactic;
|
|
|
|
|
|
|
|
|
|
options {
|
|
|
|
|
tokenVocab=ExprLexer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 15:47:51 -06:00
|
|
|
expression: expression1 (assignmentOperator expression1)?;
|
|
|
|
|
|
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-25 21:49:56 -06:00
|
|
|
| basicType;
|
|
|
|
|
|
|
|
|
|
statementExpression: expression;
|
|
|
|
|
|
|
|
|
|
constantExpression: expression;
|
|
|
|
|
|
2025-09-27 15:47:51 -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
|
|
|
|
|
| ParenthesesLeft type ParenthesesRight expression3
|
|
|
|
|
| primary (selector)* (postfixOp)*;
|
|
|
|
|
|
|
|
|
|
primary: (expression)
|
|
|
|
|
| This (arguments)?
|
|
|
|
|
| Super superSuffix
|
|
|
|
|
| literal
|
|
|
|
|
| New creator
|
|
|
|
|
| identifier (Dot identifier)* (identifierSuffix)?
|
|
|
|
|
| basicType 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
|
|
|
|
|
|
|
|
prefixOp: Increment
|
|
|
|
|
| Decrement
|
|
|
|
|
| LogicalComplement
|
2025-09-27 15:47:51 -06:00
|
|
|
| BitwiseComplement
|
2025-09-25 23:06:20 -06:00
|
|
|
| Addition
|
|
|
|
|
| Subtraction;
|
|
|
|
|
|
|
|
|
|
postfixOp: Increment | Decrement;
|
|
|
|
|
|
2025-09-26 23:52:51 -06:00
|
|
|
selector: Dot identifier (arguments)?
|
|
|
|
|
| Dot This
|
|
|
|
|
| Dot Super superSuffix
|
|
|
|
|
| Dot New innerCreator
|
|
|
|
|
| SquareBracketLeft expression SquareBracketRight;
|
2025-09-25 23:06:20 -06:00
|
|
|
|
|
|
|
|
superSuffix: arguments
|
2025-09-26 23:52:51 -06:00
|
|
|
| Dot identifier (arguments)?;
|
2025-09-27 13:28:28 -06:00
|
|
|
//primitives
|
2025-09-25 23:06:20 -06:00
|
|
|
basicType: Byte
|
|
|
|
|
| Short
|
|
|
|
|
| Char
|
|
|
|
|
| Int
|
|
|
|
|
| Long
|
|
|
|
|
| Float
|
|
|
|
|
| Double
|
|
|
|
|
| Boolean;
|
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;
|
|
|
|
|
|
|
|
|
|
statement: block
|
|
|
|
|
| If parExpression statement (Else statement)?
|
2025-09-27 13:28:28 -06:00
|
|
|
| For ParenthesesLeft forInit? Semicolon (expression)? Semicolon forUpdate? ParenthesesRight statement
|
2025-09-26 23:52:51 -06:00
|
|
|
| While parExpression statement
|
|
|
|
|
| Do statement While parExpression Semicolon
|
|
|
|
|
| Try block (catches | (catches)? Finally block)
|
2025-09-27 13:28:28 -06:00
|
|
|
| Switch parExpression CurlyBracketLeft switchBlockStatementGroups? CurlyBracketRight
|
2025-09-26 23:52:51 -06:00
|
|
|
| Synchronized parExpression block
|
|
|
|
|
| Return (expression)? Semicolon
|
|
|
|
|
| Throw expression Semicolon
|
|
|
|
|
| Break (identifier)? Semicolon
|
|
|
|
|
| Continue (identifier)? Semicolon
|
|
|
|
|
| Semicolon
|
2025-09-27 14:11:33 -06:00
|
|
|
//| expressionStatement
|
2025-09-26 23:52:51 -06:00
|
|
|
| identifier Colon statement;
|
|
|
|
|
|
|
|
|
|
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 15:47:51 -06:00
|
|
|
|
2025-09-27 13:28:28 -06:00
|
|
|
variableDeclaratorRest: bracketsOpt (Assignment variableInitializer)?;
|
|
|
|
|
|
|
|
|
|
constantDeclaratorRest: bracketsOpt Assignment variableInitializer;
|
|
|
|
|
|
|
|
|
|
variableDeclaratorId: identifier bracketsOpt;
|
|
|
|
|
|
|
|
|
|
compilationUnit: (Package qualifiedIdentifier Semicolon)? (importDeclaration)*;
|
|
|
|
|
|
2025-09-27 14:11:33 -06:00
|
|
|
importDeclaration: Import identifier (Dot identifier)* (Dot Multiplication)? Semicolon;
|
2025-09-27 13:28:28 -06:00
|
|
|
|
|
|
|
|
typeDeclaration: classOrInterfaceDeclaration Semicolon;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
qualifiedIdentifierList: qualifiedIdentifier (Semicolon qualifiedIdentifier)*;
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|