home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / java.grm < prev    next >
Encoding:
Text File  |  2004-07-12  |  17.7 KB  |  816 lines

  1. /*------------------------------------------------------------------
  2.  * Copyright (C)
  3.  *   1996, 1997, 1998 Dmitri Bronnikov, All rights reserved.
  4.  *
  5.  * THIS GRAMMAR IS PROVIDED "AS IS" WITHOUT  ANY  EXPRESS  OR
  6.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  7.  * WARRANTIES  OF  MERCHANTABILITY  AND  FITNESS  FOR  A  PARTICULAR
  8.  * PURPOSE, OR NON-INFRINGMENT.
  9.  *
  10.  * Bronikov@inreach.com
  11.  *
  12.  *------------------------------------------------------------------
  13.  *
  14.  * VERSION 1.06 DATE 20 AUG 1998
  15.  *
  16.  *------------------------------------------------------------------
  17.  *
  18.  * UPDATES
  19.  *
  20.  * 1.06 Correction of Java 1.1 syntax
  21.  * 1.05 Yet more Java 1.1
  22.  *      <qualified name>.<allocation expression>
  23.  * 1.04 More Java 1.1 features:
  24.  *      <class name>.this
  25.  *      <type name>.class
  26.  * 1.03 Added Java 1.1 features:
  27.  *      inner classes,
  28.  *      anonymous classes,
  29.  *      non-static initializer blocks,
  30.  *      array initialization by new operator
  31.  * 1.02 Corrected cast expression syntax
  32.  * 1.01 All shift/reduce conflicts, except dangling else, resolved
  33.  *
  34.  *------------------------------------------------------------------
  35.  *
  36.  * PARSING CONFLICTS RESOLVED
  37.  *
  38.  * Some Shift/Reduce conflicts have been resolved at the expense of
  39.  * the grammar defines a superset of the language. The following
  40.  * actions have to be performed to complete program syntax checking:
  41.  *
  42.  * 1) Check that modifiers applied to a class, interface, field,
  43.  *    or constructor are allowed in respectively a class, inteface,
  44.  *    field or constructor declaration. For example, a class
  45.  *    declaration should not allow other modifiers than abstract,
  46.  *    final and public.
  47.  *
  48.  * 2) For an expression statement, check it is either increment, or
  49.  *    decrement, or assignment expression.
  50.  *
  51.  * 3) Check that type expression in a cast operator indicates a type.
  52.  *    Some of the compilers that I have tested will allow simultaneous
  53.  *    use of identically named type and variable in the same scope
  54.  *    depending on context.
  55.  *
  56.  * 4) Change lexical definition to change '[' optionally followed by
  57.  *    any number of white-space characters immediately followed by ']'
  58.  *    to OP_DIM token. I defined this token as [\[]{white_space}*[\]]
  59.  *    in the lexer.
  60.  *
  61.  *------------------------------------------------------------------
  62.  *
  63.  * UNRESOLVED SHIFT/REDUCE CONFLICTS
  64.  *
  65.  * Dangling else in if-then-else
  66.  *
  67.  *------------------------------------------------------------------
  68.  */
  69.  
  70. %token DOPEN     "\(";
  71. %token DCLOSE    "\)";
  72. %token COPEN     "\{";
  73. %token CCLOSE    "\}";
  74. %token BOPEN     "\[";
  75. %token BCLOSE    "\]";
  76. %token SEMICOLON "\;";
  77. %token COMMA     "\,";
  78. %right DOT       "\.";
  79.  
  80. %token OP_EQ    "==";
  81. %token OP_LE    "\<=";
  82. %token OP_GE    "\>=";
  83. %token OP_NE    "!=";
  84. %token OP_LOR   "\|\|";
  85. %token OP_LAND  "&&";
  86. %token OP_INC   "\+\+";
  87. %token OP_DEC   "\-\-";
  88. %token OP_SHR   "\>\>";
  89. %token OP_SHL   "\<\<";
  90. %token OP_SHRR  "\>\>\>";
  91. %token ASS_OP   "\+= | \-= | \*= | /= | &= | \|= | \^= | \%= | \<\<= | \>\>= | \>\>\>=";
  92.  
  93. %right EQ    "\=";
  94. %token GT    "\>";
  95. %token LT    "\<";
  96. %token NOT   "\!";
  97. %token TILDE "\~";
  98. %token QM    "\?";
  99. %token COLON "\:";
  100. %token PLUS  "\+";
  101. %token MINUS "\-";
  102. %token MULT  "\*";
  103. %token DIV   "\/";
  104. %token AND   "\&";
  105. %token OR    "\|";
  106. %token XOR   "\^";
  107. %token MOD   "\%";
  108.  
  109. %token BOOLLIT "true|false";
  110.  
  111. %token ABSTRACT     "abstract";
  112. %token DO           "do";
  113. %token IMPLEMENTS   "implements";
  114. %token PACKAGE      "package";
  115. %token THROW        "throw";
  116. %token BOOLEAN      "boolean";
  117. %token DOUBLE       "double";
  118. %token IMPORT       "import";
  119. %token PRIVATE      "private";
  120. %token THROWS       "throws";
  121. %token BREAK        "break";
  122.  
  123. %right ELSE         "else";
  124.  
  125. %token INNER        "inner";
  126. %token PROTECTED    "protected";
  127. %token TRANSIENT    "transient";
  128. %token BYTE         "byte";
  129. %token EXTENDS      "extends";
  130. %token INSTANCEOF   "instanceof";
  131. %token PUBLIC       "public";
  132. %token TRY          "try";
  133. %token CASE         "case";
  134. %token FINAL        "final";
  135. %token INT          "int";
  136. %token REST         "rest";
  137. %token VAR          "var";
  138. %token CAST         "cast";
  139. %token FINALLY      "finally";
  140. %token INTERFACE    "interface";
  141. %token RETURN       "return";
  142. %token VOID         "void";
  143. %token CATCH        "catch";
  144. %token FLOAT        "float";
  145. %token LONG         "long";
  146. %token SHORT        "short";
  147. %token VOLATILE     "volatile";
  148. %token CHAR         "char";
  149. %token FOR          "for";
  150. %token NATIVE       "native";
  151. %token STATIC       "static";
  152. %token WHILE        "while";
  153. %token CLASS        "class";
  154. %token FUTURE       "future";
  155. %token NEW          "new";
  156. %token SUPER        "super";
  157. %token CONST        "const";
  158. %token GENERIC      "generic";
  159. %token NULL         "null";
  160. %token SWITCH       "switch";
  161. %token CONTINUE     "continue";
  162. %token GOTO         "goto";
  163. %token OPERATOR     "operator";
  164. %token SYNCHRONIZED "synchronized";
  165. %token DEFAULT      "default";
  166. %token IF           "if";
  167. %token OUTER        "outer";
  168. %token THIS         "this";
  169.  
  170. %ab HexDigit        "[0-9a-fA-F]";
  171. %ab Digit           "[0-9]";
  172. %ab OctalDigit      "[0-7]";
  173. %ab TetraDigit      "[0-3]";
  174. %ab NonZeroDigit    "[1-9]";
  175. %ab Letter          "[a-zA-Z_]";
  176. %ab AnyButSlash     "[^\/]";
  177. %ab AnyButAstr      "[^\*]";
  178. %ab UniEsc          "[\1b]";
  179.  
  180. %ab OctEscape1      "\\ <OctalDigit>";
  181. %ab OctEscape2      "\\ <OctalDigit><OctalDigit>";
  182. %ab OctEscape3      "\\ <TetraDigit><OctalDigit><OctalDigit>";
  183. %ab OctEscape       "(<OctEscape1>|<OctEscape2>|<OctEscape3>)";
  184.  
  185. %ab Escape          "[\\]([rnbft\\\'\"])";
  186. %ab ULetter         "(<Letter>|<UniEsc>)";
  187. %ab Identifier      "<ULetter>(<ULetter>|<Digit>)*";
  188.  
  189. %ab IntSuffix       "(l|L)";
  190. %ab DecimalNum      "<NonZeroDigit><Digit>*<IntSuffix>?";
  191. %ab OctalNum        "0 <OctalDigit>*<IntSuffix>?";
  192. %ab HexNum          "0 (x|X) <HexDigit><HexDigit>*<IntSuffix>?";
  193. %ab IntegerLiteral  "(<DecimalNum>|<OctalNum>|<HexNum>)";
  194.  
  195. %ab Sign            "(\+ | \-)";
  196. %ab FlSuffix        "(f|F|d|D)";
  197. %ab SignedInt       "<Sign>?<Digit>+";
  198. %ab Expo            "(e|E)";
  199. %ab ExponentPart    "<Expo><SignedInt>?";
  200. %ab Float1          "<Digit>+ \. (<Digit>+)?<ExponentPart>?<FlSuffix>?";
  201. %ab Float2          "\. <Digit>+<ExponentPart>?<FlSuffix>?";
  202. %ab Float3          "<Digit>+<ExponentPart><FlSuffix>?";
  203. %ab Float4          "<Digit>+<FlSuffix>";
  204. %ab FloatingPoint   "(<Float1>|<Float2>|<Float3>|<Float4>)";
  205.  
  206. %ab AnyChrChr       "[^\\']";
  207. %ab AnyStrChr       "[^\\\"]";
  208. %ab Character       "\' (<Escape>|<OctEscape>|<AnyChrChr>)  \'";
  209. %ab String          "\" (<Escape>|<OctEscape>|<AnyStrChr>)* \"";
  210. %ab Numeric         "(<IntegerLiteral>|<FloatingPoint>)";
  211.  
  212. %token LITERAL      "(<Numeric>|<Character>|<String>)";
  213.  
  214. %token IDENTIFIER   "([a-zA-Z_]|[\1b])(([a-zA-Z_]|[\1b])|[0-9])*";
  215.  
  216.  
  217. %token OP_DIM "\[ ([\r\n\t\ ]|( \/ \* ([^\*]| \* [^\/])* \*  \/ |
  218.                \/ \/ (.*)))* \]";
  219.  
  220. %token SPACES "(\ )+";
  221. %token TAB "\t";
  222.  
  223. %token EOL "\r(\n)?|\n"; // eol
  224.  
  225. %token JAVADOC           "/ \* \* ([^\*]|[\*][^/])* \* /";
  226. %token MULTILINECOMMENT  "/ \* ([^\*]|\*[^/])* \* /";
  227.  
  228. %token SINGLELINECOMMENT "\/ \/ (.*)";
  229.  
  230. %start CompilationUnit;
  231.  
  232. %%
  233.  
  234. TypeSpecifier
  235.     : TypeName
  236.     | TypeName Dims
  237.     ;
  238.  
  239. TypeName
  240.     : PrimitiveType
  241.     | QualifiedName %prec DOT
  242.     ;
  243.  
  244. ClassNameList
  245.   : QualifiedName
  246.   | ClassNameList COMMA QualifiedName
  247.     ;
  248.  
  249. PrimitiveType
  250.     : BOOLEAN
  251.     | CHAR
  252.     | BYTE
  253.     | SHORT
  254.     | INT
  255.     | LONG
  256.     | FLOAT
  257.     | DOUBLE
  258.     | VOID
  259.     ;
  260.  
  261. SemiColons
  262.     : SEMICOLON
  263.   | SemiColons SEMICOLON
  264.   ;
  265.  
  266. CompilationUnit
  267.     : ProgramFile
  268.   ;
  269.  
  270. ProgramFile
  271.     : PackageStatement ImportStatements TypeDeclarations
  272.     | PackageStatement ImportStatements
  273.     | PackageStatement                  TypeDeclarations
  274.     |                  ImportStatements TypeDeclarations
  275.     | PackageStatement
  276.     |                  ImportStatements
  277.     |                                   TypeDeclarations
  278.     ;
  279.  
  280. PackageStatement
  281.     : PACKAGE QualifiedName SemiColons
  282.     ;
  283.  
  284. TypeDeclarations
  285.     : TypeDeclarationOptSemi
  286.     | TypeDeclarations TypeDeclarationOptSemi
  287.     ;
  288.  
  289. TypeDeclarationOptSemi
  290.   : TypeDeclaration
  291.   | TypeDeclaration SemiColons
  292.   ;
  293.  
  294. ImportStatements
  295.     : ImportStatement
  296.     | ImportStatements ImportStatement
  297.     ;
  298.  
  299. ImportStatement
  300.     : IMPORT QualifiedName SemiColons
  301.     | IMPORT QualifiedName DOT MULT SemiColons
  302.     ;
  303.  
  304. QualifiedName
  305.     : IDENTIFIER 
  306.     | QualifiedName DOT IDENTIFIER 
  307.     ;
  308.  
  309. TypeDeclaration
  310.     :         ClassHeader COPEN FieldDeclarations CCLOSE
  311.     |         ClassHeader COPEN CCLOSE
  312.   | JAVADOC ClassHeader COPEN FieldDeclarations CCLOSE
  313.   | JAVADOC ClassHeader COPEN CCLOSE
  314.     ;
  315.  
  316. ClassHeader
  317.     : Modifiers ClassWord IDENTIFIER Extends Interfaces
  318.     | Modifiers ClassWord IDENTIFIER Extends
  319.     | Modifiers ClassWord IDENTIFIER         Interfaces
  320.     |           ClassWord IDENTIFIER Extends Interfaces
  321.     | Modifiers ClassWord IDENTIFIER
  322.     |           ClassWord IDENTIFIER Extends
  323.     |           ClassWord IDENTIFIER         Interfaces
  324.     |           ClassWord IDENTIFIER
  325.     ;
  326.  
  327. Modifiers
  328.     : Modifier 
  329.     | Modifiers Modifier 
  330.     ;
  331.  
  332. Modifier
  333.     : ABSTRACT
  334.     | FINAL
  335.     | PUBLIC
  336.     | PROTECTED
  337.     | PRIVATE
  338.     | STATIC
  339.     | TRANSIENT
  340.     | VOLATILE
  341.     | NATIVE
  342.     | SYNCHRONIZED
  343.     ;
  344.  
  345. ClassWord
  346.     : CLASS
  347.     | INTERFACE
  348.     ;
  349.  
  350. Interfaces
  351.     : IMPLEMENTS ClassNameList
  352.     ;
  353.  
  354. FieldDeclarations
  355.     : FieldDeclarationOptSemi
  356.   | FieldDeclarations FieldDeclarationOptSemi
  357.     ;
  358.  
  359. FieldDeclarationOptSemi
  360.   : FieldDeclaration
  361.   | FieldDeclaration SemiColons
  362.   ;
  363.  
  364. FieldDeclaration
  365.     : FieldVariableDeclaration SEMICOLON
  366.     | MethodDeclaration
  367.     | ConstructorDeclaration
  368.     | StaticInitializer
  369.   | NonStaticInitializer
  370.   | TypeDeclaration
  371.     ;
  372.  
  373. FieldVariableDeclaration
  374.     :         Modifiers TypeSpecifier VariableDeclarators
  375.     |                   TypeSpecifier VariableDeclarators
  376.   | JAVADOC Modifiers TypeSpecifier VariableDeclarators
  377.   | JAVADOC           TypeSpecifier VariableDeclarators
  378.     ;
  379.  
  380. VariableDeclarators
  381.     : VariableDeclarator
  382.     | VariableDeclarators COMMA VariableDeclarator
  383.     ;
  384.  
  385. VariableDeclarator
  386.     : DeclaratorName
  387.     | DeclaratorName EQ VariableInitializer
  388.     ;
  389.  
  390. VariableInitializer
  391.     : Expression
  392.     | COPEN CCLOSE
  393.   | COPEN ArrayInitializers CCLOSE
  394.   ;
  395.  
  396. ArrayInitializers
  397.     : VariableInitializer
  398.     | ArrayInitializers COMMA VariableInitializer
  399.     | ArrayInitializers COMMA
  400.     ;
  401.  
  402. MethodDeclaration
  403.     :         Modifiers TypeSpecifier MethodDeclarator Throws MethodBody
  404.     |         Modifiers TypeSpecifier MethodDeclarator        MethodBody
  405.     |                   TypeSpecifier MethodDeclarator Throws MethodBody
  406.     |                   TypeSpecifier MethodDeclarator        MethodBody
  407.   | JAVADOC Modifiers TypeSpecifier MethodDeclarator Throws MethodBody
  408.   | JAVADOC Modifiers TypeSpecifier MethodDeclarator        MethodBody
  409.   | JAVADOC           TypeSpecifier MethodDeclarator Throws MethodBody
  410.   | JAVADOC           TypeSpecifier MethodDeclarator        MethodBody
  411.     ;
  412.  
  413. MethodDeclarator
  414.     : DeclaratorName DOPEN ParameterList DCLOSE
  415.     | DeclaratorName DOPEN DCLOSE
  416.     | MethodDeclarator OP_DIM
  417.     ;
  418.  
  419. ParameterList
  420.     : Parameter
  421.     | ParameterList COMMA Parameter
  422.     ;
  423.  
  424. Parameter
  425.     : TypeSpecifier DeclaratorName
  426.   | FINAL TypeSpecifier DeclaratorName
  427.     ;
  428.  
  429. DeclaratorName
  430.     : IDENTIFIER
  431.   | DeclaratorName OP_DIM
  432.   ;
  433.  
  434. Throws
  435.     : THROWS ClassNameList
  436.     ;
  437.  
  438. MethodBody
  439.     : Block
  440.     | SEMICOLON
  441.     ;
  442.  
  443. ConstructorDeclaration
  444.     :         Modifiers ConstructorDeclarator Throws Block
  445.     |         Modifiers ConstructorDeclarator        Block
  446.     |                   ConstructorDeclarator Throws Block
  447.     |                   ConstructorDeclarator        Block
  448.   | JAVADOC Modifiers ConstructorDeclarator Throws Block
  449.   | JAVADOC Modifiers ConstructorDeclarator        Block
  450.   | JAVADOC           ConstructorDeclarator Throws Block
  451.   | JAVADOC           ConstructorDeclarator        Block
  452.     ;
  453.  
  454. ConstructorDeclarator
  455.     : IDENTIFIER DOPEN ParameterList DCLOSE
  456.     | IDENTIFIER DOPEN DCLOSE
  457.     ;
  458.  
  459. StaticInitializer
  460.     :         STATIC Block
  461.   | JAVADOC STATIC Block
  462.     ;
  463.  
  464. NonStaticInitializer
  465.   : Block
  466.   ;
  467.  
  468. Extends
  469.     : EXTENDS TypeName
  470.     | Extends COMMA TypeName
  471.     ;
  472.  
  473. Block
  474.     : COPEN LocalVariableDeclarationsAndStatements CCLOSE
  475.     | COPEN CCLOSE
  476.   ;
  477.  
  478. LocalVariableDeclarationsAndStatements
  479.     : LocalVariableDeclarationOrStatement 
  480.     | LocalVariableDeclarationsAndStatements LocalVariableDeclarationOrStatement 
  481.     ;
  482.  
  483. LocalVariableDeclarationOrStatement
  484.     : LocalVariableDeclarationStatement
  485.     | Statement
  486.     ;
  487.  
  488. LocalVariableDeclarationStatement
  489.     : TypeSpecifier VariableDeclarators SEMICOLON
  490.   | FINAL TypeSpecifier VariableDeclarators SEMICOLON
  491.     ;
  492.  
  493. Statement
  494.     : EmptyStatement
  495.     | LabelStatement
  496.     | ExpressionStatement SEMICOLON
  497.   | SelectionStatement
  498.   | IterationStatement
  499.     | JumpStatement
  500.     | GuardingStatement
  501.     | Block
  502.     ;
  503.  
  504. EmptyStatement
  505.     : SEMICOLON
  506.   ;
  507.  
  508. LabelStatement
  509.     : IDENTIFIER COLON
  510.   | CASE ConstantExpression COLON
  511.     | DEFAULT COLON
  512.   ;
  513.  
  514. ExpressionStatement
  515.     : Expression
  516.     ;
  517.  
  518. SelectionStatement
  519.     : IF DOPEN Expression DCLOSE Statement %prec ELSE
  520.   | IF DOPEN Expression DCLOSE Statement ELSE Statement %prec ELSE
  521.   | SWITCH DOPEN Expression DCLOSE Block
  522.   ;
  523.  
  524. IterationStatement
  525.     : WHILE DOPEN Expression DCLOSE Statement
  526.     | DO Statement WHILE DOPEN Expression DCLOSE SEMICOLON
  527.     | FOR DOPEN ForInit ForExpr ForIncr DCLOSE Statement
  528.     | FOR DOPEN ForInit ForExpr         DCLOSE Statement
  529.     ;
  530.  
  531. ForInit
  532.     : ExpressionStatements SEMICOLON
  533.     | LocalVariableDeclarationStatement
  534.     | SEMICOLON
  535.     ;
  536.  
  537. ForExpr
  538.     : Expression SEMICOLON
  539.     | SEMICOLON
  540.     ;
  541.  
  542. ForIncr
  543.     : ExpressionStatements
  544.     ;
  545.  
  546. ExpressionStatements
  547.     : ExpressionStatement 
  548.     | ExpressionStatements COMMA ExpressionStatement
  549.     ;
  550.  
  551. JumpStatement
  552.     : BREAK IDENTIFIER SEMICOLON
  553.     | BREAK            SEMICOLON
  554.   | CONTINUE IDENTIFIER SEMICOLON
  555.     | CONTINUE            SEMICOLON
  556.     | RETURN Expression SEMICOLON
  557.     | RETURN            SEMICOLON
  558.     | THROW Expression SEMICOLON
  559.     ;
  560.  
  561. GuardingStatement
  562.     : SYNCHRONIZED DOPEN Expression DCLOSE Statement
  563.     | TRY Block Finally
  564.     | TRY Block Catches
  565.     | TRY Block Catches Finally
  566.     ;
  567.  
  568. Catches
  569.     : Catch
  570.     | Catches Catch
  571.     ;
  572.  
  573. Catch
  574.     : CatchHeader Block
  575.     ;
  576.  
  577. CatchHeader
  578.     : CATCH DOPEN TypeSpecifier IDENTIFIER DCLOSE
  579.     | CATCH DOPEN TypeSpecifier DCLOSE
  580.     ;
  581.  
  582. Finally
  583.     : FINALLY Block
  584.     ;
  585.  
  586. PrimaryExpression
  587.     : QualifiedName %prec DOPEN
  588.     | NotJustName 
  589.     ;
  590.  
  591. NotJustName
  592.     : SpecialName 
  593.     | NewAllocationExpression 
  594.     | ComplexPrimary 
  595.     ;
  596.  
  597. ComplexPrimary
  598.     : DOPEN Expression DCLOSE
  599.     | ComplexPrimaryNoParenthesis 
  600.     ;
  601.  
  602. ComplexPrimaryNoParenthesis
  603.     : LITERAL
  604.     | BOOLLIT
  605.     | ArrayAccess
  606.     | FieldAccess
  607.     | MethodCall
  608.     ;
  609.  
  610. ArrayAccess
  611.     : QualifiedName  BOPEN Expression BCLOSE
  612.     | ComplexPrimary BOPEN Expression BCLOSE
  613.     ;
  614.  
  615. FieldAccess
  616.     : NotJustName DOT IDENTIFIER
  617.     | RealPostfixExpression DOT IDENTIFIER
  618.   | QualifiedName DOT THIS
  619.   | QualifiedName DOT CLASS
  620.   | PrimitiveType DOT CLASS
  621.     ;
  622.  
  623. MethodCall
  624.     : MethodAccess DOPEN ArgumentList DCLOSE
  625.     | MethodAccess DOPEN DCLOSE
  626.     ;
  627.  
  628. MethodAccess
  629.     : ComplexPrimaryNoParenthesis
  630.     | SpecialName
  631.     | QualifiedName
  632.     ;
  633.  
  634. SpecialName
  635.     : THIS
  636.     | SUPER
  637.     | NULL
  638.     ;
  639.  
  640. ArgumentList
  641.     : Expression
  642.     | ArgumentList COMMA Expression
  643.     ;
  644.  
  645. NewAllocationExpression
  646.   : PlainNewAllocationExpression
  647.   | QualifiedName DOT PlainNewAllocationExpression
  648.   ;
  649.  
  650. PlainNewAllocationExpression
  651.      : ArrayAllocationExpression
  652.      | ClassAllocationExpression
  653.      | ArrayAllocationExpression COPEN CCLOSE
  654.      | ClassAllocationExpression COPEN CCLOSE
  655.      | ArrayAllocationExpression COPEN ArrayInitializers CCLOSE
  656.      | ClassAllocationExpression COPEN FieldDeclarations CCLOSE
  657.      ;
  658.  
  659. ClassAllocationExpression
  660.     : NEW TypeName DOPEN ArgumentList DCLOSE
  661.     | NEW TypeName DOPEN              DCLOSE
  662.   ;
  663.  
  664. ArrayAllocationExpression
  665.     : NEW TypeName DimExprs Dims
  666.     | NEW TypeName DimExprs
  667.   | NEW TypeName Dims
  668.     ;
  669.  
  670. DimExprs
  671.     : DimExpr
  672.     | DimExprs DimExpr
  673.     ;
  674.  
  675. DimExpr
  676.     : BOPEN Expression BCLOSE
  677.     ;
  678.  
  679. Dims
  680.     : OP_DIM
  681.     | Dims OP_DIM
  682.     ;
  683.  
  684. PostfixExpression
  685.     : PrimaryExpression 
  686.     | RealPostfixExpression 
  687.     ;
  688.  
  689. RealPostfixExpression
  690.     : PostfixExpression OP_INC
  691.     | PostfixExpression OP_DEC
  692.     ;
  693.  
  694. UnaryExpression
  695.     : OP_INC UnaryExpression
  696.     | OP_DEC UnaryExpression
  697.     | ArithmeticUnaryOperator CastExpression
  698.     | LogicalUnaryExpression 
  699.     ;
  700.  
  701. LogicalUnaryExpression
  702.     : PostfixExpression 
  703.     | LogicalUnaryOperator UnaryExpression
  704.     ;
  705.  
  706. LogicalUnaryOperator
  707.     : TILDE
  708.     | NOT
  709.     ;
  710.  
  711. ArithmeticUnaryOperator
  712.     : PLUS
  713.     | MINUS
  714.     ;
  715.  
  716. CastExpression
  717.     : UnaryExpression 
  718.     | DOPEN PrimitiveTypeExpression DCLOSE CastExpression
  719.     | DOPEN ClassTypeExpression DCLOSE CastExpression
  720.     | DOPEN Expression DCLOSE LogicalUnaryExpression
  721.     ;
  722.  
  723. PrimitiveTypeExpression
  724.     : PrimitiveType 
  725.   | PrimitiveType Dims
  726.   ;
  727.  
  728. ClassTypeExpression
  729.     : QualifiedName Dims
  730.   ;
  731.  
  732. MultiplicativeExpression
  733.     : CastExpression 
  734.     | MultiplicativeExpression MULT CastExpression
  735.     | MultiplicativeExpression DIV CastExpression
  736.     | MultiplicativeExpression MOD CastExpression
  737.     ;
  738.  
  739. AdditiveExpression
  740.     : MultiplicativeExpression 
  741.   | AdditiveExpression PLUS MultiplicativeExpression
  742.     | AdditiveExpression MINUS MultiplicativeExpression
  743.   ;
  744.  
  745. ShiftExpression 
  746.     : AdditiveExpression 
  747.   | ShiftExpression OP_SHL AdditiveExpression
  748.   | ShiftExpression OP_SHR AdditiveExpression
  749.   | ShiftExpression OP_SHRR AdditiveExpression
  750.     ;
  751.  
  752. RelationalExpression
  753.     : ShiftExpression 
  754.   | RelationalExpression LT ShiftExpression
  755.     | RelationalExpression GT ShiftExpression
  756.     | RelationalExpression OP_LE ShiftExpression
  757.     | RelationalExpression OP_GE ShiftExpression
  758.     | RelationalExpression INSTANCEOF TypeSpecifier
  759.     ;
  760.  
  761. EqualityExpression
  762.     : RelationalExpression 
  763.   | EqualityExpression OP_EQ RelationalExpression
  764.   | EqualityExpression OP_NE RelationalExpression
  765.   ;
  766.  
  767. AndExpression
  768.     : EqualityExpression 
  769.   | AndExpression AND EqualityExpression
  770.   ;
  771.  
  772. ExclusiveOrExpression
  773.     : AndExpression 
  774.     | ExclusiveOrExpression XOR AndExpression
  775.     ;
  776.  
  777. InclusiveOrExpression
  778.     : ExclusiveOrExpression 
  779.     | InclusiveOrExpression OR ExclusiveOrExpression
  780.     ;
  781.  
  782. ConditionalAndExpression
  783.     : InclusiveOrExpression 
  784.     | ConditionalAndExpression OP_LAND InclusiveOrExpression
  785.     ;
  786.  
  787. ConditionalOrExpression
  788.     : ConditionalAndExpression 
  789.     | ConditionalOrExpression OP_LOR ConditionalAndExpression
  790.     ;
  791.  
  792. ConditionalExpression
  793.     : ConditionalOrExpression 
  794.     | ConditionalOrExpression QM Expression COLON ConditionalExpression
  795.     ;
  796.  
  797. AssignmentExpression
  798.     : ConditionalExpression 
  799.     | UnaryExpression AssignmentOperator AssignmentExpression
  800.     ;
  801.  
  802. AssignmentOperator
  803.     : EQ
  804.     | ASS_OP
  805.     ;
  806.  
  807. Expression
  808.     : AssignmentExpression
  809.   ;
  810.  
  811. ConstantExpression
  812.     : ConditionalExpression
  813.     ;
  814.  
  815.  
  816.