|
java11.grm
|
// FILE. . . . . /home/hak/d/ilog/rnd/grammars/java/java11.grm // EDIT BY . . . Hassan Ait-Kaci // ON MACHINE. . Latitude407 // STARTED ON. . Mon Sep 29 17:48:11 2003 // Last modified on Tue Sep 30 17:23:52 2003 by hak
| This grammar was adapted from Hassan Aït-Kaci | ||
| Inreach: | com"> | |
| Copyright: | © 2000 ILOG, Inc. | |
| Version: | Last modified on Mon Sep 29 18:08:33 2003 by hak |
// %dynamic Operator
// %Operator '||' xfy 800
// %Operator '&&' xfy 700
// %Operator '==' xfy 600
// %Operator '!=' xfy 600
// %Operator '-=' xfy 580
// %Operator '^=' xfy 575
// %Operator '=^' xfy 575
// %Operator '^' yfx 555
// %Operator '<' xfx 500
// %Operator '<=' xfx 500
// %Operator '>' xfx 500
// %Operator '>=' xfx 500
// %Operator '..' xfx 450
// %Operator 'max' yfx 440
// %Operator 'min' yfx 430
// %Operator '+' xfy 400
// %Operator '-' yfx 400
// %Operator '*' yfx 300
// %Operator '/' yfx 300
// %Operator '%' yfx 300
// %Operator '**' yfx 200
// %Operator '!' fy 100
// %Operator '-' fy 100
// %Operator '+' fy 100
%token ABSTRACT
%token BOOLEAN BREAK BYTE // BYVALUE
%token CASE CATCH CHAR CLASS CONTINUE // CAST CONST
%token DEFAULT DO DOUBLE
%token ELSE EXTENDS
%token FINAL FINALLY FLOAT FOR // FUTURE
// %token GENERIC GOTO
%token IF IMPLEMENTS IMPORT INSTANCEOF INT INTERFACE // INNER
%token LONG
%token NATIVE NEW NULL
// %token OUTER OPERATOR
%token PACKAGE PRIVATE PROTECTED PUBLIC
%token RETURN // REST
%token SHORT STATIC SUPER SWITCH SYNCHRONIZED
%token THIS THROW THROWS TRANSIENT TRY
%token VOID VOLATILE // VAR
%token WHILE
%token OP_INC OP_DEC
%token OP_SHL OP_SHR OP_SHRR
%token OP_GE OP_LE OP_EQ OP_NE
%token OP_LAND OP_LOR
%token ASS_MUL ASS_DIV ASS_MOD ASS_ADD ASS_SUB
%token ASS_SHL ASS_SHR ASS_SHRR ASS_AND ASS_XOR ASS_OR
%token IDENTIFIER LITERAL BOOLLIT
%start ProgramFile
%%
TypeSpecifier
: TypeName Dimensions_opt
;
TypeName
: PrimitiveType
| QualifiedName
;
ClassNameList
: QualifiedName
| ClassNameList ',' QualifiedName
;
PrimitiveType
: BOOLEAN
| CHAR
| BYTE
| SHORT
| INT
| LONG
| FLOAT
| DOUBLE
| VOID
;
SemiColons
: ';'
| SemiColons ';'
;
ProgramFile
: PackageStatement_opt ImportStatements_opt TypeDeclarations_opt
;
PackageStatement_opt
: /* empty */
| PackageStatement
;
ImportStatements_opt
: /* empty */
| ImportStatements
;
TypeDeclarations_opt
: /* empty */
| TypeDeclarations
;
PackageStatement
: PACKAGE QualifiedName SemiColons
;
TypeDeclarations
: TypeDeclarationOptSemi
| TypeDeclarations TypeDeclarationOptSemi
;
TypeDeclarationOptSemi
: TypeDeclaration SemiColons_opt
;
SemiColons_opt
: /* empty */
| SemiColons
;
ImportStatements
: ImportStatement
| ImportStatements ImportStatement
;
ImportStatement
: IMPORT QualifiedName DotStar_opt SemiColons
;
DotStar_opt
: /* empty */
| '.' '*'
;
QualifiedName
: IDENTIFIER
| QualifiedName '.' IDENTIFIER
;
TypeDeclaration
: ClassHeader '{' FieldDeclarations_opt '}'
;
FieldDeclarations_opt
: /* empty */
| FieldDeclarations
;
ClassHeader
: Modifiers_opt ClassWord IDENTIFIER Extends_opt Implements_opt
;
Modifiers_opt
: /* empty */
| Modifiers
;
Extends_opt
: /* empty */
| Extends
;
Implements_opt
: /* empty */
| Implements
;
Modifiers
: Modifier
| Modifiers Modifier
;
Modifier
: ABSTRACT
| FINAL
| PUBLIC
| PROTECTED
| PRIVATE
| STATIC
| TRANSIENT
| VOLATILE
| NATIVE
| SYNCHRONIZED
;
ClassWord
: CLASS
| INTERFACE
;
Implements
: IMPLEMENTS ClassNameList
;
FieldDeclarations
: FieldDeclarationOptSemi
| FieldDeclarations FieldDeclarationOptSemi
;
FieldDeclarationOptSemi
: FieldDeclaration SemiColons_opt
;
FieldDeclaration
: FieldVariableDeclaration ';'
| MethodDeclaration
| ConstructorDeclaration
| Initializer
| TypeDeclaration
;
FieldVariableDeclaration
: Modifiers_opt TypeSpecifier VariableDeclarators
;
VariableDeclarators
: VariableDeclarator
| VariableDeclarators ',' VariableDeclarator
;
VariableDeclarator
: DeclaratorName VariableInitialization_opt
;
VariableInitialization_opt
: /* empty */
| VariableInitialization
;
VariableInitialization
: '=' VariableInitializer
;
VariableInitializer_opt
: /* empty */
| VariableInitializer
;
VariableInitializer
: Expression
| ArrayInitialization
;
ArrayInitializers
: VariableInitializer
| ArrayInitializers ',' VariableInitializer_opt
;
MethodDeclaration
: Modifiers_opt TypeSpecifier MethodDeclarator Throws_opt MethodBody
;
MethodDeclarator
: DeclaratorName '(' ParameterList_opt ')'
| MethodDeclarator Dimensions
;
ParameterList_opt
: /* empty */
| ParameterList
;
ParameterList
: Parameter
| ParameterList ',' Parameter
;
Parameter
: Final_opt TypeSpecifier DeclaratorName
;
Final_opt
: /* empty */
| FINAL
;
DeclaratorName
: IDENTIFIER
| DeclaratorName Dimensions
;
Throws_opt
: /* empty */
| Throws
;
Throws
: THROWS ClassNameList
;
MethodBody
: Block
| ';'
;
ConstructorDeclaration
: Modifiers_opt ConstructorDeclarator Throws_opt Block
;
ConstructorDeclarator
: IDENTIFIER '(' ParameterList_opt ')'
;
Initializer
: STATIC_opt Block
;
STATIC_opt
: /* empty */
| STATIC
;
Extends
: EXTENDS TypeName
// | Extends ',' TypeName // Why is this here ????
;
Block
: '{' LocalVariableDeclarationsAndStatements_opt '}'
;
LocalVariableDeclarationsAndStatements_opt
: /* empty */
| LocalVariableDeclarationsAndStatements
;
LocalVariableDeclarationsAndStatements
: LocalVariableDeclarationOrStatement
| LocalVariableDeclarationsAndStatements LocalVariableDeclarationOrStatement
;
LocalVariableDeclarationOrStatement
: LocalVariableDeclarationStatement
| Statement
;
LocalVariableDeclarationStatement
: Final_opt TypeSpecifier VariableDeclarators ';'
;
Statement
: EmptyStatement
| LabelStatement ':'
| Expression ';'
| SelectionStatement
| IterationStatement
| JumpStatement
| GuardingStatement
| Block
;
EmptyStatement
: ';'
;
LabelStatement
: IDENTIFIER
| DEFAULT
| CASE ConstantExpression
;
SelectionStatement
: IF ParenthesizedExpression Statement Else_opt
| SWITCH ParenthesizedExpression Block
;
ParenthesizedExpression
: '(' Expression ')'
;
Else_opt
: /*empty */
| ELSE Statement
;
IterationStatement
: WHILE ParenthesizedExpression Statement
| DO Statement WHILE ParenthesizedExpression ';'
| FOR '(' ForInitialization ForBound Expressions_opt ')' Statement
;
ForInitialization
: Expressions ';'
| LocalVariableDeclarationStatement
| ';'
;
ForBound
: Expression_opt ';'
;
Expressions_opt
: /* empty */
| Expressions
;
Expressions
: Expression
| Expressions ',' Expression
;
JumpStatement
: BREAK Identifier_opt ';'
| CONTINUE Identifier_opt ';'
| RETURN Expression_opt ';'
| THROW Expression ';'
;
GuardingStatement
: SYNCHRONIZED ParenthesizedExpression Statement
| TRY Block Handler
;
Handler
: Catches Finally_opt
| Finally
;
Catches
: Catch
| Catches Catch
;
Catch
: CatchHeader Block
;
CatchHeader
: CATCH '(' TypeSpecifier Identifier_opt ')'
;
Identifier_opt
: /* empty */
| IDENTIFIER
;
Finally_opt
: /* empty */
| Finally
;
Finally
: FINALLY Block
;
PrimaryExpression
: QualifiedName
| NotJustName
;
NotJustName
: SpecialName
| NewAllocationExpression
| ComplexPrimary
;
ComplexPrimary
: ParenthesizedExpression
| ComplexPrimaryNoParenthesis
;
ComplexPrimaryNoParenthesis
: LITERAL
| BOOLLIT
| ArrayAccess
| FieldAccess
| MethodCall
;
ArrayAccess
: QualifiedName DimensionExpression
| ComplexPrimary DimensionExpression
;
DimensionExpression
: '[' Expression ']'
;
FieldAccess
: NotJustName '.' IDENTIFIER
| RealPostfixExpression '.' IDENTIFIER
| QualifiedName '.' THIS
| QualifiedName '.' CLASS
| PrimitiveType '.' CLASS
;
MethodCall
: MethodAccess '(' ArgumentList_opt ')'
;
MethodAccess
: ComplexPrimaryNoParenthesis
| SpecialName
| QualifiedName
;
SpecialName
: THIS
| SUPER
| NULL
;
ArgumentList_opt
: /* empty */
| ArgumentList
;
ArgumentList
: Expression
| ArgumentList ',' Expression
;
NewAllocationExpression
: PlainNewAllocationExpression
| QualifiedName '.' PlainNewAllocationExpression
;
PlainNewAllocationExpression
: ArrayAllocationExpression ArrayInitialization_opt '}'
| ClassAllocationExpression ClasssBody_opt
;
ArrayInitialization_opt
: /* empty */
| ArrayInitialization
;
ArrayInitialization
: '{' ArrayInitializers_opt '}'
;
ClasssBody_opt
: /* empty */
| '{' FieldDeclarations_opt '}'
;
ArrayInitializers_opt
: /* empty */
| ArrayInitializers
;
ClassAllocationExpression
: NEW TypeName '(' ArgumentList_opt ')'
;
ArrayAllocationExpression
: NEW TypeName DimensionExpressions Dimensions
| NEW TypeName DimensionExpressions
| NEW TypeName Dimensions
;
DimensionExpressions
: DimensionExpression
| DimensionExpressions DimensionExpression
;
Dimensions_opt
: /* empty */
| Dimensions
;
Dimensions
: Dimension
| Dimensions Dimension
;
Dimension
: '[' ']'
;
PostfixExpression
: PrimaryExpression
| RealPostfixExpression
;
RealPostfixExpression
: PostfixExpression OP_INC
| PostfixExpression OP_DEC
;
UnaryExpression
: OP_INC UnaryExpression
| OP_DEC UnaryExpression
| ArithmeticUnaryOperator CastExpression
| LogicalUnaryExpression
;
LogicalUnaryExpression
: PostfixExpression
| LogicalUnaryOperator UnaryExpression
;
LogicalUnaryOperator
: '~'
| '!'
;
ArithmeticUnaryOperator
: '+'
| '-'
;
CastExpression
: UnaryExpression
| '(' TypeExpression ')' CastExpression
| ParenthesizedExpression LogicalUnaryExpression
;
TypeExpression
: PrimitiveTypeExpression
| ClassTypeExpression
;
PrimitiveTypeExpression
: PrimitiveType Dimensions_opt
;
ClassTypeExpression
: QualifiedName Dimensions_opt
;
MultiplicativeExpression
: CastExpression
| MultiplicativeExpression '*' CastExpression
| MultiplicativeExpression '/' CastExpression
| MultiplicativeExpression '%' CastExpression
;
AdditiveExpression
: MultiplicativeExpression
| AdditiveExpression '+' MultiplicativeExpression
| AdditiveExpression '-' MultiplicativeExpression
;
ShiftExpression
: AdditiveExpression
| ShiftExpression OP_SHL AdditiveExpression
| ShiftExpression OP_SHR AdditiveExpression
| ShiftExpression OP_SHRR AdditiveExpression
;
RelationalExpression
: ShiftExpression
| RelationalExpression '<' ShiftExpression
| RelationalExpression '>' ShiftExpression
| RelationalExpression OP_LE ShiftExpression
| RelationalExpression OP_GE ShiftExpression
| RelationalExpression INSTANCEOF TypeSpecifier
;
EqualityExpression
: RelationalExpression
| EqualityExpression OP_EQ RelationalExpression
| EqualityExpression OP_NE RelationalExpression
;
AndExpression
: EqualityExpression
| AndExpression '&' EqualityExpression
;
ExclusiveOrExpression
: AndExpression
| ExclusiveOrExpression '^' AndExpression
;
InclusiveOrExpression
: ExclusiveOrExpression
| InclusiveOrExpression '|' ExclusiveOrExpression
;
ConditionalAndExpression
: InclusiveOrExpression
| ConditionalAndExpression OP_LAND InclusiveOrExpression
;
ConditionalOrExpression
: ConditionalAndExpression
| ConditionalOrExpression OP_LOR ConditionalAndExpression
;
ConditionalExpression
: ConditionalOrExpression
| ConditionalOrExpression '?' Expression ':' ConditionalExpression
;
AssignmentExpression
: ConditionalExpression
| UnaryExpression AssignmentOperator AssignmentExpression
;
AssignmentOperator
: '='
| ASS_MUL
| ASS_DIV
| ASS_MOD
| ASS_ADD
| ASS_SUB
| ASS_SHL
| ASS_SHR
| ASS_SHRR
| ASS_AND
| ASS_XOR
| ASS_OR
;
Expression
: AssignmentExpression
;
Expression_opt
: /* empty */
| Expression
;
ConstantExpression
: ConditionalExpression
;
%%
This file was generated on Wed Dec 10 14:40:52 PST 2003 from file java11.grm
by the ilog.language.tools.Hilite Java tool written by Hassan Aït-Kaci