grammar completed V1, still needs testing
This commit is contained in:
@@ -96,7 +96,7 @@ Volatile: 'volatile';
|
|||||||
While: 'while';
|
While: 'while';
|
||||||
|
|
||||||
// LITERALS -------------------------------------------------------------------------------------------------------------------
|
// LITERALS -------------------------------------------------------------------------------------------------------------------
|
||||||
IntigerLiteral: DecimalIntegerLiteral | HexIntegerLiteral | OctalIntegerLiteral;
|
IntegerLiteral: DecimalIntegerLiteral | HexIntegerLiteral | OctalIntegerLiteral;
|
||||||
|
|
||||||
fragment DecimalIntegerLiteral:
|
fragment DecimalIntegerLiteral:
|
||||||
DecimalNumeral IntegerTypeSuffix?;
|
DecimalNumeral IntegerTypeSuffix?;
|
||||||
@@ -214,7 +214,7 @@ ConditionalOR: '||';
|
|||||||
Increment: '++';
|
Increment: '++';
|
||||||
Decrement: '--';
|
Decrement: '--';
|
||||||
Addition: '+';
|
Addition: '+';
|
||||||
Subtaction: '-';
|
Subtraction: '-';
|
||||||
Multiplication: '*';
|
Multiplication: '*';
|
||||||
Division: '/';
|
Division: '/';
|
||||||
BitwiseAND: '&';
|
BitwiseAND: '&';
|
||||||
|
|||||||
266
ExprSyntactic.g4
266
ExprSyntactic.g4
@@ -37,21 +37,21 @@ statementExpression: expression;
|
|||||||
|
|
||||||
constantExpression: expression;
|
constantExpression: expression;
|
||||||
|
|
||||||
expression1: expression2 (expression1Rest)*;
|
expression1: expression2 (expression1Rest)?;
|
||||||
|
|
||||||
expression1Rest: (Question expression Colon expression1)?;
|
expression1Rest: Question expression Colon expression1;
|
||||||
|
|
||||||
expression2: expression3 (expression2Rest)?;
|
expression2: expression3 expression2Rest?;
|
||||||
|
|
||||||
expression2Rest: (infixop expression3)*
|
expression2Rest: (infixop expression3)+
|
||||||
| expression3 INSTANCEOF type;
|
| InstanceOf type;
|
||||||
|
|
||||||
infixop: ConditionalOR
|
infixop: ConditionalOR
|
||||||
| ConditionalAND
|
| ConditionalAND
|
||||||
| BitwiseOR
|
| BitwiseOR
|
||||||
| BitwiseXOR
|
| BitwiseXOR
|
||||||
| BitwiseAND
|
| BitwiseAND
|
||||||
| EqualTO
|
| EqualTo
|
||||||
| NotEqualTO
|
| NotEqualTO
|
||||||
| LessThan
|
| LessThan
|
||||||
| GreterThan
|
| GreterThan
|
||||||
@@ -67,8 +67,8 @@ infixop: ConditionalOR
|
|||||||
| Remainder;
|
| Remainder;
|
||||||
|
|
||||||
expression3: prefixOp expression3 // Recursion
|
expression3: prefixOp expression3 // Recursion
|
||||||
| (expr | type) expression3
|
| (expression | type) expression3
|
||||||
| primary (selector)* (postfixOP)*;
|
| primary (selector)* (postfixOp)*;
|
||||||
|
|
||||||
primary: (expression)
|
primary: (expression)
|
||||||
| This (arguments)?
|
| This (arguments)?
|
||||||
@@ -79,6 +79,25 @@ primary: (expression)
|
|||||||
| basicType bracketsOpt Dot Class
|
| basicType bracketsOpt Dot Class
|
||||||
| Void Dot Class;
|
| Void Dot Class;
|
||||||
|
|
||||||
|
////TEST
|
||||||
|
//primary: primaryAtom primarySuffix*
|
||||||
|
// | New creator ;
|
||||||
|
//
|
||||||
|
//primaryAtom: ParenthesesLeft expression ParenthesesRight
|
||||||
|
// | This
|
||||||
|
// | literal
|
||||||
|
// | qualifiedIdentifier
|
||||||
|
// | qualifiedIdentifier Dot This
|
||||||
|
// | basicType bracketsOpt Dot Class
|
||||||
|
// | Void Dot Class
|
||||||
|
// | Super;
|
||||||
|
//
|
||||||
|
//// All selectors / postfix pieces (no recursion back to primary)
|
||||||
|
//primarySuffix: Dot Identifier arguments?
|
||||||
|
// | SquareBracketLeft expression SquareBracketRight
|
||||||
|
// | Dot Class;
|
||||||
|
////END test
|
||||||
|
|
||||||
identifierSuffix: SquareBracketLeft SquareBracketRight bracketsOpt Dot Class //Case []...'.'class
|
identifierSuffix: SquareBracketLeft SquareBracketRight bracketsOpt Dot Class //Case []...'.'class
|
||||||
|SquareBracketLeft expression SquareBracketRight //arr[5]
|
|SquareBracketLeft expression SquareBracketRight //arr[5]
|
||||||
|arguments
|
|arguments
|
||||||
@@ -101,7 +120,7 @@ selector: Dot identifier (arguments)?
|
|||||||
|
|
||||||
superSuffix: arguments
|
superSuffix: arguments
|
||||||
| Dot identifier (arguments)?;
|
| Dot identifier (arguments)?;
|
||||||
|
//primitives
|
||||||
basicType: Byte
|
basicType: Byte
|
||||||
| Short
|
| Short
|
||||||
| Char
|
| Char
|
||||||
@@ -113,7 +132,7 @@ basicType: Byte
|
|||||||
//TODO: REVIEW ANYTHING BEFORE THIS POINT FOR POTENTIAL CONFUSSION ON TERMINAL SYMBOLS AND GRAMMAR
|
//TODO: REVIEW ANYTHING BEFORE THIS POINT FOR POTENTIAL CONFUSSION ON TERMINAL SYMBOLS AND GRAMMAR
|
||||||
argumentsOpt: (arguments)?;
|
argumentsOpt: (arguments)?;
|
||||||
|
|
||||||
arguments: ParenthesesLeft (expression (',' expression)*)? ParenthesesRight;
|
arguments: ParenthesesLeft (expression (Comma expression)*)? ParenthesesRight;
|
||||||
|
|
||||||
bracketsOpt: (SquareBracketLeft SquareBracketRight)*;
|
bracketsOpt: (SquareBracketLeft SquareBracketRight)*;
|
||||||
|
|
||||||
@@ -138,17 +157,17 @@ blockStatements: (blockStatement)*;
|
|||||||
|
|
||||||
blockStatement: localVariableDeclarationStatement
|
blockStatement: localVariableDeclarationStatement
|
||||||
|classOrInterfaceDeclaration
|
|classOrInterfaceDeclaration
|
||||||
|(identifier Colon)?;
|
|(identifier Colon)? statement;
|
||||||
|
|
||||||
localVariableDeclarationStatement: (Final)? type variableDeclarators;
|
localVariableDeclarationStatement: (Final)? type variableDeclarators;
|
||||||
|
|
||||||
statement: block
|
statement: block
|
||||||
| If parExpression statement (Else statement)?
|
| If parExpression statement (Else statement)?
|
||||||
| For ParenthesesLeft forInitOp Semicolon (expression)? Semicolon forUpdateOpt ParenthesesRight statement
|
| For ParenthesesLeft forInit? Semicolon (expression)? Semicolon forUpdate? ParenthesesRight statement
|
||||||
| While parExpression statement
|
| While parExpression statement
|
||||||
| Do statement While parExpression Semicolon
|
| Do statement While parExpression Semicolon
|
||||||
| Try block (catches | (catches)? Finally block)
|
| Try block (catches | (catches)? Finally block)
|
||||||
| Switch parExpression CurlyBracketLeft switchBlockStatementsGroups? CurlyBracketRight
|
| Switch parExpression CurlyBracketLeft switchBlockStatementGroups? CurlyBracketRight
|
||||||
| Synchronized parExpression block
|
| Synchronized parExpression block
|
||||||
| Return (expression)? Semicolon
|
| Return (expression)? Semicolon
|
||||||
| Throw expression Semicolon
|
| Throw expression Semicolon
|
||||||
@@ -162,7 +181,7 @@ catches: catchClause (catchClause)*;
|
|||||||
|
|
||||||
catchClause: Catch ParenthesesLeft formalParameter ParanthesesRight block;
|
catchClause: Catch ParenthesesLeft formalParameter ParanthesesRight block;
|
||||||
|
|
||||||
switchBlockStatementGroups: (switchBlockStatementGroups)*;
|
switchBlockStatementGroups: (switchBlockStatementGroup)*;
|
||||||
|
|
||||||
switchBlockStatementGroup: switchLabel blockStatements;
|
switchBlockStatementGroup: switchLabel blockStatements;
|
||||||
|
|
||||||
@@ -189,14 +208,225 @@ modifier: Public
|
|||||||
| Volatile
|
| Volatile
|
||||||
| Strictfp;
|
| Strictfp;
|
||||||
|
|
||||||
variableDeclarators: variableDeclarators (Comma variableDeclarator)*;
|
variableDeclarators: variableDeclarator (Comma variableDeclarator)*;
|
||||||
|
|
||||||
variableDeclaratorsRest: variableDeclaratorsRest (Comma variableDeclarator)*;
|
variableDeclaratorsRest: variableDeclaratorRest (Comma variableDeclarator)*;
|
||||||
|
|
||||||
constantDeclaratorRest: constantDeclaratorRest (Comma constantDeclarator)*;
|
constantDeclaratorsRest: constantDeclaratorRest (Comma constantDeclarator)*;
|
||||||
|
|
||||||
variableDeclarator: identifier variableDeclaratorsRest;
|
variableDeclarator: identifier variableDeclaratorsRest;
|
||||||
|
|
||||||
constantDeclarator: identifier constantDeclaratorRest;
|
constantDeclarator: identifier constantDeclaratorRest;
|
||||||
|
|
||||||
//Little git test
|
variableDeclaratorRest: bracketsOpt (Assignment variableInitializer)?;
|
||||||
|
|
||||||
|
constantDeclaratorRest: bracketsOpt Assignment variableInitializer;
|
||||||
|
|
||||||
|
variableDeclaratorId: identifier bracketsOpt;
|
||||||
|
|
||||||
|
compilationUnit: (Package qualifiedIdentifier Semicolon)? (importDeclaration)*;
|
||||||
|
|
||||||
|
importDeclaration: Import identifier (Dot identifier)*(importDeclaration Multiplication)? Semicolon;
|
||||||
|
|
||||||
|
typeDeclaration: classOrInterfaceDeclaration Semicolon;
|
||||||
|
|
||||||
|
classOrInterfaceDeclaration: modifiersOpt (classDeclaration | interfaceDeclaration);
|
||||||
|
|
||||||
|
classDeclaration: Class identifier (Extends type)? (Implements typeList)? classBody;
|
||||||
|
|
||||||
|
interfaceDeclaration: Interface identifier (Extends typeList)? interfaceBody;
|
||||||
|
|
||||||
|
typeList: type (Semicolon 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;
|
||||||
|
|
||||||
|
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)*;
|
||||||
|
|
||||||
|
formalParameters:ParenthesesLeft (formalParameters(Semicolon formalParameter))? ParanthesesRight;
|
||||||
|
|
||||||
|
formalParameter: (Final)? type variableDeclaratorId;
|
||||||
|
|
||||||
|
methodBody: block;
|
||||||
|
|
||||||
|
//Things not defined within the final chapter of JSL2
|
||||||
|
expressionStatement: statementExpression Semicolon;
|
||||||
|
|
||||||
|
asssignmentExpression: conditionalExpression
|
||||||
|
| assignment;
|
||||||
|
assignment: leftHandSide assignmentOperator assignmentExpression;
|
||||||
|
|
||||||
|
leftHandSide: expressionName
|
||||||
|
| fieldAccess
|
||||||
|
| arrayAccess;
|
||||||
|
|
||||||
|
conditionalExpression: conditionalOrExpression
|
||||||
|
| conditionalOrExpression Question expression Colon conditionalExpression;
|
||||||
|
|
||||||
|
conditionalOrExpression:
|
||||||
|
conditionalAndExpression
|
||||||
|
|conditionalOrExpression ConditionalOr conditionalAndExpression;
|
||||||
|
//Conditional And (&&)
|
||||||
|
conditionalAndExpression:
|
||||||
|
inclusiveOrExpression
|
||||||
|
|conditionalAndExpression ConditionalAnd inclusiveOrExpression;
|
||||||
|
inclusiveOrExpression:
|
||||||
|
exclusiveOrExpression
|
||||||
|
inclusiveOrExpression BitwiseOR exclusiveOrExpression;
|
||||||
|
//Assignment operators
|
||||||
|
assignmentExpression:conditionalExpression
|
||||||
|
|assignment;
|
||||||
|
|
||||||
|
relationalExpression:
|
||||||
|
shiftExpression
|
||||||
|
|relationalExpression LessThan shiftExpression
|
||||||
|
|relationalExpression GreaterThan shiftExpression
|
||||||
|
|relationalExpression LessOrEqual shiftExpression
|
||||||
|
|relationalExpression GreaterOrEqual shiftExpression
|
||||||
|
|relationalExpression InstanceOf referenceType;
|
||||||
|
|
||||||
|
//ShiftExpression:
|
||||||
|
shiftExpression: additiveExpression
|
||||||
|
|shiftExpression LeftShift additiveExpression
|
||||||
|
|shiftExpression SignedRightShift additiveExpression
|
||||||
|
|shiftExpression UnsignedRightShift additiveExpression;
|
||||||
|
//Additive Operators
|
||||||
|
additiveExpression: multiplicativeExpression
|
||||||
|
| additiveExpression Addition multiplicativeExpression
|
||||||
|
| additiveExpression Subtraction multiplicativeExpression;
|
||||||
|
|
||||||
|
//Multiplicative Operators
|
||||||
|
multiplicativeExpression: unaryExpression
|
||||||
|
| multiplicativeExpression Multiplication unaryExpression
|
||||||
|
| multiplicativeExpression Division unaryExpression
|
||||||
|
| multiplicativeExpression Remainder unaryExpression;
|
||||||
|
//Unary Operators
|
||||||
|
unaryExpression: preIncrementExpression
|
||||||
|
|preDecrementExpression
|
||||||
|
|Addition unaryExpression
|
||||||
|
|Subtraction unaryExpression
|
||||||
|
|unaryExpressionNotPlusMinus;
|
||||||
|
|
||||||
|
preIncrementExpression: Increment unaryExpression;
|
||||||
|
preDecrementExpression: Decrement unaryExpression;
|
||||||
|
unaryExpressionNotPlusMinus: postfixExpression
|
||||||
|
|BitwiseComplement unaryExpression
|
||||||
|
|LogicalComplement unaryExpression
|
||||||
|
| castExpression;
|
||||||
|
castExpression: ParenthesesLeft primitiveType ParanthesesRight unaryExpression
|
||||||
|
| ParenthesesLeft referenceType ParanthesesRight unaryExpressionNotPlusMinus;
|
||||||
|
//Primitive types
|
||||||
|
primitiveType: numericType
|
||||||
|
| Boolean;
|
||||||
|
referenceType: classOrInterfaceType
|
||||||
|
| arrayType;
|
||||||
|
classOrInterfaceType: classType
|
||||||
|
| interfaceType;
|
||||||
|
classType: typeName;
|
||||||
|
interfaceType: typeName;
|
||||||
|
//Determining meaning of Name
|
||||||
|
typeName: identifier
|
||||||
|
| packageOrTypeName Dot Identifier;
|
||||||
|
packageOrTypeName: Identifier
|
||||||
|
| packageOrTypeName Dot identifier;
|
||||||
|
arrayType: type SquareBracketLeft SquareBracketRight;
|
||||||
|
numericType: integralType
|
||||||
|
| floatingPointType;
|
||||||
|
integralType: Byte | Short | Int | Long | Char;
|
||||||
|
floatingPointType: Float | Double;
|
||||||
|
//postfix expressions
|
||||||
|
//postfixExpression: primary
|
||||||
|
// | expressionName
|
||||||
|
// | postIncrementExpression
|
||||||
|
// | postDecrementExpression;
|
||||||
|
postfixBase: primary | expressionName ;
|
||||||
|
postfixExpression : postfixBase (Increment | Decrement)* ;
|
||||||
|
postIncrementExpression: postfixExpression Increment;
|
||||||
|
postDecrementExpression: postfixExpression Decrement;
|
||||||
|
|
||||||
|
//Equality Operators
|
||||||
|
equalityExpression:
|
||||||
|
relationalExpression
|
||||||
|
|equalityExpression EqualEqual relationalExpression
|
||||||
|
|equalityExpression NotEqualTo relationalExpression;
|
||||||
|
|
||||||
|
//Bitwise and Logical Operators
|
||||||
|
andExpression:
|
||||||
|
equalityExpression
|
||||||
|
|andExpression BitwiseAND andExpression;
|
||||||
|
exclusiveOrExpression:
|
||||||
|
andExpression
|
||||||
|
|exclusiveOrExpression BitwiseXOR andExpression;
|
||||||
|
expressionName: Identifier (Dot Identifier)*;
|
||||||
|
fieldAccess
|
||||||
|
: primary Dot Identifier
|
||||||
|
| Super Dot Identifier
|
||||||
|
| typeName Dot Super Dot Identifier
|
||||||
|
;
|
||||||
|
|
||||||
|
primaryNoNewArray: literal
|
||||||
|
| type Dot Class
|
||||||
|
|Void Dot Class
|
||||||
|
|This
|
||||||
|
|qualifiedIdentifier Dot This
|
||||||
|
|ParenthesesLeft expression ParanthesesRight
|
||||||
|
|classInstanceCreationExpression
|
||||||
|
|fieldAccess
|
||||||
|
|methodInvocation
|
||||||
|
|arrayAccess;
|
||||||
|
|
||||||
|
classInstanceCreationExpression: New classOrInterfaceType ParenthesesLeft argumentsOpt ParanthesesRight classBody
|
||||||
|
| primary New identifier ParenthesesLeft argumentsOpt ParanthesesRight classBody;
|
||||||
|
|
||||||
|
methodInvocation: methodName arguments
|
||||||
|
| primary Dot Identifier arguments
|
||||||
|
| Super Dot Identifier arguments
|
||||||
|
| typeName Dot Super Dot Identifier arguments;
|
||||||
|
methodName
|
||||||
|
: Identifier (Dot Identifier)*;
|
||||||
|
|
||||||
|
//arguments: ParenthesesLeft argumentList? ParanthesesRight;
|
||||||
|
|
||||||
|
argumentList: expression (Comma expression)*;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user