Title: [1138] trunk/qdox/src/grammar/parser.y: Rearrange according to chapters (although, have to start with CompilationUnit otherwise the Parser won't work)
Revision
1138
Author
rfscholte
Date
2011-03-23 17:10:36 -0500 (Wed, 23 Mar 2011)

Log Message

Rearrange according to chapters (although, have to start with CompilationUnit otherwise the Parser won't work)

Modified Paths

Diff

Modified: trunk/qdox/src/grammar/parser.y (1137 => 1138)

--- trunk/qdox/src/grammar/parser.y	2011-03-23 20:11:58 UTC (rev 1137)
+++ trunk/qdox/src/grammar/parser.y	2011-03-23 22:10:36 UTC (rev 1138)
@@ -56,11 +56,11 @@
 %type <type> PrimitiveType NumericType IntegralType FloatingPointType
 %type <type> InterfaceType
 %type <type> Wildcard
-%type <annoval> _expression_ Literal Annotation ElementValue ElementValueArrayInitializer
+%type <annoval> _expression_ Literal Annotation ElementValue ElementValueArrayInitializer
 %type <annoval> ConditionalExpression ConditionalOrExpression ConditionalAndExpression InclusiveOrExpression ExclusiveOrExpression AndExpression
 %type <annoval> EqualityExpression RelationalExpression ShiftExpression AdditiveExpression MultiplicativeExpression
 %type <annoval> UnaryExpression UnaryExpressionNotPlusMinus primary
-%type <annoval> PostfixExpression CastExpression
+%type <annoval> PostfixExpression CastExpression AssignmentExpression
 %type <ival> dims Dims_opt
 %type <sval> AnyName typedeclspecifier memberend
 %type <type> Type ReferenceType VariableDeclaratorId classtype ActualTypeArgument
@@ -68,6 +68,8 @@
 %%
 // Source: Java Language Specification - Third Edition
 
+// 7 Packages
+
 // 7.3 Compilation Units
 CompilationUnit: PackageDeclaration_opt ImportDeclarations_opt TypeDeclarations_opt;
 
@@ -132,207 +134,10 @@
 /*               | InterfaceDeclaration */
                | SEMI;
 
+// 3 Lexical Structure
 
-//8.1 Class Declaration
-ClassDeclaration: NormalClassDeclaration	
-                | EnumDeclaration;
-                
-// ----- COMMON TOKENS
-
-// 6.5 Determining the Meaning of a Name
-// PackageName | TypeName | ExpressionName | MethodName | PackageOrTypeName | AmbiguousName 
-AnyName: IDENTIFIER { $$ = $1; } 
-       | AnyName DOT IDENTIFIER { $$ = $1 + '.' + $3; };
-
-// Modifiers to methods, fields, classes, interfaces, parameters, etc...
-AnyModifiers_opt:
-                | AnyModifiers_opt AnyModifier;
-
-AnyModifier: Annotation 
-           | PUBLIC          { modifiers.add("public"); }
-           | PROTECTED       { modifiers.add("protected"); } 
-           | PRIVATE         { modifiers.add("private"); }
-           | STATIC          { modifiers.add("static"); }
-           | FINAL           { modifiers.add("final"); }
-           | ABSTRACT        { modifiers.add("abstract"); }
-           | NATIVE          { modifiers.add("native"); }
-           | SYNCHRONIZED    { modifiers.add("synchronized"); }
-           | VOLATILE        { modifiers.add("volatile"); }
-           | TRANSIENT       { modifiers.add("transient"); }
-           | STRICTFP        { modifiers.add("strictfp"); } ;
-
-
-//--------------------------------------------------------------------------------
-// ANNOTATIONS
-//--------------------------------------------------------------------------------
-
-// 9.7 Annotations
-
-Annotations_opt: 
-               | Annotations_opt Annotation;
-
-Annotation /* = NormalAnnotation*/: AT AnyName /* =TypeName */ 
-                                    {
-                                      AnnoDef annotation = new AnnoDef();
-                                      annotation.typeDef = new TypeDef($2);
-                                      annotation.lineNumber = lexer.getLine();
-                                      annotationStack.addFirst(annotation);
-                                    }
-                                    annotationParensOpt
-                                    {
-                                      AnnoDef annotation = annotationStack.removeFirst();
-                                      if(annotationStack.isEmpty()) 
-                                      {
-                                        builder.addAnnotation(annotation);
-                                      }
-                                      $$ = annotation;
-                                    };
-    
-annotationParensOpt:
-	               | PARENOPEN ElementValue PARENCLOSE 
-	                 { 
-	                   annotationStack.getFirst().args.put("value", $2);
-                     }
-	               | PARENOPEN ElementValuePairs_opt PARENCLOSE;
-  
-ElementValuePairs_opt:
-                     | ElementValuePairs;   
-
-    
-ElementValuePairs: ElementValuePair 
-                 | ElementValuePairs COMMA ElementValuePair;
-    
-ElementValuePair: IDENTIFIER EQUALS ElementValue 
-                  {
-                    annotationStack.getFirst().args.put($1, $3);
-                  };
-
-/* Specs say: { ElementValues_opt COMMA_opt }
-   The optional COMMA causes trouble for the parser
-   For that reason the adjusted options of ElementValues_opt, which will accept all cases
-*/    
-ElementValueArrayInitializer: {
-                                annoValueListStack.add(annoValueList);
-                                annoValueList = new LinkedList();
-                              }
-                              BRACEOPEN ElementValues_opt BRACECLOSE
-                              { 
-                                $$ = new ElemValueListDef(annoValueList);
-                                annoValueList = annoValueListStack.remove(annoValueListStack.size() - 1);
-                              };
-    
-ElementValues_opt:
-                 | ElementValues_opt ElementValue
-                   { 
-                     annoValueList.add($2); 
-                   } 
-                 | ElementValues_opt COMMA;    
-    
-ElementValue: _expression_ 
-            | Annotation 
-            | ElementValueArrayInitializer ;
-
-_expression_:
-	ConditionalExpression ;
-
-//15.25 Conditional Operator ? :	
-ConditionalExpression: ConditionalOrExpression 
-                     | ConditionalOrExpression QUERY _expression_ COLON _expression_ { $$ = new AnnotationQuery($1, $3, $5); };
-
-//15.24 Conditional-Or Operator ||
-ConditionalOrExpression: ConditionalAndExpression 
-                       | ConditionalOrExpression VERTLINE2 ConditionalAndExpression { $$ = new AnnotationLogicalOr($1, $3); };
-
-// 15.23 Conditional-And Operator &&
-ConditionalAndExpression: InclusiveOrExpression 
-                        | ConditionalAndExpression AMPERSAND2 InclusiveOrExpression { $$ = new AnnotationLogicalAnd($1, $3); };
-
-//15.22 Bitwise and Logical Operators
-InclusiveOrExpression: ExclusiveOrExpression 
-                     | InclusiveOrExpression VERTLINE ExclusiveOrExpression { $$ = new AnnotationOr($1, $3); };
-
-ExclusiveOrExpression: AndExpression 
-                     | ExclusiveOrExpression CIRCUMFLEX AndExpression { $$ = new AnnotationExclusiveOr($1, $3); };
-
-AndExpression: EqualityExpression 
-             | AndExpression AMPERSAND EqualityExpression { $$ = new AnnotationAnd($1, $3); };
-
-// 15.21 Equality Operators
-EqualityExpression: RelationalExpression 
-                  | EqualityExpression EQUALS2 RelationalExpression   { $$ = new AnnotationEquals($1, $3); } 
-                  | EqualityExpression NOTEQUALS RelationalExpression { $$ = new AnnotationNotEquals($1, $3); };
-
-// 15.20 Relational Operators
-RelationalExpression: ShiftExpression 
-                    | RelationalExpression LESSEQUALS ShiftExpression    { $$ = new AnnotationLessEquals($1, $3); } 
-                    | RelationalExpression GREATEREQUALS ShiftExpression { $$ = new AnnotationGreaterEquals($1, $3); } 
-                    | RelationalExpression LESSTHAN ShiftExpression      { $$ = new AnnotationLessThan($1, $3); } 
-                    | RelationalExpression GREATERTHAN ShiftExpression   { $$ = new AnnotationGreaterThan($1, $3); };
-
-// 15.19 Shift Operators
-ShiftExpression: AdditiveExpression 
-               | ShiftExpression LESSTHAN2 AdditiveExpression    { $$ = new AnnotationShiftLeft($1, $3); }
-               | ShiftExpression GREATERTHAN3 AdditiveExpression { $$ = new AnnotationUnsignedShiftRight($1, $3); } 
-               | ShiftExpression GREATERTHAN2 AdditiveExpression { $$ = new AnnotationShiftRight($1, $3); };
-
-// 15.18 Additive Operators
-AdditiveExpression:	MultiplicativeExpression 
-                  |	AdditiveExpression PLUS MultiplicativeExpression  { $$ = new AnnotationAdd($1, $3); } 
-                  |	AdditiveExpression MINUS MultiplicativeExpression { $$ = new AnnotationSubtract($1, $3); };
-
-// 15.17 Multiplicative Operators
-MultiplicativeExpression: UnaryExpression 
-                        | MultiplicativeExpression STAR UnaryExpression    { $$ = new AnnotationMultiply($1, $3); } 
-                        | MultiplicativeExpression SLASH UnaryExpression   { $$ = new AnnotationDivide($1, $3); } 
-                        | MultiplicativeExpression PERCENT UnaryExpression { $$ = new AnnotationRemainder($1, $3); };
-
-// 15.15 Unary Operators
-UnaryExpression: /* PreIncrementExpression | PreDecrementExpression | */
-                 PLUS UnaryExpression  { $$ = new AnnotationPlusSign($2); } 
-               | MINUS UnaryExpression { $$ = new AnnotationMinusSign($2); }
-               | UnaryExpressionNotPlusMinus;
-
-UnaryExpressionNotPlusMinus: PostfixExpression 
-                           | TILDE UnaryExpression       { $$ = new AnnotationNot($2); } 
-                           | EXCLAMATION UnaryExpression { $$ = new AnnotationLogicalNot($2); } 
-                           | CastExpression;
-
-// 15.16 Cast Expressions	
-CastExpression: PARENOPEN PrimitiveType Dims_opt PARENCLOSE UnaryExpression { $$ = new AnnotationCast(new TypeDef($2.name, $3), $5); } 
-              | PARENOPEN AnyName PARENCLOSE UnaryExpressionNotPlusMinus       { $$ = new AnnotationCast(new TypeDef($2, 0), $4); }
-              | PARENOPEN AnyName dims PARENCLOSE UnaryExpressionNotPlusMinus  { $$ = new AnnotationCast(new TypeDef($2, $3), $5); };
-
-PostfixExpression: primary;
-
-//Primary: PrimaryNoNewArray
-//       | ArrayCreationExpression;
-       
-//PrimaryNoNewArray: Literal
-//                 | Type DOT CLASS
-//                 | VOID DOT CLASS
-//                 | THIS
-//        ClassName.this
-//        ( _expression_ )
-//        ClassInstanceCreationExpression
-//        FieldAccess
-//        MethodInvocation
-//        ArrayAccess
-       
-
-primary:
-    Literal |
-    PARENOPEN _expression_ PARENCLOSE { $$ = new AnnotationParenExpression($2); } |
-    PrimitiveType Dims_opt DOT CLASS { $$ = new AnnotationTypeRef(new TypeDef($1.name, $2)); } |
-    AnyName DOT CLASS { $$ = new AnnotationTypeRef(new TypeDef($1, 0)); } |
-    AnyName dims DOT CLASS { $$ = new AnnotationTypeRef(new TypeDef($1, $2)); } |
-    AnyName { $$ = new AnnotationFieldRef($1); };
-	
-Dims_opt:  { $$ = 0; }
-		| dims;	
-dims:
-    SQUAREOPEN SQUARECLOSE { $$ = 1; } |
-    dims SQUAREOPEN SQUARECLOSE { $$ = $1 + 1; };
-	
+// 3.10 Literals
+// NOTE: LONG_LITERAL and DOUBLE_LITERAL are not part of 
 Literal: INTEGER_LITERAL
          { 
            $$ = new AnnotationConstant(toInteger($1), $1); 
@@ -363,39 +168,141 @@
            String s = lexer.getCodeBody(); 
            $$ = new AnnotationConstant(toString(s), s); 
          };
-        
-PrimitiveType:
-	NumericType |
-    BOOLEAN { $$ = new TypeDef("boolean"); };
 
-NumericType:
-	IntegralType |
-	FloatingPointType;
-	
-IntegralType:
-    BYTE { $$ = new TypeDef("byte"); } |
-    SHORT { $$ = new TypeDef("short"); } |
-    INT { $$ = new TypeDef("int"); } |
-    LONG { $$ = new TypeDef("long"); } |
-    CHAR { $$ = new TypeDef("char"); };
+// 4 Types, Values, and Variables
 
-FloatingPointType:
-    FLOAT { $$ = new TypeDef("float"); } |
-    DOUBLE { $$ = new TypeDef("double"); };
-        
-
-// ----- TYPES
-
+// 4.1 The Kinds of Types and Values
 Type: PrimitiveType
     | ReferenceType;
+    
+// 4.2 Primitive Types and Values        
+PrimitiveType: NumericType
+             | BOOLEAN 
+               { 
+                 $$ = new TypeDef("boolean"); 
+               };
 
+NumericType: IntegralType
+           | FloatingPointType;
+	
+IntegralType: BYTE 
+              { 
+                $$ = new TypeDef("byte"); 
+              } 
+            | SHORT 
+              { 
+                $$ = new TypeDef("short"); 
+              } 
+            | INT 
+              { 
+                $$ = new TypeDef("int"); 
+              } 
+            | LONG 
+              { 
+                $$ = new TypeDef("long"); 
+              } 
+            | CHAR 
+              { 
+                $$ = new TypeDef("char");
+              };
+
+FloatingPointType: FLOAT 
+                   {
+                     $$ = new TypeDef("float");
+                   }
+                 | DOUBLE 
+                   { 
+                     $$ = new TypeDef("double");
+                   };
+                   
+// 4.3 Reference Types and Values
 ReferenceType: classtype Dims_opt 
                {
                  TypeDef td = $1;
     	         td.dimensions = $2;
                  $$ = td;
                };
+// 4.4 Type Variables
+TypeParameter: IDENTIFIER 
+               { 
+                 typeVariable = new TypeVariableDef($1);
+                 typeVariable.bounds = new LinkedList();
+               }
+               TypeBound_opt
+               {
+                 typeParams.add(typeVariable);
+                 typeVariable = null;
+               }
+               ;
 
+TypeBound_opt:
+             | TypeBound;
+
+TypeBound: EXTENDS ReferenceType /* =ClassOrInterfaceType */
+		   {
+		     typeVariable.bounds = new LinkedList();
+		     typeVariable.bounds.add($2); 
+		   }
+		   AdditionalBoundList_opt;
+		   
+AdditionalBoundList_opt:
+                       | AdditionalBoundList_opt AdditionalBound;		   
+
+AdditionalBound: AMPERSAND ReferenceType /* =InterfaceType */
+                 { 
+                   typeVariable.bounds.add($2); 
+                 };
+
+
+// 4.5.1 Type Arguments and Wildcards
+Wildcard: QUERY              
+          { 
+            $$ = new WildcardTypeDef(); 
+          } 
+        | QUERY EXTENDS ReferenceType 
+          { 
+            $$ = new WildcardTypeDef($3, "extends" ); 
+          }
+        | QUERY SUPER ReferenceType
+          { 
+            $$ = new WildcardTypeDef($3, "super" ); 
+          };
+
+// 6.5 Determining the Meaning of a Name
+// PackageName | TypeName | ExpressionName | MethodName | PackageOrTypeName | AmbiguousName 
+AnyName: IDENTIFIER { $$ = $1; } 
+       | AnyName DOT IDENTIFIER { $$ = $1 + '.' + $3; };
+
+
+// 15.8 Primary Expressions
+//Primary: PrimaryNoNewArray
+//       | ArrayCreationExpression;
+       
+//PrimaryNoNewArray: Literal
+//                 | Type DOT CLASS
+//                 | VOID DOT CLASS
+//                 | THIS
+//        ClassName.this
+//        ( _expression_ )
+//        ClassInstanceCreationExpression
+//        FieldAccess
+//        MethodInvocation
+//        ArrayAccess
+       
+primary:
+    Literal |
+    PARENOPEN _expression_ PARENCLOSE { $$ = new AnnotationParenExpression($2); } |
+    PrimitiveType Dims_opt DOT CLASS { $$ = new AnnotationTypeRef(new TypeDef($1.name, $2)); } |
+    AnyName DOT CLASS { $$ = new AnnotationTypeRef(new TypeDef($1, 0)); } |
+    AnyName dims DOT CLASS { $$ = new AnnotationTypeRef(new TypeDef($1, $2)); } |
+    AnyName { $$ = new AnnotationFieldRef($1); };
+	
+Dims_opt:  { $$ = 0; }
+		| dims;	
+dims:
+    SQUAREOPEN SQUARECLOSE { $$ = 1; } |
+    dims SQUAREOPEN SQUARECLOSE { $$ = $1 + 1; };
+
 classtype: typedeclspecifier LESSTHAN 
            {
     		 TypeDef td = new TypeDef($1,0);
@@ -431,114 +338,38 @@
 ActualTypeArgument: ReferenceType 
                   | Wildcard;
 
-// 4.5.1 Type Arguments and Wildcards
-Wildcard: QUERY              
-          { 
-            $$ = new WildcardTypeDef(); 
-          } 
-        | QUERY EXTENDS ReferenceType 
-          { 
-            $$ = new WildcardTypeDef($3, "extends" ); 
-          }
-        | QUERY SUPER ReferenceType
-          { 
-            $$ = new WildcardTypeDef($3, "super" ); 
-          };
 
-// 8.1.2 Generic Classes and Type Parameters
-TypeParameters_opt: 
-                  | TypeParameters;
 
-TypeParameters: LESSTHAN 
-                { 
-                  typeParams = new LinkedList(); 
-                } 
-                TypeParameterList GREATERTHAN;
+// 8 Classes
 
-TypeParameterList: TypeParameter 
-                 | TypeParameterList COMMA TypeParameter;
+// 8.1.1 ClassModifier: Annotation public protected private abstract static final strictfp 
+// 8.3.1 FieldModifier: Annotation public protected private static final transient volatile
+// 8.4.1 VariableModifier: final Annotation
+// 8.4.3 MethodModifier: Annotation public protected private abstract static final synchronized native strictfp
+// 8.8.3 ConstructorModifier: Annotation public protected private
 
-// 4.4 Type Variables
-TypeParameter: IDENTIFIER 
-               { 
-                 typeVariable = new TypeVariableDef($1);
-                 typeVariable.bounds = new LinkedList();
-               }
-               TypeBound_opt
-               {
-                 typeParams.add(typeVariable);
-                 typeVariable = null;
-               }
-               ;
+AnyModifiers_opt:
+                | AnyModifiers_opt AnyModifier;
 
-TypeBound_opt:
-             | TypeBound;
+AnyModifier: Annotation 
+           | PUBLIC          { modifiers.add("public"); }
+           | PROTECTED       { modifiers.add("protected"); } 
+           | PRIVATE         { modifiers.add("private"); }
+           | STATIC          { modifiers.add("static"); }
+           | FINAL           { modifiers.add("final"); }
+           | ABSTRACT        { modifiers.add("abstract"); }
+           | NATIVE          { modifiers.add("native"); }
+           | SYNCHRONIZED    { modifiers.add("synchronized"); }
+           | VOLATILE        { modifiers.add("volatile"); }
+           | TRANSIENT       { modifiers.add("transient"); }
+           | STRICTFP        { modifiers.add("strictfp"); } ;
 
-TypeBound: EXTENDS ReferenceType /* =ClassOrInterfaceType */
-		   {
-		     typeVariable.bounds = new LinkedList();
-		     typeVariable.bounds.add($2); 
-		   }
-		   AdditionalBoundList_opt;
-		   
-AdditionalBoundList_opt:
-                       | AdditionalBoundList_opt AdditionalBound;		   
-
-AdditionalBound: AMPERSAND ReferenceType /* =InterfaceType */
-                 { 
-                   typeVariable.bounds.add($2); 
-                 };
-
-// ----- ENUM
-
-// 8.9 Enums
-EnumDeclaration: AnyModifiers_opt /* =ClassModifiers_opt*/ ENUM IDENTIFIER Interfaces_opt 
-                 { 
-                   cls.lineNumber = line;
-                   cls.modifiers.addAll(modifiers);
-                   cls.name = $3;
-                   cls.type = ClassDef.ENUM;
-                   builder.beginClass(cls);
-                   cls = new ClassDef();
-                   fieldType = new TypeDef($3, 0);
-                 } 
-                 EnumBody;
-
-/* Specs say: { EnumConstants_opt ,_opt EnumBodyDeclarations_opt }
-   The optional COMMA causes trouble for the parser
-   For that reason the adjusted options of EnumConstants_opt, which will accept all cases 
-*/
-EnumBody: BRACEOPEN EnumConstants_opt EnumBodyDeclarations_opt BRACECLOSE 
-          { builder.endClass();
-            fieldType = null;
-            modifiers.clear();
-          };
-
-EnumConstants_opt:
-                 | EnumConstants_opt COMMA
-                 | EnumConstants_opt EnumConstant;
-                 
-EnumConstant: Annotations_opt IDENTIFIER Arguments_opt ClassBody_opt
-              { 
-                makeField(new TypeDef($2, 0), ""); 
-              };
-
-         
-Arguments_opt:
-             | PARENBLOCK /* =Arguments */;
-
-ClassBody_opt:
-             | CODEBLOCK /* =ClassBody */;
-
-EnumBodyDeclarations_opt:
-                        | SEMI ClassBodyDeclarations_opt;
-          
-// ----- CLASS
-
 // 8.1 Class Declaration
+ClassDeclaration: NormalClassDeclaration	
+                | EnumDeclaration;
 
 NormalClassDeclaration: 
-    AnyModifiers_opt classorinterface IDENTIFIER TypeParameters_opt opt_extends Interfaces_opt  {
+    AnyModifiers_opt /* =ClassModifiers_opt */ classorinterface /* =CLASS or =INTERFACE */ IDENTIFIER TypeParameters_opt opt_extends Interfaces_opt  {
         cls.lineNumber = line;
         cls.modifiers.addAll(modifiers); modifiers.clear(); 
         cls.name = $3;
@@ -551,6 +382,33 @@
       builder.endClass(); 
     };    
 
+// 8.1.1 Class Modifiers
+// See: AnyModifiers
+
+// 8.1.2 Generic Classes and Type Parameters
+TypeParameters_opt: 
+                  | TypeParameters;
+
+TypeParameters: LESSTHAN 
+                { 
+                  typeParams = new LinkedList(); 
+                } 
+                TypeParameterList GREATERTHAN;
+
+TypeParameterList: TypeParameter 
+                 | TypeParameterList COMMA TypeParameter;
+                 
+// 8.1.5 Superinterfaces
+Interfaces_opt:
+              | Interfaces;
+              
+Interfaces:	IMPLEMENTS InterfaceTypeList;
+
+InterfaceTypeList: InterfaceType { cls.implementz.add($1); }
+                 | InterfaceTypeList COMMA InterfaceType { cls.implementz.add($3); };
+
+InterfaceType: classtype;
+
 // 8.1.6 Class Body and Member Declarations
 ClassBody: BRACEOPEN ClassBodyDeclarations_opt BRACECLOSE; 
 
@@ -587,17 +445,6 @@
     classtype { cls.extendz.add($1); } |
     extendslist COMMA classtype { cls.extendz.add($3); };
 
-// 8.1.5 Superinterfaces
-Interfaces_opt:
-              | Interfaces;
-              
-Interfaces:	IMPLEMENTS InterfaceTypeList;
-
-InterfaceTypeList: InterfaceType { cls.implementz.add($1); }
-                 | InterfaceTypeList COMMA InterfaceType { cls.implementz.add($3); };
-
-InterfaceType: classtype;
-
 static_block:
     AnyModifiers_opt CODEBLOCK { lexer.getCodeBody(); modifiers.clear(); };
 
@@ -657,54 +504,6 @@
                 mth.dimensions = $6;
               };
 
-constructor:
-    AnyModifiers_opt IDENTIFIER {
-        builder.beginConstructor();
-        mth.lineNumber = lexer.getLine();
-        mth.modifiers.addAll(modifiers); modifiers.clear(); 
-        mth.constructor = true; mth.name = $2;
-    } methoddef Throws_opt memberend /* =MethodBody */ {
-        mth.body = $6;
-        builder.endConstructor(mth);
-        mth = new MethodDef(); 
-    } |
-    AnyModifiers_opt TypeParameters IDENTIFIER {
-        builder.beginConstructor();
-        mth.lineNumber = lexer.getLine();
-        mth.typeParams = typeParams;
-        mth.modifiers.addAll(modifiers); modifiers.clear(); 
-        mth.constructor = true; mth.name = $3;
-    } methoddef Throws_opt memberend /* =MethodBody */ {
-        mth.body = $7;
-        builder.endConstructor(mth);
-        mth = new MethodDef(); 
-    };
-
-// 8.4.7 Method Body
-
-memberend: CODEBLOCK 
-           {
-	         $$ = lexer.getCodeBody();
-           } 
-         | SEMI 
-           {
-             $$ = "";
-           };
-
-methoddef: PARENOPEN FormalParameterList_opt PARENCLOSE;
-
-// 8.4.6 Method Throws
-Throws_opt:
-          | THROWS ExceptionTypeList;
-
-ExceptionTypeList: classtype /*ExceptionType*/
-                   { 
-                     mth.exceptions.add($1); 
-                   }
-                 | ExceptionTypeList COMMA classtype /* =ExceptionType */
-                   {
-                     mth.exceptions.add($3);
-                   };
 // 8.4.1 Formal Parameters
 FormalParameterList_opt:
                        | FormalParameterList;
@@ -737,6 +536,284 @@
                        param = new FieldDef();
                      };
                    | FormalParameter;
+
+// 8.4.6 Method Throws
+Throws_opt:
+          | THROWS ExceptionTypeList;
+
+ExceptionTypeList: classtype /*ExceptionType*/
+                   { 
+                     mth.exceptions.add($1); 
+                   }
+                 | ExceptionTypeList COMMA classtype /* =ExceptionType */
+                   {
+                     mth.exceptions.add($3);
+                   };
+                   
+// 8.4.7 Method Body
+
+memberend: CODEBLOCK 
+           {
+	         $$ = lexer.getCodeBody();
+           } 
+         | SEMI 
+           {
+             $$ = "";
+           };
+
+methoddef: PARENOPEN FormalParameterList_opt PARENCLOSE;
+
+// 8.8 Constructor Declarations
+constructor: AnyModifiers_opt /* =ConstructorModifiers_opt */ IDENTIFIER 
+             {
+               builder.beginConstructor();
+               mth.lineNumber = lexer.getLine();
+               mth.modifiers.addAll(modifiers); modifiers.clear();
+               mth.constructor = true; mth.name = $2;
+             }
+             methoddef Throws_opt memberend /* =MethodBody */ 
+             {
+               mth.body = $6;
+               builder.endConstructor(mth);
+               mth = new MethodDef(); 
+             }
+           | AnyModifiers_opt /* =ConstructorModifiers_opt */ TypeParameters IDENTIFIER 
+             {
+               builder.beginConstructor();
+               mth.lineNumber = lexer.getLine();
+               mth.typeParams = typeParams;
+               mth.modifiers.addAll(modifiers); modifiers.clear();
+               mth.constructor = true; mth.name = $3;
+             } 
+             methoddef Throws_opt memberend /* =MethodBody */ 
+             {
+               mth.body = $7;
+               builder.endConstructor(mth);
+               mth = new MethodDef(); 
+             };
+             
+// 8.9 Enums
+EnumDeclaration: AnyModifiers_opt /* =ClassModifiers_opt*/ ENUM IDENTIFIER Interfaces_opt 
+                 { 
+                   cls.lineNumber = line;
+                   cls.modifiers.addAll(modifiers);
+                   cls.name = $3;
+                   cls.type = ClassDef.ENUM;
+                   builder.beginClass(cls);
+                   cls = new ClassDef();
+                   fieldType = new TypeDef($3, 0);
+                 } 
+                 EnumBody;
+
+/* Specs say: { EnumConstants_opt ,_opt EnumBodyDeclarations_opt }
+   The optional COMMA causes trouble for the parser
+   For that reason the adjusted options of EnumConstants_opt, which will accept all cases 
+*/
+EnumBody: BRACEOPEN EnumConstants_opt EnumBodyDeclarations_opt BRACECLOSE 
+          { builder.endClass();
+            fieldType = null;
+            modifiers.clear();
+          };
+
+EnumConstants_opt:
+                 | EnumConstants_opt COMMA
+                 | EnumConstants_opt EnumConstant;
+                 
+EnumConstant: Annotations_opt IDENTIFIER Arguments_opt ClassBody_opt
+              { 
+                makeField(new TypeDef($2, 0), ""); 
+              };
+
+         
+Arguments_opt:
+             | PARENBLOCK /* =Arguments */;
+
+ClassBody_opt:
+             | CODEBLOCK /* =ClassBody */;
+
+EnumBodyDeclarations_opt:
+                        | SEMI ClassBodyDeclarations_opt;      
+                        
+// 9.7 Annotations
+
+Annotations_opt: 
+               | Annotations_opt Annotation;
+
+Annotation /* = NormalAnnotation*/: AT AnyName /* =TypeName */ 
+                                    {
+                                      AnnoDef annotation = new AnnoDef();
+                                      annotation.typeDef = new TypeDef($2);
+                                      annotation.lineNumber = lexer.getLine();
+                                      annotationStack.addFirst(annotation);
+                                    }
+                                    annotationParensOpt
+                                    {
+                                      AnnoDef annotation = annotationStack.removeFirst();
+                                      if(annotationStack.isEmpty()) 
+                                      {
+                                        builder.addAnnotation(annotation);
+                                      }
+                                      $$ = annotation;
+                                    };
+    
+annotationParensOpt:
+	               | PARENOPEN ElementValue PARENCLOSE 
+	                 { 
+	                   annotationStack.getFirst().args.put("value", $2);
+                     }
+	               | PARENOPEN ElementValuePairs_opt PARENCLOSE;
+  
+ElementValuePairs_opt:
+                     | ElementValuePairs;   
+
+    
+ElementValuePairs: ElementValuePair 
+                 | ElementValuePairs COMMA ElementValuePair;
+    
+ElementValuePair: IDENTIFIER EQUALS ElementValue 
+                  {
+                    annotationStack.getFirst().args.put($1, $3);
+                  };
+
+/* Specs say: { ElementValues_opt COMMA_opt }
+   The optional COMMA causes trouble for the parser
+   For that reason the adjusted options of ElementValues_opt, which will accept all cases
+*/    
+ElementValueArrayInitializer: {
+                                annoValueListStack.add(annoValueList);
+                                annoValueList = new LinkedList();
+                              }
+                              BRACEOPEN ElementValues_opt BRACECLOSE
+                              { 
+                                $$ = new ElemValueListDef(annoValueList);
+                                annoValueList = annoValueListStack.remove(annoValueListStack.size() - 1);
+                              };
+    
+ElementValues_opt:
+                 | ElementValues_opt ElementValue
+                   { 
+                     annoValueList.add($2); 
+                   } 
+                 | ElementValues_opt COMMA;    
+    
+ElementValue: ConditionalExpression 
+            | Annotation 
+            | ElementValueArrayInitializer ;
+
+// 15.14 Postfix Expressions
+PostfixExpression: /* ExpressionName | PostIncrementExpression | PostDecrementExpression | */
+                   primary ;
+
+// 15.15 Unary Operators
+UnaryExpression: /* PreIncrementExpression | PreDecrementExpression | */
+                 PLUS UnaryExpression  { $$ = new AnnotationPlusSign($2); } 
+               | MINUS UnaryExpression { $$ = new AnnotationMinusSign($2); }
+               | UnaryExpressionNotPlusMinus;
+
+UnaryExpressionNotPlusMinus: PostfixExpression 
+                           | TILDE UnaryExpression       { $$ = new AnnotationNot($2); } 
+                           | EXCLAMATION UnaryExpression { $$ = new AnnotationLogicalNot($2); } 
+                           | CastExpression;
+
+// 15.16 Cast Expressions	
+CastExpression: PARENOPEN PrimitiveType Dims_opt PARENCLOSE UnaryExpression { $$ = new AnnotationCast(new TypeDef($2.name, $3), $5); } 
+              | PARENOPEN AnyName PARENCLOSE UnaryExpressionNotPlusMinus       { $$ = new AnnotationCast(new TypeDef($2, 0), $4); }
+              | PARENOPEN AnyName dims PARENCLOSE UnaryExpressionNotPlusMinus  { $$ = new AnnotationCast(new TypeDef($2, $3), $5); };
+
+// 15.17 Multiplicative Operators
+MultiplicativeExpression: UnaryExpression 
+                        | MultiplicativeExpression STAR UnaryExpression    { $$ = new AnnotationMultiply($1, $3); } 
+                        | MultiplicativeExpression SLASH UnaryExpression   { $$ = new AnnotationDivide($1, $3); } 
+                        | MultiplicativeExpression PERCENT UnaryExpression { $$ = new AnnotationRemainder($1, $3); };
+
+// 15.18 Additive Operators
+AdditiveExpression:	MultiplicativeExpression 
+                  |	AdditiveExpression PLUS MultiplicativeExpression  { $$ = new AnnotationAdd($1, $3); } 
+                  |	AdditiveExpression MINUS MultiplicativeExpression { $$ = new AnnotationSubtract($1, $3); };
+
+// 15.19 Shift Operators
+ShiftExpression: AdditiveExpression 
+               | ShiftExpression LESSTHAN2 AdditiveExpression    { $$ = new AnnotationShiftLeft($1, $3); }
+               | ShiftExpression GREATERTHAN3 AdditiveExpression { $$ = new AnnotationUnsignedShiftRight($1, $3); } 
+               | ShiftExpression GREATERTHAN2 AdditiveExpression { $$ = new AnnotationShiftRight($1, $3); };
+
+// 15.20 Relational Operators
+RelationalExpression: ShiftExpression 
+                    | RelationalExpression LESSEQUALS ShiftExpression    
+                      { 
+                        $$ = new AnnotationLessEquals($1, $3);
+                      } 
+                    | RelationalExpression GREATEREQUALS ShiftExpression 
+                      { 
+                        $$ = new AnnotationGreaterEquals($1, $3); 
+                      } 
+                    | RelationalExpression LESSTHAN ShiftExpression      
+                      { 
+                        $$ = new AnnotationLessThan($1, $3); 
+                      } 
+                    | RelationalExpression GREATERTHAN ShiftExpression   
+                      { 
+                        $$ = new AnnotationGreaterThan($1, $3); 
+                      };
+
+// 15.21 Equality Operators
+EqualityExpression: RelationalExpression 
+                  | EqualityExpression EQUALS2 RelationalExpression   
+                    { 
+                      $$ = new AnnotationEquals($1, $3);
+                    } 
+                  | EqualityExpression NOTEQUALS RelationalExpression 
+                    { 
+                      $$ = new AnnotationNotEquals($1, $3); 
+                    };
+
+// 15.22 Bitwise and Logical Operators
+InclusiveOrExpression: ExclusiveOrExpression 
+                     | InclusiveOrExpression VERTLINE ExclusiveOrExpression 
+                       { 
+                         $$ = new AnnotationOr($1, $3); 
+                       };
+
+ExclusiveOrExpression: AndExpression 
+                     | ExclusiveOrExpression CIRCUMFLEX AndExpression 
+                       { 
+                         $$ = new AnnotationExclusiveOr($1, $3);
+                       };
+
+AndExpression: EqualityExpression 
+             | AndExpression AMPERSAND EqualityExpression 
+               { 
+                 $$ = new AnnotationAnd($1, $3); 
+               };
+
+// 15.23 Conditional-And Operator &&
+ConditionalAndExpression: InclusiveOrExpression 
+                        | ConditionalAndExpression AMPERSAND2 InclusiveOrExpression 
+                          { 
+                            $$ = new AnnotationLogicalAnd($1, $3); 
+                          };
+
+// 15.24 Conditional-Or Operator ||
+ConditionalOrExpression: ConditionalAndExpression 
+                       | ConditionalOrExpression VERTLINE2 ConditionalAndExpression 
+                         { 
+                           $$ = new AnnotationLogicalOr($1, $3);
+                         };
+
+// 15.25 Conditional Operator ? :	
+ConditionalExpression: ConditionalOrExpression 
+                     | ConditionalOrExpression QUERY _expression_ COLON ConditionalExpression 
+                       { 
+                         $$ = new AnnotationQuery($1, $3, $5);
+                       };
+                       
+// 15.26 Assignment Operators
+AssignmentExpression: ConditionalExpression;
+                    /* | Assignment */ 
+
+// 15.27 _expression_
+_expression_: AssignmentExpression;
+
 %%
 
 private JavaLexer lexer;


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to