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.egrm < prev    next >
Encoding:
Text File  |  2004-07-12  |  11.2 KB  |  559 lines

  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. *     http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* Java Grammar */
  17.  
  18. %ab HexDigit        : [0-9a-fA-F];
  19. %ab Digit           : [0-9];
  20. %ab OctalDigit      : [0-7];
  21. %ab TetraDigit      : [0-3];
  22. %ab NonZeroDigit    : [1-9];
  23. %ab Letter          : [a-zA-Z_];
  24. %ab AnyButSlash     : [^/];
  25. %ab AnyButAstr      : [^*];
  26. %ab UniEsc          : [\u0001];
  27.  
  28. %ab OctEscape1      : "\\" OctalDigit;
  29. %ab OctEscape2      : "\\" OctalDigit OctalDigit;
  30. %ab OctEscape3      : "\\" TetraDigit OctalDigit OctalDigit;
  31. %ab OctEscape       : OctEscape1 | OctEscape2 | OctEscape3;
  32.  
  33. %ab Escape          : [\\] [rnbft\\'"];
  34. %ab ULetter         : Letter | UniEsc;
  35. Identifier          : ULetter ( ULetter Digit )*;
  36.  
  37. %ab IntSuffix       : "l" | "L";
  38. %ab DecimalNum      : NonZeroDigit Digit* IntSuffix? ;
  39. %ab OctalNum        : "0" OctalDigit* IntSuffix? ;
  40. %ab HexNum          : "0" ("x"|"X") HexDigit HexDigit* IntSuffix? ;
  41. %ab IntegerLiteral  : DecimalNum | OctalNum | HexNum;
  42.                                                                                                                                                                                
  43. %ab Sign            : "+" | "-";
  44. %ab FlSuffix        : "f" | "F" | "d" | "D";
  45. %ab SignedInt       : Sign? Digit+ ;
  46. %ab Expo            : "e" | "E" ;
  47. %ab ExponentPart    : Expo SignedInt? ;
  48. %ab Float1          : Digit+ "." (Digit+)? ExponentPart? FlSuffix?;
  49. %ab Float2          : "." Digit+ ExponentPart? FlSuffix? ;
  50. %ab Float3          : Digit+ ExponentPart FlSuffix? ;
  51. %ab Float4          : Digit+ FlSuffix ;
  52. %ab FloatingPoint   : Float1 | Float2 | Float3 | Float4 ;
  53.  
  54. %ab AnyChrChr       : [^\\'] ;
  55. %ab AnyStrChr       : [^\\"] ;
  56. %ab Character       : "'" (Escape | OctEscape | AnyChrChr)  "'" ;
  57. %ab String          : "\"" (Escape | OctEscape | AnyStrChr)* "\"";
  58. %ab Numeric         : IntegerLiteral | FloatingPoint ;
  59.  
  60. LITERAL         : Numeric | Character | String ;
  61.  
  62. IDENTIFIER      : ([a-zA-Z_] | [\u0001]) (([a-zA-Z_] | [\u0001]) | [0-9])*;
  63.  
  64. OP_DIM          : "[" ([\r\n\t\ ] | ( "/" "\*" ([^\*] | "\*" [^/])* "\*" "/" |
  65.                   "//" (.*)))* "]";
  66.  
  67. %ab SPACES          : " "+;
  68. %ab TAB             : "\t";
  69. %ab EOL             : "\r" "\n"? | "\n" ;
  70. // JAVADOC           : "/**" ([^*] | [*] [^/])* "*/";
  71.  
  72. JAVADOC : "/**" Description Property+ "*/";
  73.  
  74. Description : ([\*\n\r\ \t]+ | DescriptionText)* ;
  75. DescriptionText : [A-Za-z<>%]+ ([\ \t]+ [A-Za-z<>%]+)* ;
  76. Property : "@" PropertyIdentifier [\ \t]+ Description ;
  77. PropertyIdentifier : [A-Za-z]+ ;
  78.  
  79. %ab MULTILINECOMMENT  : "/*" [^*] ([^*] | "*" [^/])* "*/";
  80. %ab SINGLELINECOMMENT : "//" (.*);
  81.  
  82. WS : (SPACES|TAB|EOL|JAVADOC|MULTILINECOMMENT|SINGLELINECOMMENT)*
  83.    ;
  84.  
  85. %start CompilationUnit;
  86.  
  87. TypeSpecifier
  88.   : TypeName Dims?
  89.   ;
  90.  
  91. TypeName
  92.   : PrimitiveType
  93.   | QualifiedName
  94.   ;
  95.  
  96. ClassNameList
  97.   : QualifiedName (WS "," WS QualifiedName)*
  98.   ;
  99.  
  100. PrimitiveType
  101.   : "boolean"
  102.   | "char"
  103.   | "byte"
  104.   | "short"
  105.   | "int"
  106.   | "long"
  107.   | "float"
  108.   | "double"
  109.   | "void"
  110.   ;
  111.  
  112. SemiColons
  113.   : ";"
  114.   | SemiColons ";"
  115.   ;
  116.  
  117. CompilationUnit
  118.   : ProgramFile
  119.   ;
  120.  
  121. ProgramFile
  122.   :  WS PackageStatement   (WS ImportStatements)? (WS TypeDeclarations)? WS
  123.   | (WS PackageStatement)?  WS ImportStatements   (WS TypeDeclarations)? WS
  124.   | (WS PackageStatement)? (WS ImportStatements)?  WS TypeDeclarations   WS
  125.   ;
  126.  
  127. PackageStatement
  128.   : "package" WS QualifiedName WS SemiColons
  129.   ;
  130.  
  131. TypeDeclarations
  132.   : TypeDeclarationOptSemi+
  133.   ;
  134.  
  135. TypeDeclarationOptSemi
  136.   : TypeDeclaration SemiColons?
  137.   ;
  138.  
  139. ImportStatements
  140.   : ImportStatement (WS ImportStatement)*
  141.   ;
  142.  
  143. ImportStatement
  144.   : "import" WS QualifiedName ("." "*")? WS SemiColons
  145.   ;
  146.  
  147. QualifiedName
  148.   : IDENTIFIER ("." IDENTIFIER)*
  149.   ;
  150.  
  151. TypeDeclaration
  152.   : ClassHeader WS "{" (WS FieldDeclarations)? WS "}"
  153.   ;
  154.  
  155. ClassHeader
  156.   : (Modifiers WS)? ClassWord WS IDENTIFIER (WS Extends)? (WS Interfaces)?
  157.   ;
  158.  
  159. Modifiers
  160.   : Modifier ( WS Modifier )*
  161.   ;
  162.  
  163. Modifier
  164.   : "abstract"
  165.   | "final"
  166.   | "public"
  167.   | "protected"
  168.   | "private"
  169.   | "static"
  170.   | "transient"
  171.   | "volatile"
  172.   | "native"
  173.   | "synchronized"
  174.   ;
  175.  
  176. ClassWord
  177.   : "class"
  178.   | "interface"
  179.   ;
  180.  
  181. Interfaces
  182.   : "implements" WS ClassNameList
  183.   ;
  184.  
  185. FieldDeclarations
  186.   : FieldDeclaration ((WS SemiColons)? WS FieldDeclaration)*
  187.   ;
  188.  
  189. FieldDeclaration
  190.   : FieldVariableDeclaration WS ";"
  191.   | MethodDeclaration
  192.   | ConstructorDeclaration
  193.   | StaticInitializer
  194.   | NonStaticInitializer
  195.   | TypeDeclaration
  196.   ;
  197.  
  198. FieldVariableDeclaration
  199.   : (Modifiers WS)? TypeSpecifier WS VariableDeclarators
  200.   ;
  201.  
  202. VariableDeclarators
  203.   : VariableDeclarator (WS "," WS VariableDeclarator)*
  204.   ;
  205.  
  206. VariableDeclarator
  207.   : DeclaratorName (WS "=" WS VariableInitializer)?
  208.   ;
  209.  
  210. VariableInitializer
  211.   : Expression
  212.   | "{" (WS ArrayInitializers)? WS "}"
  213.   ;
  214.  
  215. ArrayInitializers
  216.   : VariableInitializer (WS "," WS VariableInitializer)*
  217.   ;
  218.  
  219. MethodDeclaration
  220.   : (Modifiers WS)? TypeSpecifier WS MethodDeclarator (WS Throws)? WS MethodBody
  221.   ;
  222.  
  223. MethodDeclarator
  224.   : DeclaratorName WS "(" (WS ParameterList)? WS ")"
  225.   | MethodDeclarator OP_DIM
  226.   ;
  227.  
  228. ParameterList
  229.   : Parameter (WS "," WS Parameter)*
  230.   ;
  231.  
  232. Parameter
  233.   : "final"? TypeSpecifier WS DeclaratorName
  234.   ;
  235.  
  236. DeclaratorName
  237.   : IDENTIFIER
  238.   | DeclaratorName OP_DIM
  239.   ;
  240.  
  241. Throws
  242.   : "throws" WS ClassNameList
  243.   ;
  244.  
  245. MethodBody
  246.   : Block
  247.   | ";"
  248.   ;
  249.  
  250. ConstructorDeclaration
  251.   : Modifiers? ConstructorDeclarator Throws? Block
  252.   ;
  253.  
  254. ConstructorDeclarator
  255.   : IDENTIFIER "(" ParameterList? ")"
  256.   ;
  257.  
  258. StaticInitializer
  259.   : "static" Block
  260.   ;
  261.  
  262. NonStaticInitializer
  263.   : Block
  264.   ;
  265.  
  266. Extends
  267.   : "extends" TypeName ("," TypeName)*
  268.   ;
  269.  
  270. Block
  271.   : "{" (WS LocalVariableDeclarationsAndStatements)? WS "}"
  272.   ;
  273.  
  274. LocalVariableDeclarationsAndStatements
  275.   : LocalVariableDeclarationOrStatement (WS LocalVariableDeclarationOrStatement)*
  276.   ;
  277.  
  278. LocalVariableDeclarationOrStatement
  279.   : LocalVariableDeclarationStatement
  280.   | Statement
  281.   ;
  282.  
  283. LocalVariableDeclarationStatement
  284.   : ("final" WS)? TypeSpecifier WS VariableDeclarators ";"
  285.   ;
  286.  
  287. Statement
  288.   : EmptyStatement
  289.   | LabelStatement
  290.   | ExpressionStatement ";"
  291.   | SelectionStatement
  292.   | IterationStatement
  293.   | JumpStatement
  294.   | GuardingStatement
  295.   | Block
  296.   ;
  297.  
  298. EmptyStatement
  299.   : ";"
  300.   ;
  301.  
  302. LabelStatement
  303.   : IDENTIFIER ":"
  304.   | "case" ConstantExpression ":"
  305.   | "default" ":"
  306.   ;
  307.  
  308. ExpressionStatement
  309.   : Expression
  310.   ;
  311.  
  312. SelectionStatement
  313.   : "if" WS "(" WS Expression WS ")" WS Statement 
  314.   | "if" WS "(" WS Expression WS ")" WS Statement WS "else" WS Statement
  315.   | "switch" WS "(" WS Expression WS ")" WS Block
  316.   ;
  317.  
  318. IterationStatement
  319.   : "while" WS "(" WS Expression WS ")" WS Statement
  320.   | "do" WS Statement WS "while" WS "(" WS Expression WS ")" WS ";"
  321.   | "for" WS "(" WS ForInit WS ForExpr WS ForIncr WS ")" WS Statement
  322.   | "for" WS "(" WS ForInit WS ForExpr            WS ")" WS Statement
  323.   ;
  324.  
  325. ForInit
  326.   : ExpressionStatements WS ";"
  327.   | LocalVariableDeclarationStatement
  328.   | ";"
  329.   ;
  330.  
  331. ForExpr
  332.   : Expression WS ";"
  333.   | ";"
  334.   ;
  335.  
  336. ForIncr
  337.   : ExpressionStatements
  338.   ;
  339.  
  340. ExpressionStatements
  341.   : ExpressionStatement (WS "," WS ExpressionStatement)* 
  342.   ;
  343.  
  344. JumpStatement
  345.   : "break"    (WS IDENTIFIER)? WS ";"
  346.   | "continue" (WS IDENTIFIER)? WS ";"
  347.   | "return"   (WS Expression)? WS ";"
  348.   | "throw"     WS Expression   WS ";"
  349.   ;
  350.  
  351. GuardingStatement
  352.   : "synchronized" WS "(" WS Expression WS ")" WS Statement
  353.   | "try" WS Block             WS Finally
  354.   | "try" WS Block WS Catches (WS Finally)?
  355.   ;
  356.  
  357. Catches
  358.   : Catch (WS Catch)*
  359.   ;
  360.  
  361. Catch
  362.   : CatchHeader WS Block
  363.   ;
  364.  
  365. CatchHeader
  366.   : "catch" WS "(" WS TypeSpecifier (WS IDENTIFIER)? WS ")"
  367.   ;
  368.  
  369. Finally
  370.   : "finally" WS Block
  371.   ;
  372.  
  373. PrimaryExpression
  374.   : QualifiedName 
  375.   | NotJustName 
  376.   ;
  377.  
  378. NotJustName
  379.   : SpecialName 
  380.   | NewAllocationExpression 
  381.   | ComplexPrimary 
  382.   ;
  383.  
  384. ComplexPrimary
  385.   : "(" WS Expression WS ")"
  386.   | ComplexPrimaryNoParenthesis 
  387.   ;
  388.  
  389. ComplexPrimaryNoParenthesis
  390.   : LITERAL
  391.   | "true" | "false"
  392.   | ArrayAccess
  393.   | FieldAccess
  394.   | MethodCall
  395.   ;
  396.  
  397. ArrayAccess
  398.   : QualifiedName  WS "[" WS Expression WS "]"
  399.   | ComplexPrimary WS "[" WS Expression WS "]"
  400.   ;
  401.  
  402. FieldAccess
  403.   : NotJustName "." IDENTIFIER
  404.   | RealPostfixExpression "." IDENTIFIER
  405.   | QualifiedName "." "this"
  406.   | QualifiedName "." "class"
  407.   | PrimitiveType "." "class"
  408.   ;
  409.  
  410. MethodCall
  411.   : MethodAccess WS "(" (WS ArgumentList)? WS ")"
  412.   ;
  413.  
  414. MethodAccess
  415.   : ComplexPrimaryNoParenthesis
  416.   | SpecialName
  417.   | QualifiedName
  418.   ;
  419.  
  420. SpecialName
  421.   : "this"
  422.   | "super"
  423.   | "null"
  424.   ;
  425.  
  426. ArgumentList
  427.   : Expression (WS "," WS Expression)*
  428.   ;
  429.  
  430. NewAllocationExpression
  431.   : (QualifiedName ".")? PlainNewAllocationExpression
  432.   ;
  433.  
  434. PlainNewAllocationExpression
  435.    : ArrayAllocationExpression (WS "{" (WS ArrayInitializers)? WS "}")?
  436.    | ClassAllocationExpression (WS "{" (WS FieldDeclarations)? WS "}")?
  437.    ;
  438.  
  439. ClassAllocationExpression
  440.   : "new" WS TypeName WS "(" (WS ArgumentList)? WS ")"
  441.   ;
  442.  
  443. ArrayAllocationExpression
  444.   : "new" WS TypeName WS DimExprs (WS Dims)?
  445.   | "new" WS TypeName WS Dims
  446.   ;
  447.  
  448. DimExprs
  449.   : DimExpr+
  450.   ;
  451.  
  452. DimExpr
  453.   : "[" WS Expression WS "]"
  454.   ;
  455.  
  456. Dims
  457.   : OP_DIM+
  458.   ;
  459.  
  460. PostfixExpression
  461.   : PrimaryExpression 
  462.   | RealPostfixExpression 
  463.   ;
  464.  
  465. RealPostfixExpression
  466.   : PostfixExpression WS ("++"|"--")
  467.   ;
  468.  
  469. UnaryExpression
  470.   : ("++"|"--") UnaryExpression
  471.   | ("+"|"-")   CastExpression
  472.   | LogicalUnaryExpression 
  473.   ;
  474.  
  475. LogicalUnaryExpression
  476.   : PostfixExpression 
  477.   | ("~"|"!") UnaryExpression
  478.   ;
  479.  
  480. CastExpression
  481.   : UnaryExpression 
  482.   | "(" WS PrimitiveTypeExpression WS ")" WS CastExpression
  483.   | "(" WS ClassTypeExpression WS ")" WS CastExpression
  484.   | "(" WS Expression WS ")" WS LogicalUnaryExpression
  485.   ;
  486.  
  487. PrimitiveTypeExpression
  488.   : PrimitiveType Dims?
  489.   ;
  490.  
  491. ClassTypeExpression
  492.   : QualifiedName Dims
  493.   ;
  494.  
  495. MultiplicativeExpression
  496.   : CastExpression (WS ("*"|"/"|"%") WS CastExpression)*
  497.   ;
  498.  
  499. AdditiveExpression
  500.   : MultiplicativeExpression (WS ("+"|"-") WS MultiplicativeExpression)*
  501.   ;
  502.  
  503. ShiftExpression 
  504.   : AdditiveExpression (WS ("<<"|">>"|">>>") WS AdditiveExpression)*
  505.   ;
  506.  
  507. RelationalExpression
  508.   : ShiftExpression (WS ("<"|">"|"<="|">=") WS ShiftExpression)*
  509.   | RelationalExpression WS "instanceof" WS TypeSpecifier
  510.   ;
  511.  
  512. EqualityExpression
  513.   : RelationalExpression  (WS ("==" | "!=") WS RelationalExpression)*
  514.   ;
  515.  
  516. AndExpression
  517.   : EqualityExpression (WS "&" WS EqualityExpression)*
  518.   ;
  519.  
  520. ExclusiveOrExpression
  521.   : AndExpression (WS "^" WS AndExpression)*
  522.   ;
  523.  
  524. InclusiveOrExpression
  525.   : ExclusiveOrExpression (WS "|" WS ExclusiveOrExpression)*
  526.   ;
  527.  
  528. ConditionalAndExpression
  529.   : InclusiveOrExpression (WS "&&" WS InclusiveOrExpression)*
  530.   ;
  531.  
  532. ConditionalOrExpression
  533.   : ConditionalAndExpression (WS "||" WS ConditionalAndExpression)*
  534.   ;
  535.  
  536. ConditionalExpression
  537.   : ConditionalOrExpression 
  538.   | ConditionalOrExpression "?" Expression ":" ConditionalExpression
  539.   ;
  540.  
  541. AssignmentExpression
  542.   : ConditionalExpression 
  543.   | UnaryExpression WS AssignmentOperator WS AssignmentExpression
  544.   ;
  545.  
  546. AssignmentOperator
  547.   : "="
  548.   | "+=" | "-=" | "*=" | "/=" | "&=" | "|=" | "^=" | "%=" | "<<=" | ">>=" | ">>>="
  549.   ;
  550.  
  551. Expression
  552.   : AssignmentExpression
  553.   ;
  554.  
  555. ConstantExpression
  556.   : ConditionalExpression
  557.   ;
  558.  
  559.