You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vs...@apache.org on 2006/09/15 15:05:58 UTC

svn commit: r446601 [2/3] - in /maven/plugins/trunk/maven-antlr-plugin: ./ src/main/java/org/apache/maven/plugin/antlr/ src/main/mdo/ src/site/ src/site/apt/ src/site/apt/examples/ src/site/fml/ src/test/java/org/apache/maven/plugin/antlr/ src/test/res...

Added: maven/plugins/trunk/maven-antlr-plugin/src/test/resources/unit/java-grammar-inheritance-test/src/main/antlr/GnuCParser.g
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antlr-plugin/src/test/resources/unit/java-grammar-inheritance-test/src/main/antlr/GnuCParser.g?view=auto&rev=446601
==============================================================================
--- maven/plugins/trunk/maven-antlr-plugin/src/test/resources/unit/java-grammar-inheritance-test/src/main/antlr/GnuCParser.g (added)
+++ maven/plugins/trunk/maven-antlr-plugin/src/test/resources/unit/java-grammar-inheritance-test/src/main/antlr/GnuCParser.g Fri Sep 15 06:05:57 2006
@@ -0,0 +1,850 @@
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+        Copyright (c) Non, Inc. 1998 -- All Rights Reserved
+
+PROJECT:        C Compiler
+MODULE:         GnuCParser
+FILE:           GnuCParser.g
+
+AUTHOR:         Monty Zukowski (jamz@cdsnet.net) April 28, 1998
+
+DESCRIPTION:
+                This is a grammar for the GNU C compiler.  It is a
+                grammar subclass of StdCParser, overriding only those
+                rules which are different from Standard C.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+    
+{
+import java.io.*;
+
+import antlr.CommonAST;
+import antlr.DumpASTVisitor;
+}
+
+           
+class GnuCParser extends StdCParser;
+
+options
+        {
+        k = 2;
+        exportVocab = GNUC;
+        buildAST = true;
+        ASTLabelType = "TNode";
+
+        // Copied following options from java grammar.
+        codeGenMakeSwitchThreshold = 2;
+        codeGenBitsetTestThreshold = 3;
+        }
+
+
+{
+    // Suppport C++-style single-line comments?
+    public static boolean CPPComments = true;
+
+    // access to symbol table
+    public CSymbolTable symbolTable = new CSymbolTable();
+
+    // source for names to unnamed scopes
+    protected int unnamedScopeCounter = 0;
+
+    public boolean isTypedefName(String name) {
+      boolean returnValue = false;
+      TNode node = symbolTable.lookupNameInCurrentScope(name);
+      for (; node != null; node = (TNode) node.getNextSibling() ) {
+        if(node.getType() == LITERAL_typedef) {
+            returnValue = true;
+            break;
+        }
+      }
+      return returnValue;
+    }
+
+
+    public String getAScopeName() {
+      return "" + (unnamedScopeCounter++);
+    }
+
+    public void pushScope(String scopeName) {
+      symbolTable.pushScope(scopeName);
+    }
+
+    public void popScope() {
+      symbolTable.popScope();
+    }
+
+        int traceDepth = 0;
+        public void reportError(RecognitionException ex) {
+          try {
+            System.err.println("ANTLR Parsing Error: "+ex + " token name:" + tokenNames[LA(1)]);
+            ex.printStackTrace(System.err);
+          }
+	  catch (TokenStreamException e) {
+            System.err.println("ANTLR Parsing Error: "+ex);
+            ex.printStackTrace(System.err);              
+          }
+        }
+        public void reportError(String s) {
+            System.err.println("ANTLR Parsing Error from String: " + s);
+        }
+        public void reportWarning(String s) {
+            System.err.println("ANTLR Parsing Warning from String: " + s);
+        }
+        public void match(int t) throws MismatchedTokenException {
+          boolean debugging = false;
+          
+          if ( debugging ) {
+           for (int x=0; x<traceDepth; x++) System.out.print(" ");
+           try {
+            System.out.println("Match("+tokenNames[t]+") with LA(1)="+
+                tokenNames[LA(1)] + ((inputState.guessing>0)?" [inputState.guessing "+ inputState.guessing + "]":""));
+           }
+           catch (TokenStreamException e) {
+            System.out.println("Match("+tokenNames[t]+") " + ((inputState.guessing>0)?" [inputState.guessing "+ inputState.guessing + "]":""));
+
+           }
+    
+          }
+          try {
+            if ( LA(1)!=t ) {
+                if ( debugging ){
+                    for (int x=0; x<traceDepth; x++) System.out.print(" ");
+                    System.out.println("token mismatch: "+tokenNames[LA(1)]
+                                + "!="+tokenNames[t]);
+                }
+	        throw new MismatchedTokenException(tokenNames, LT(1), t, false, getFilename());
+
+            } else {
+                // mark token as consumed -- fetch next token deferred until LA/LT
+                consume();
+            }
+          }
+          catch (TokenStreamException e) {
+          }
+    
+        }
+        public void traceIn(String rname) {
+          traceDepth += 1;
+          for (int x=0; x<traceDepth; x++) System.out.print(" ");
+          try {
+            System.out.println("> "+rname+"; LA(1)==("+ tokenNames[LT(1).getType()] 
+                + ") " + LT(1).getText() + " [inputState.guessing "+ inputState.guessing + "]");
+          }
+          catch (TokenStreamException e) {
+          }
+        }
+        public void traceOut(String rname) {
+          for (int x=0; x<traceDepth; x++) System.out.print(" ");
+          try {
+            System.out.println("< "+rname+"; LA(1)==("+ tokenNames[LT(1).getType()] 
+                + ") "+LT(1).getText() + " [inputState.guessing "+ inputState.guessing + "]");
+          }
+          catch (TokenStreamException e) {
+          }
+          traceDepth -= 1;
+        }
+    
+}
+
+
+translationUnit
+        :       ( externalList )?       /* Empty source files are allowed.  */
+        ;
+asm_expr
+        :       "asm"^ 
+                ("volatile")? LCURLY expr RCURLY ( SEMI )+
+        ;
+
+idList
+        :       ID ( options{warnWhenFollowAmbig=false;}: COMMA ID )*
+        ;
+
+externalDef
+        :       ( "typedef" | declaration )=> declaration
+        |       ( functionPrefix )=> functionDef
+        |       typelessDeclaration
+        |       asm_expr
+        |       SEMI
+        ;
+
+/* these two are here because GCC allows "cat = 13;" as a valid program! */
+functionPrefix
+                            { String declName; }
+        :       ( (functionDeclSpecifiers)=> ds:functionDeclSpecifiers
+                |  //epsilon
+                )
+                declName = d:declarator[true]
+                ( declaration )* (VARARGS)? ( SEMI )*
+                LCURLY
+        ;
+
+typelessDeclaration
+                        { AST typeMissing = #[NTypeMissing]; }
+        :       initDeclList[typeMissing] SEMI          { ## = #( #[NTypeMissing], ##); }
+        ;
+
+initializer
+        : ( ( ( (initializerElementLabel)=> initializerElementLabel )?
+                ( assignExpr | lcurlyInitializer )  { ## = #( #[NInitializer], ## ); }
+              )
+              | lcurlyInitializer
+              )
+        ;
+
+// GCC allows more specific initializers
+initializerElementLabel
+        :   (   ( LBRACKET ((constExpr VARARGS)=> rangeExpr | constExpr) RBRACKET (ASSIGN)? )
+                | ID COLON
+                | DOT ID ASSIGN
+            )
+                                    { ## = #( #[NInitializerElementLabel], ##) ; }
+        ;
+
+// GCC allows empty initializer lists
+lcurlyInitializer 
+        :    
+                LCURLY^ (initializerList ( COMMA! )? )? RCURLY
+                            { ##.setType( NLcurlyInitializer ); }
+        ;
+    
+initializerList
+        :       initializer ( options{warnWhenFollowAmbig=false;}:COMMA! initializer )*
+        ;
+    
+
+declarator[boolean isFunctionDefinition] returns [String declName]
+                                                { declName = ""; }
+        :
+                ( pointerGroup )?               
+
+                ( id:ID                         { declName = id.getText(); }
+                | LPAREN declName = declarator[false] RPAREN
+                )
+
+                ( declaratorParamaterList[isFunctionDefinition, declName]
+                | LBRACKET ( expr )? RBRACKET
+                )*
+                                                { ## = #( #[NDeclarator], ## ); }
+        ;
+
+declaratorParamaterList[boolean isFunctionDefinition, String declName]
+        :
+                LPAREN^
+                                                { 
+                                                    if (isFunctionDefinition) {
+                                                        pushScope(declName);
+                                                    }
+                                                    else {
+                                                        pushScope("!"+declName); 
+                                                    }
+                                                }
+                (                           
+                        (declSpecifiers)=> parameterTypeList
+                        | (idList)?
+                )
+                                                {
+                                                popScope();
+                                                }    
+                ( COMMA! )?
+                RPAREN       
+                                                { ##.setType(NParameterTypeList); }      
+        ;
+           
+parameterTypeList
+        :       parameterDeclaration
+                (   options {
+                            warnWhenFollowAmbig = false;
+                        } : 
+                  ( COMMA | SEMI )  
+                  parameterDeclaration
+                )*
+                ( ( COMMA | SEMI ) 
+                  VARARGS
+                )?
+        ;
+
+
+declarationList
+         :       (               options {   // this loop properly aborts when
+                                            // it finds a non-typedefName ID MBZ
+                                            warnWhenFollowAmbig = false;
+                                        } :
+    
+                localLabelDeclaration
+                |  ( declarationPredictor )=> declaration
+                )+
+        ;
+localLabelDeclaration    
+        :       ( //GNU note:  any __label__ declarations must come before regular declarations.
+                "__label__"^ ID (options{warnWhenFollowAmbig=false;}: COMMA! ID)* ( COMMA! )? ( SEMI! )+
+                )
+        ;
+
+    
+declaration
+                                        { AST ds1 = null; }
+        :       ds:declSpecifiers       { ds1 = astFactory.dupList(#ds); }
+                (                       
+                    initDeclList[ds1]
+                )?
+                ( SEMI )+
+                                        { ## = #( #[NDeclaration], ##); }
+                
+        ;
+
+functionStorageClassSpecifier
+        :       "extern"
+        |       "static"
+        |       "inline"
+        ;
+
+typeSpecifier [int specCount] returns [int retSpecCount]
+                                                        { retSpecCount = specCount + 1; }
+        :       
+        ( "void"
+        |       "char"
+        |       "short"
+        |       "int"
+        |       "long"
+        |       "float"
+        |       "double"
+        |       "signed"
+        |       "unsigned"
+        |       structOrUnionSpecifier  ( options{warnWhenFollowAmbig=false;}: attributeDecl )*
+        |       enumSpecifier
+        |       { specCount==0 }? typedefName
+        |       "typeof"^ LPAREN
+                ( ( typeName )=> typeName
+                | expr
+                )
+                RPAREN
+        |       "__complex"
+        )
+        ;
+    
+
+structOrUnionSpecifier
+                                        { String scopeName; }
+        :       sou:structOrUnion!
+                ( ( ID LCURLY )=> i:ID l:LCURLY
+                                            {
+                                            scopeName = #sou.getText() + " " + #i.getText();
+                                            #l.setText(scopeName);
+                                            pushScope(scopeName);
+                                            }
+                        ( structDeclarationList )?
+                                            { popScope();}
+                        RCURLY
+                |   l1:LCURLY
+                                            {
+                                            scopeName = getAScopeName();
+                                            #l1.setText(scopeName);
+                                            pushScope(scopeName);
+                                            }
+                    ( structDeclarationList )?
+                                            { popScope(); }
+                    RCURLY
+                | ID
+                )
+                                            {
+                                            ## = #( #sou, ## );
+                                            }
+        ;
+
+
+structDeclaration
+        :       specifierQualifierList structDeclaratorList ( COMMA! )? ( SEMI! )+
+        ;
+
+structDeclaratorList
+        :       structDeclarator ( options{warnWhenFollowAmbig=false;}: COMMA! structDeclarator )*
+        ;
+
+structDeclarator
+        :       ( declarator[false] )?
+                ( COLON constExpr )?
+                ( attributeDecl )*
+                                    { ## = #( #[NStructDeclarator], ##); }
+        ;
+
+
+
+enumSpecifier
+        :       "enum"^
+                ( ( ID LCURLY )=> i:ID LCURLY enumList[i.getText()] RCURLY
+                | LCURLY enumList["anonymous"] RCURLY
+                | ID
+                )
+        ;
+enumList[String enumName]
+        :       enumerator[enumName] ( options{warnWhenFollowAmbig=false;}: COMMA! enumerator[enumName] )* ( COMMA! )?
+        ;
+
+
+initDeclList[AST declarationSpecifiers]
+        :       initDecl[declarationSpecifiers] 
+                ( options{warnWhenFollowAmbig=false;}: COMMA! initDecl[declarationSpecifiers] )*
+                ( COMMA! )?
+        ;
+
+initDecl[AST declarationSpecifiers]
+                                        { String declName = ""; }
+        :       declName = d:declarator[false]
+                                        {   AST ds1, d1;
+                                            ds1 = astFactory.dupList(declarationSpecifiers);
+                                            d1 = astFactory.dupList(#d);
+                                            symbolTable.add(declName, #(null, ds1, d1) );
+                                        }
+                ( attributeDecl )*
+                ( ASSIGN initializer
+                | COLON expr
+                )?
+                                        { ## = #( #[NInitDecl], ## ); }
+        ;
+
+attributeDecl
+        :       "__attribute"^ LPAREN LPAREN attributeList RPAREN RPAREN
+                | "asm"^ LPAREN stringConst RPAREN { ##.setType( NAsmAttribute ); }
+        ;
+
+attributeList
+        :       attribute ( options{warnWhenFollowAmbig=false;}: COMMA attribute)*  ( COMMA )?
+        ;
+
+attribute
+        :       ( ~(LPAREN | RPAREN | COMMA)
+                |  LPAREN attributeList RPAREN
+                )*
+        ;
+compoundStatement[String scopeName]
+        :       LCURLY^
+
+                            {
+                                pushScope(scopeName);
+                            }
+                (       //this ambiguity is ok, declarationList and nestedFunctionDef end properly
+                        options {
+                            warnWhenFollowAmbig = false;
+                        } :
+                    ( "typedef" | "__label__" | declaration )=> declarationList
+                    | (nestedFunctionDef)=> nestedFunctionDef
+                )*
+                ( statementList )?
+                            { popScope(); }
+                RCURLY
+                            { ##.setType( NCompoundStatement ); ##.setAttribute( "scopeName", scopeName ); }
+        ;
+
+nestedFunctionDef
+                            { String declName; }
+        :       ( "auto" )? //only for nested functions
+                ( (functionDeclSpecifiers)=> ds:functionDeclSpecifiers
+                )?
+                declName = d:declarator[false]
+                            {
+                            AST d2, ds2;
+                            d2 = astFactory.dupList(#d);
+                            ds2 = astFactory.dupList(#ds);
+                            symbolTable.add(declName, #(null, ds2, d2));
+                            pushScope(declName);
+                            }
+                ( declaration )*
+                            { popScope(); }
+                compoundStatement[declName]
+                            { ## = #( #[NFunctionDef], ## );}
+        ;
+
+statement
+        :       SEMI                    // Empty statements
+        
+        |       compoundStatement[getAScopeName()]       // Group of statements
+
+        |       expr SEMI!               { ## = #( #[NStatementExpr], ## );} // Expressions
+
+// Iteration statements:
+
+        |       "while"^ LPAREN! expr RPAREN! statement
+        |       "do"^ statement "while"! LPAREN! expr RPAREN! SEMI!
+        |!       "for"
+                LPAREN ( e1:expr )? SEMI ( e2:expr )? SEMI ( e3:expr )? RPAREN
+                s:statement
+                                    {
+                                        if ( #e1 == null) { #e1 = #[ NEmptyExpression ]; }
+                                        if ( #e2 == null) { #e2 = #[ NEmptyExpression ]; }
+                                        if ( #e3 == null) { #e3 = #[ NEmptyExpression ]; }
+                                        ## = #( #[LITERAL_for, "for"], #e1, #e2, #e3, #s );
+                                    }
+
+
+// Jump statements:
+
+        |       "goto"^ expr SEMI!
+        |       "continue" SEMI!
+        |       "break" SEMI!
+        |       "return"^ ( expr )? SEMI!
+
+
+        |       ID COLON! (options {warnWhenFollowAmbig=false;}: statement)?  { ## = #( #[NLabel], ## ); }
+// GNU allows range expressions in case statements
+        |       "case"^ ((constExpr VARARGS)=> rangeExpr | constExpr) COLON! ( options{warnWhenFollowAmbig=false;}:statement )?
+        |       "default"^ COLON! ( options{warnWhenFollowAmbig=false;}: statement )?
+
+// Selection statements:
+
+        |       "if"^
+                 LPAREN! expr RPAREN! statement  
+                ( //standard if-else ambiguity
+                        options {
+                            warnWhenFollowAmbig = false;
+                        } :
+                "else" statement )?
+        |       "switch"^ LPAREN! expr RPAREN! statement
+        ;
+
+
+
+conditionalExpr
+        :       logicalOrExpr
+                ( QUESTION^ (expr)? COLON conditionalExpr )?
+        ;
+
+rangeExpr   //used in initializers only
+        :  constExpr VARARGS constExpr
+                                { ## = #(#[NRangeExpr], ##); }
+        ;
+
+castExpr
+        :       ( LPAREN typeName RPAREN )=>
+                LPAREN^ typeName RPAREN ( castExpr | lcurlyInitializer )
+                            { ##.setType(NCast); }
+
+        |       unaryExpr
+        ;
+nonemptyAbstractDeclarator
+        :   (
+                pointerGroup
+                (   (LPAREN  
+                    (   nonemptyAbstractDeclarator
+                        | parameterTypeList
+                    )?
+                    ( COMMA! )?
+                    RPAREN)
+                | (LBRACKET (expr)? RBRACKET)
+                )*
+
+            |   (   (LPAREN  
+                    (   nonemptyAbstractDeclarator
+                        | parameterTypeList
+                    )?
+                    ( COMMA! )?
+                    RPAREN)
+                | (LBRACKET (expr)? RBRACKET)
+                )+
+            )
+                            {   ## = #( #[NNonemptyAbstractDeclarator], ## ); }
+                                
+        ;
+
+
+
+unaryExpr
+        :       postfixExpr
+        |       INC^ castExpr
+        |       DEC^ castExpr
+        |       u:unaryOperator castExpr { ## = #( #[NUnaryExpr], ## ); }
+
+        |       "sizeof"^
+                ( ( LPAREN typeName )=> LPAREN typeName RPAREN
+                | unaryExpr
+                )
+        |       "__alignof"^
+                ( ( LPAREN typeName )=> LPAREN typeName RPAREN
+                | unaryExpr
+                )       
+        |       gnuAsmExpr
+        ;
+
+unaryOperator
+        :       BAND
+        |       STAR
+        |       PLUS
+        |       MINUS
+        |       BNOT    //also stands for complex conjugation
+        |       LNOT
+        |       LAND    //for label dereference (&&label)
+        |       "__real"
+        |       "__imag"
+        ;
+
+gnuAsmExpr
+        :       "asm"^ ("volatile")? 
+                LPAREN stringConst
+                ( options { warnWhenFollowAmbig = false; }:
+                  COLON (strOptExprPair ( COMMA strOptExprPair)* )?
+                  ( options { warnWhenFollowAmbig = false; }:
+                    COLON (strOptExprPair ( COMMA strOptExprPair)* )?
+                  )?
+                )?
+                ( COLON stringConst ( COMMA stringConst)* )?
+                RPAREN
+                                { ##.setType(NGnuAsmExpr); }
+        ;
+
+//GCC requires the PARENs
+strOptExprPair
+        :  stringConst ( LPAREN expr RPAREN )?
+        ;
+
+
+primaryExpr
+        :       ID
+        |       Number
+        |       charConst
+        |       stringConst
+// JTC:
+// ID should catch the enumerator
+// leaving it in gives ambiguous err
+//      | enumerator
+        |       (LPAREN LCURLY) => LPAREN^ compoundStatement[getAScopeName()] RPAREN
+        |       LPAREN^ expr RPAREN        { ##.setType(NExpressionGroup); }
+        ;
+    
+
+{
+        import CToken;
+        import java.io.*;
+        import LineObject;
+        import antlr.*;
+}
+
+class GnuCLexer extends StdCLexer;
+options 
+        {
+        k = 3;
+        importVocab = GNUC;
+        testLiterals = false;
+        }    
+tokens {
+        LITERAL___extension__ = "__extension__";
+}
+
+{
+  public void initialize(String src)
+  {
+    setOriginalSource(src);
+    initialize();
+  }
+
+  public void initialize() 
+  {
+    literals.put(new ANTLRHashString("__alignof__", this), new Integer(LITERAL___alignof));
+    literals.put(new ANTLRHashString("__asm", this), new Integer(LITERAL_asm));
+    literals.put(new ANTLRHashString("__asm__", this), new Integer(LITERAL_asm));
+    literals.put(new ANTLRHashString("__attribute__", this), new Integer(LITERAL___attribute));
+    literals.put(new ANTLRHashString("__complex__", this), new Integer(LITERAL___complex));
+    literals.put(new ANTLRHashString("__const", this), new Integer(LITERAL_const));
+    literals.put(new ANTLRHashString("__const__", this), new Integer(LITERAL_const));
+    literals.put(new ANTLRHashString("__imag__", this), new Integer(LITERAL___imag));
+    literals.put(new ANTLRHashString("__inline", this), new Integer(LITERAL_inline));
+    literals.put(new ANTLRHashString("__inline__", this), new Integer(LITERAL_inline));
+    literals.put(new ANTLRHashString("__real__", this), new Integer(LITERAL___real));
+    literals.put(new ANTLRHashString("__signed", this), new Integer(LITERAL_signed));
+    literals.put(new ANTLRHashString("__signed__", this), new Integer(LITERAL_signed));
+    literals.put(new ANTLRHashString("__typeof", this), new Integer(LITERAL_typeof));
+    literals.put(new ANTLRHashString("__typeof__", this), new Integer(LITERAL_typeof));
+    literals.put(new ANTLRHashString("__volatile", this), new Integer(LITERAL_volatile));
+    literals.put(new ANTLRHashString("__volatile__", this), new Integer(LITERAL_volatile));
+  }
+
+
+  LineObject lineObject = new LineObject();
+  String originalSource = "";
+  PreprocessorInfoChannel preprocessorInfoChannel = new PreprocessorInfoChannel();
+  int tokenNumber = 0;
+  boolean countingTokens = true;
+  int deferredLineCount = 0;
+
+  public void setCountingTokens(boolean ct) 
+  {
+    countingTokens = ct;
+    if ( countingTokens ) {
+      tokenNumber = 0;
+    }
+    else {
+      tokenNumber = 1;
+    }
+  }
+
+  public void setOriginalSource(String src) 
+  {
+    originalSource = src;
+    lineObject.setSource(src);
+  }
+  public void setSource(String src) 
+  {
+    lineObject.setSource(src);
+  }
+  
+  public PreprocessorInfoChannel getPreprocessorInfoChannel() 
+  {
+    return preprocessorInfoChannel;
+  }
+
+  public void setPreprocessingDirective(String pre)
+  {
+    preprocessorInfoChannel.addLineForTokenNumber( pre, new Integer(tokenNumber) );
+  }
+  
+  protected Token makeToken(int t)
+  {
+    if ( t != Token.SKIP && countingTokens) {
+        tokenNumber++;
+    }
+    CToken tok = (CToken) super.makeToken(t);
+    tok.setLine(lineObject.line);
+    tok.setSource(lineObject.source);
+    tok.setTokenNumber(tokenNumber);
+
+    lineObject.line += deferredLineCount;
+    deferredLineCount = 0;
+    return tok;
+  }
+
+    public void deferredNewline() { 
+        deferredLineCount++;
+    }
+
+    public void newline() { 
+        lineObject.newline();
+    }
+
+
+
+
+
+
+}
+Whitespace
+        :       ( ( ' ' | '\t' | '\014')
+                | "\r\n"                { newline(); }
+                | ( '\n' | '\r' )       { newline();    }
+                )                       { _ttype = Token.SKIP;  }
+        ;
+
+
+protected
+Escape
+        :       '\\'
+                ( options{warnWhenFollowAmbig=false;}: 
+                  ~('0'..'7' | 'x')
+                | ('0'..'3') ( options{warnWhenFollowAmbig=false;}: Digit )*
+                | ('4'..'7') ( options{warnWhenFollowAmbig=false;}: Digit )*
+                | 'x' ( options{warnWhenFollowAmbig=false;}: Digit | 'a'..'f' | 'A'..'F' )+
+                )
+        ;
+
+protected IntSuffix
+        :   'L'
+            | 'l'
+            | 'U'
+            | 'u'
+            | 'I'
+            | 'i'
+            | 'J'
+            | 'j'
+        ;
+protected NumberSuffix
+        :
+            IntSuffix
+            | 'F'
+            | 'f'
+        ;
+    
+Number
+        :       ( ( Digit )+ ( '.' | 'e' | 'E' ) )=> ( Digit )+
+                ( '.' ( Digit )* ( Exponent )?
+                | Exponent
+                ) 
+                ( NumberSuffix
+                )*
+
+        |       ( "..." )=> "..."       { _ttype = VARARGS;     }
+
+        |       '.'                     { _ttype = DOT; }
+                ( ( Digit )+ ( Exponent )?
+                                        { _ttype = Number;   }
+                    ( NumberSuffix
+                    )*
+                )?
+
+        |       '0' ( '0'..'7' )*       
+                ( NumberSuffix
+                )*
+
+        |       '1'..'9' ( Digit )*     
+                ( NumberSuffix
+                )*
+
+        |       '0' ( 'x' | 'X' ) ( 'a'..'f' | 'A'..'F' | Digit )+
+                ( IntSuffix
+                )*
+        ;
+
+IDMEAT
+        :
+                i:ID                {
+                                        
+                                        if ( i.getType() == LITERAL___extension__ ) {
+                                                $setType(Token.SKIP);
+                                        }
+                                        else {
+                                                $setType(i.getType());
+                                        }
+                                        
+                                    }
+        ;
+
+protected ID
+        options 
+                {
+                testLiterals = true; 
+                }
+        :       ( 'a'..'z' | 'A'..'Z' | '_' | '$')
+                ( 'a'..'z' | 'A'..'Z' | '_' | '$' | '0'..'9' )*
+        ;
+
+WideCharLiteral
+        :
+                'L' CharLiteral
+                                { $setType(CharLiteral); }
+        ;
+
+
+
+WideStringLiteral
+        :
+                'L' StringLiteral
+                                { $setType(StringLiteral); }
+        ;
+
+StringLiteral
+        :
+                '"'
+                ( ('\\' ~('\n'))=> Escape
+                | ( '\r'        { newline(); }
+                  | '\n'        {
+                                newline();
+                                }
+                  | '\\' '\n'   {
+                                newline();
+                                }
+                  )
+                | ~( '"' | '\r' | '\n' | '\\' )
+                )*
+                '"'
+        ;
+
+            
+
+

Propchange: maven/plugins/trunk/maven-antlr-plugin/src/test/resources/unit/java-grammar-inheritance-test/src/main/antlr/GnuCParser.g
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-antlr-plugin/src/test/resources/unit/java-grammar-inheritance-test/src/main/antlr/GnuCParser.g
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/plugins/trunk/maven-antlr-plugin/src/test/resources/unit/java-grammar-inheritance-test/src/main/antlr/GnuCTreeParser.g
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antlr-plugin/src/test/resources/unit/java-grammar-inheritance-test/src/main/antlr/GnuCTreeParser.g?view=auto&rev=446601
==============================================================================
--- maven/plugins/trunk/maven-antlr-plugin/src/test/resources/unit/java-grammar-inheritance-test/src/main/antlr/GnuCTreeParser.g (added)
+++ maven/plugins/trunk/maven-antlr-plugin/src/test/resources/unit/java-grammar-inheritance-test/src/main/antlr/GnuCTreeParser.g Fri Sep 15 06:05:57 2006
@@ -0,0 +1,850 @@
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+        Copyright (c) Non, Inc. 1998 -- All Rights Reserved
+
+PROJECT:        C Compiler
+MODULE:         GnuCTreeParser
+FILE:           GnuCTreeParser.g
+
+AUTHOR:         Monty Zukowski (jamz@cdsnet.net) April 28, 1998
+
+DESCRIPTION:
+
+                This tree grammar is for a Gnu C AST.  No actions in it,
+                subclass to do something useful.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+
+{
+import java.io.*;
+
+import antlr.CommonAST;
+import antlr.DumpASTVisitor;
+}
+
+                     
+class GnuCTreeParser extends TreeParser;
+
+options
+        {
+        importVocab = GNUC;
+        buildAST = false;
+        ASTLabelType = "TNode";
+
+        // Copied following options from java grammar.
+        codeGenMakeSwitchThreshold = 2;
+        codeGenBitsetTestThreshold = 3;
+        }
+
+
+{
+        int traceDepth = 0;
+        public void reportError(RecognitionException ex) {
+          if ( ex != null)   {
+                System.err.println("ANTLR Tree Parsing RecognitionException Error: " + ex.getClass().getName() + " " + ex );
+                ex.printStackTrace(System.err);
+          }
+        }
+        public void reportError(NoViableAltException ex) {
+                System.err.println("ANTLR Tree Parsing NoViableAltException Error: " + ex.toString());
+                TNode.printTree( ex.node );
+                ex.printStackTrace(System.err);
+        }
+        public void reportError(MismatchedTokenException ex) {
+          if ( ex != null)   {
+                TNode.printTree( ex.node );
+                System.err.println("ANTLR Tree Parsing MismatchedTokenException Error: " + ex );
+                ex.printStackTrace(System.err);
+          }
+        }
+        public void reportError(String s) {
+                System.err.println("ANTLR Error from String: " + s);
+        }
+        public void reportWarning(String s) {
+                System.err.println("ANTLR Warning from String: " + s);
+        }
+        protected void match(AST t, int ttype) throws MismatchedTokenException {
+                //System.out.println("match("+ttype+"); cursor is "+t);
+                super.match(t, ttype);
+        }
+        public void match(AST t, BitSet b) throws MismatchedTokenException {
+                //System.out.println("match("+b+"); cursor is "+t);
+                super.match(t, b);
+        }
+        protected void matchNot(AST t, int ttype) throws MismatchedTokenException {
+                //System.out.println("matchNot("+ttype+"); cursor is "+t);
+                super.matchNot(t, ttype);
+                }
+        public void traceIn(String rname, AST t) {
+          traceDepth += 1;
+          for (int x=0; x<traceDepth; x++) System.out.print(" ");
+          super.traceIn(rname, t);   
+        }
+        public void traceOut(String rname, AST t) {
+          for (int x=0; x<traceDepth; x++) System.out.print(" ");
+          super.traceOut(rname, t);
+          traceDepth -= 1;
+        }
+
+
+}
+
+translationUnit  options {
+  defaultErrorHandler=false;
+}
+        :       ( externalList )? 
+        ;
+
+/*
+exception
+catch [RecognitionException ex]
+                        {
+                        reportError(ex);
+                        System.out.println("PROBLEM TREE:\n" 
+                                                + _t.toStringList());
+                        if (_t!=null) {_t = _t.getNextSibling();}
+                        }
+*/
+
+
+externalList
+        :       ( externalDef )+
+        ;
+
+
+externalDef
+        :       declaration
+        |       functionDef
+        |       asm_expr
+        |       SEMI
+        |       typelessDeclaration
+        ;
+
+typelessDeclaration
+        :       #(NTypeMissing initDeclList SEMI)
+        ;
+
+
+
+asm_expr
+        :       #( "asm" ( "volatile" )? LCURLY expr RCURLY ( SEMI )+ )
+        ;
+
+
+declaration
+        :       #( NDeclaration
+                    declSpecifiers
+                    (                   
+                        initDeclList
+                    )?
+                    ( SEMI )+
+                )
+        ;
+
+
+declSpecifiers 
+        :       ( storageClassSpecifier
+                | typeQualifier
+                | typeSpecifier
+                )+
+        ;
+
+storageClassSpecifier
+        :       "auto"
+        |       "register"
+        |       "typedef"
+        |       functionStorageClassSpecifier
+        ;
+
+
+functionStorageClassSpecifier
+        :       "extern"
+        |       "static"
+        |       "inline"
+        ;
+
+
+typeQualifier
+        :       "const"
+        |       "volatile"
+        ;
+
+
+typeSpecifier
+        :       "void"
+        |       "char"
+        |       "short"
+        |       "int"
+        |       "long"
+        |       "float"
+        |       "double"
+        |       "signed"
+        |       "unsigned"
+        |       structSpecifier ( attributeDecl )*
+        |       unionSpecifier  ( attributeDecl )*
+        |       enumSpecifier
+        |       typedefName
+        |       #("typeof" LPAREN
+                    ( (typeName )=> typeName 
+                    | expr
+                    )
+                    RPAREN
+                )
+        |       "__complex"
+        ;
+
+
+typedefName
+        :       #(NTypedefName ID)
+        ;
+
+
+structSpecifier
+        :   #( "struct" structOrUnionBody )
+        ;
+
+unionSpecifier
+        :   #( "union" structOrUnionBody )
+        ;
+   
+structOrUnionBody
+        :       ( (ID LCURLY) => ID LCURLY
+                        ( structDeclarationList )?
+                        RCURLY  
+                |   LCURLY
+                    ( structDeclarationList )?
+                    RCURLY
+                | ID
+                )
+        ;
+/*
+exception
+catch [RecognitionException ex]
+                        {
+                        reportError(ex);
+                        System.out.println("PROBLEM TREE:\n" 
+                                                + _t.toStringList());
+                        if (_t!=null) {_t = _t.getNextSibling();}
+                        }
+*/
+
+
+structDeclarationList
+        :       ( structDeclaration )+
+        ;
+/*
+exception
+catch [RecognitionException ex]
+                        {
+                        reportError(ex);
+                        System.out.println("PROBLEM TREE:\n" 
+                                                + _t.toStringList());
+                        if (_t!=null) {_t = _t.getNextSibling();}
+                        }
+*/
+
+
+
+structDeclaration
+        :       specifierQualifierList structDeclaratorList
+        ;
+/*
+exception
+catch [RecognitionException ex]
+                        {
+                        reportError(ex);
+                        System.out.println("PROBLEM TREE:\n" 
+                                                + _t.toStringList());
+                        if (_t!=null) {_t = _t.getNextSibling();}
+                        }
+*/
+
+
+
+specifierQualifierList
+        :       (
+                typeSpecifier
+                | typeQualifier
+                )+
+        ;
+/*
+exception
+catch [RecognitionException ex]
+                        {
+                        reportError(ex);
+                        System.out.println("PROBLEM TREE:\n" 
+                                                + _t.toStringList());
+                        if (_t!=null) {_t = _t.getNextSibling();}
+                        }
+*/
+
+
+
+structDeclaratorList
+        :       ( structDeclarator )+
+        ;
+/*
+exception
+catch [RecognitionException ex]
+                        {
+                        reportError(ex);
+                        System.out.println("PROBLEM TREE:\n" 
+                                                + _t.toStringList());
+                        if (_t!=null) {_t = _t.getNextSibling();}
+                        }
+*/
+
+
+
+structDeclarator
+        :
+        #( NStructDeclarator      
+            ( declarator )?
+            ( COLON expr )?
+            ( attributeDecl )*
+        )
+        ;
+/*
+exception
+catch [RecognitionException ex]
+                        {
+                        reportError(ex);
+                        System.out.println("PROBLEM TREE:\n" 
+                                                + _t.toStringList());
+                        if (_t!=null) {_t = _t.getNextSibling();}
+                        }
+*/
+
+
+
+
+enumSpecifier
+        :   #(  "enum"
+                ( ID )? 
+                ( LCURLY enumList RCURLY )?
+            )
+        ;
+
+
+enumList
+        :       ( enumerator )+
+        ;
+
+
+enumerator
+        :       ID ( ASSIGN expr )?
+        ;
+
+
+
+attributeDecl:
+        #( "__attribute" (.)* )
+        | #( NAsmAttribute LPAREN expr RPAREN )
+        ;
+
+initDeclList
+        :       ( initDecl )+
+        ;
+
+
+initDecl
+                                        { String declName = ""; }
+        :       #( NInitDecl
+                declarator
+                ( attributeDecl )*
+                ( ASSIGN initializer
+                | COLON expr
+                )?
+                )
+        ;
+
+
+pointerGroup
+        :       #( NPointerGroup ( STAR ( typeQualifier )* )+ )
+        ;
+
+
+
+idList
+        :       ID ( COMMA ID )*
+        ;
+
+
+
+initializer
+        :       #( NInitializer (initializerElementLabel)? expr )
+                |   lcurlyInitializer
+        ;
+
+initializerElementLabel
+        :   #( NInitializerElementLabel
+                (
+                    ( LBRACKET expr RBRACKET (ASSIGN)? )
+                    | ID COLON
+                    | DOT ID ASSIGN
+                )
+            )
+        ;
+
+lcurlyInitializer
+        :  #( NLcurlyInitializer
+                initializerList
+                RCURLY
+            )
+        ;
+
+initializerList
+        :       ( initializer )*
+        ;
+
+
+declarator
+        :   #( NDeclarator
+                ( pointerGroup )?               
+
+                ( id:ID
+                | LPAREN declarator RPAREN
+                )
+
+                (   #( NParameterTypeList
+                      (
+                        parameterTypeList
+                        | (idList)?
+                      )
+                      RPAREN
+                    )
+                 | LBRACKET ( expr )? RBRACKET
+                )*
+             )
+        ;
+
+
+ 
+parameterTypeList
+        :       ( parameterDeclaration ( COMMA | SEMI )? )+ ( VARARGS )?
+        ;
+    
+
+
+parameterDeclaration
+        :       #( NParameterDeclaration
+                declSpecifiers
+                (declarator | nonemptyAbstractDeclarator)?
+                )
+        ;
+
+
+functionDef
+        :   #( NFunctionDef
+                ( functionDeclSpecifiers)? 
+                declarator
+                (declaration | VARARGS)*
+                compoundStatement
+            )
+        ;
+/*
+exception
+catch [RecognitionException ex]
+                        {
+                        reportError(ex);
+                        System.out.println("PROBLEM TREE:\n" 
+                                                + _t.toStringList());
+                        if (_t!=null) {_t = _t.getNextSibling();}
+                        }
+*/
+
+functionDeclSpecifiers
+        :       
+                ( functionStorageClassSpecifier
+                | typeQualifier
+                | typeSpecifier
+                )+
+        ;
+
+declarationList
+        :       
+                (   //ANTLR doesn't know that declarationList properly eats all the declarations
+                    //so it warns about the ambiguity
+                    options {
+                        warnWhenFollowAmbig = false;
+                    } :
+                localLabelDecl
+                | declaration
+                )+
+        ;
+
+localLabelDecl
+        :   #("__label__" (ID)+ )
+        ;
+   
+
+
+compoundStatement
+        :       #( NCompoundStatement
+                ( declarationList
+                | functionDef
+                )*
+                ( statementList )?
+                RCURLY
+                )
+        ;
+
+statementList
+        :       ( statement )+
+        ;
+
+statement
+        :       statementBody
+        ;
+        
+statementBody
+        :       SEMI                    // Empty statements
+
+        |       compoundStatement       // Group of statements
+
+        |       #(NStatementExpr expr)                    // Expressions
+
+// Iteration statements:
+
+        |       #( "while" expr statement )
+        |       #( "do" statement expr )
+        |       #( "for"
+                expr expr expr
+                statement
+                )
+
+
+// Jump statements:
+
+        |       #( "goto" expr )
+        |       "continue" 
+        |       "break"
+        |       #( "return" ( expr )? )
+
+
+// Labeled statements:
+        |       #( NLabel ID (statement)? )
+        |       #( "case" expr (statement)? )
+        |       #( "default" (statement)? )
+
+
+
+// Selection statements:
+
+        |       #( "if"
+                    expr statement  
+                    ( "else" statement )?
+                 )
+        |       #( "switch" expr statement )
+
+
+
+        ;
+/*
+exception
+catch [RecognitionException ex]
+                        {
+                        reportError(ex);
+                        System.out.println("PROBLEM TREE:\n" 
+                                                + _t.toStringList());
+                        if (_t!=null) {_t = _t.getNextSibling();}
+                        }
+*/
+
+
+
+
+
+
+expr
+        :       assignExpr
+        |       conditionalExpr
+        |       logicalOrExpr
+        |       logicalAndExpr
+        |       inclusiveOrExpr
+        |       exclusiveOrExpr
+        |       bitAndExpr
+        |       equalityExpr
+        |       relationalExpr
+        |       shiftExpr
+        |       additiveExpr
+        |       multExpr
+        |       castExpr
+        |       unaryExpr
+        |       postfixExpr
+        |       primaryExpr
+        |       commaExpr
+        |       emptyExpr
+        |       compoundStatementExpr
+        |       initializer
+        |       rangeExpr
+        |       gnuAsmExpr
+        ;
+
+commaExpr
+        :   #(NCommaExpr expr expr)
+        ;
+
+emptyExpr
+        :   NEmptyExpression
+        ;
+
+compoundStatementExpr
+        :   #(LPAREN compoundStatement RPAREN)
+        ;
+
+rangeExpr
+        :   #(NRangeExpr expr VARARGS expr)
+        ;
+
+gnuAsmExpr
+        :   #(NGnuAsmExpr
+                ("volatile")? 
+                LPAREN stringConst
+                ( options { warnWhenFollowAmbig = false; }:
+                  COLON (strOptExprPair ( COMMA strOptExprPair)* )?
+                  ( options { warnWhenFollowAmbig = false; }:
+                    COLON (strOptExprPair ( COMMA strOptExprPair)* )?
+                  )?
+                )?
+                ( COLON stringConst ( COMMA stringConst)* )?
+                RPAREN
+            )
+        ;
+
+strOptExprPair
+        :  stringConst ( LPAREN expr RPAREN )?
+        ;
+        
+assignExpr
+        :       #( ASSIGN expr expr)
+        |       #( DIV_ASSIGN expr expr)
+        |       #( PLUS_ASSIGN expr expr)
+        |       #( MINUS_ASSIGN expr expr)
+        |       #( STAR_ASSIGN expr expr)
+        |       #( MOD_ASSIGN expr expr)
+        |       #( RSHIFT_ASSIGN expr expr)
+        |       #( LSHIFT_ASSIGN expr expr)
+        |       #( BAND_ASSIGN expr expr)
+        |       #( BOR_ASSIGN expr expr)
+        |       #( BXOR_ASSIGN expr expr)
+        ;
+
+
+conditionalExpr
+        :       #( QUESTION expr (expr)? COLON expr )
+        ;
+
+
+logicalOrExpr
+        :       #( LOR expr expr) 
+        ;
+
+
+logicalAndExpr
+        :       #( LAND expr expr )
+        ;
+
+
+inclusiveOrExpr
+        :       #( BOR expr expr )
+        ;
+
+
+exclusiveOrExpr
+        :       #( BXOR expr expr )
+        ;
+
+
+bitAndExpr
+        :       #( BAND expr expr )
+        ;
+
+
+
+equalityExpr
+        :       #( EQUAL expr expr)
+        |       #( NOT_EQUAL expr expr)
+        ;
+
+
+relationalExpr
+        :       #( LT expr expr)
+        |       #( LTE expr expr)
+        |       #( GT expr expr)
+        |       #( GTE expr expr)
+        ;
+
+
+
+shiftExpr
+        :       #( LSHIFT expr expr)
+                | #( RSHIFT expr expr)
+        ;
+
+
+additiveExpr
+        :       #( PLUS expr expr)
+        |       #( MINUS expr expr)
+        ;
+
+
+multExpr
+        :       #( STAR expr expr)
+        |       #( DIV expr expr)
+        |       #( MOD expr expr)
+        ;
+
+
+
+castExpr
+        :       #( NCast typeName RPAREN expr)
+        ;
+
+
+typeName
+        :       specifierQualifierList (nonemptyAbstractDeclarator)?
+        ;
+
+nonemptyAbstractDeclarator
+        :   #( NNonemptyAbstractDeclarator
+            (   pointerGroup
+                (   (LPAREN  
+                    (   nonemptyAbstractDeclarator
+                        | parameterTypeList
+                    )?
+                    RPAREN)
+                | (LBRACKET (expr)? RBRACKET)
+                )*
+
+            |  (   (LPAREN  
+                    (   nonemptyAbstractDeclarator
+                        | parameterTypeList
+                    )?
+                    RPAREN)
+                | (LBRACKET (expr)? RBRACKET)
+                )+
+            )
+            )
+        ;
+
+
+
+unaryExpr
+        :       #( INC expr )
+        |       #( DEC expr )
+        |       #( NUnaryExpr unaryOperator expr)
+        |       #( "sizeof"
+                    ( ( LPAREN typeName )=> LPAREN typeName RPAREN
+                    | expr
+                    )
+                )
+        |       #( "__alignof"
+                    ( ( LPAREN typeName )=> LPAREN typeName RPAREN
+                    | expr
+                    )
+                )
+        ;
+/*
+exception
+catch [RecognitionException ex]
+                        {
+                        reportError(ex);
+                        System.out.println("PROBLEM TREE:\n" 
+                                                + _t.toStringList());
+                        if (_t!=null) {_t = _t.getNextSibling();}
+                        }
+*/
+
+    unaryOperator
+        :       BAND
+        |       STAR
+        |       PLUS
+        |       MINUS
+        |       BNOT
+        |       LNOT
+        |       LAND
+        |       "__real"
+        |       "__imag"
+        ;
+
+
+postfixExpr
+        :       #( NPostfixExpr
+                    primaryExpr
+                    ( PTR ID
+                    | DOT ID
+                    | #( NFunctionCallArgs (argExprList)? RPAREN )
+                    | LBRACKET expr RBRACKET
+                    | INC
+                    | DEC
+                    )+
+                )
+        ;
+
+
+
+primaryExpr
+        :       ID
+        |       Number
+        |       charConst
+        |       stringConst
+
+// JTC:
+// ID should catch the enumerator
+// leaving it in gives ambiguous err
+//      | enumerator
+
+        |       #( NExpressionGroup expr )
+        ;
+
+
+
+argExprList
+        :       ( expr )+
+        ;
+
+
+
+protected
+charConst
+        :       CharLiteral
+        ;
+
+
+protected
+stringConst
+        :       #(NStringSeq (StringLiteral)+)
+        ;
+
+
+protected
+intConst
+        :       IntOctalConst
+        |       LongOctalConst
+        |       UnsignedOctalConst
+        |       IntIntConst
+        |       LongIntConst
+        |       UnsignedIntConst
+        |       IntHexConst
+        |       LongHexConst
+        |       UnsignedHexConst
+        ;
+
+
+protected
+floatConst
+        :       FloatDoubleConst
+        |       DoubleDoubleConst
+        |       LongDoubleConst
+        ;
+
+
+    
+
+
+
+
+
+

Propchange: maven/plugins/trunk/maven-antlr-plugin/src/test/resources/unit/java-grammar-inheritance-test/src/main/antlr/GnuCTreeParser.g
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-antlr-plugin/src/test/resources/unit/java-grammar-inheritance-test/src/main/antlr/GnuCTreeParser.g
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/plugins/trunk/maven-antlr-plugin/src/test/resources/unit/java-grammar-inheritance-test/src/main/antlr/StdCParser.g
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antlr-plugin/src/test/resources/unit/java-grammar-inheritance-test/src/main/antlr/StdCParser.g?view=auto&rev=446601
==============================================================================
--- maven/plugins/trunk/maven-antlr-plugin/src/test/resources/unit/java-grammar-inheritance-test/src/main/antlr/StdCParser.g (added)
+++ maven/plugins/trunk/maven-antlr-plugin/src/test/resources/unit/java-grammar-inheritance-test/src/main/antlr/StdCParser.g Fri Sep 15 06:05:57 2006
@@ -0,0 +1,1357 @@
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+        Copyright (c) Non, Inc. 1997 -- All Rights Reserved
+
+PROJECT:        C Compiler
+MODULE:         Parser
+FILE:           stdc.g
+
+AUTHOR:         John D. Mitchell (john@non.net), Jul 12, 1997
+
+REVISION HISTORY:
+
+        Name    Date            Description
+        ----    ----            -----------
+        JDM     97.07.12        Initial version.
+        JTC     97.11.18        Declaration vs declarator & misc. hacking.
+        JDM     97.11.20        Fixed:  declaration vs funcDef,
+                                        parenthesized expressions,
+                                        declarator iteration,
+                                        varargs recognition,
+                                        empty source file recognition,
+                                        and some typos.
+                                        
+
+DESCRIPTION:
+
+        This grammar supports the Standard C language.
+
+        Note clearly that this grammar does *NOT* deal with
+        preprocessor functionality (including things like trigraphs)
+        Nor does this grammar deal with multi-byte characters nor strings
+        containing multi-byte characters [these constructs are "exercises
+        for the reader" as it were :-)].
+
+        Please refer to the ISO/ANSI C Language Standard if you believe
+        this grammar to be in error.  Please cite chapter and verse in any
+        correspondence to the author to back up your claim.
+
+TODO:
+
+        - typedefName is commented out, needs a symbol table to resolve
+        ambiguity.
+
+        - trees
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+
+{
+import java.io.*;
+
+import antlr.CommonAST;
+import antlr.DumpASTVisitor;
+}
+
+                     
+class StdCParser extends Parser;
+
+options
+        {
+        k = 2;
+        exportVocab = STDC;
+        buildAST = true;
+        ASTLabelType = "TNode";
+
+        // Copied following options from java grammar.
+        codeGenMakeSwitchThreshold = 2;
+        codeGenBitsetTestThreshold = 3;
+        }
+
+
+{
+    // Suppport C++-style single-line comments?
+    public static boolean CPPComments = true;
+
+    // access to symbol table
+    public CSymbolTable symbolTable = new CSymbolTable();
+
+    // source for names to unnamed scopes
+    protected int unnamedScopeCounter = 0;
+
+    public boolean isTypedefName(String name) {
+      boolean returnValue = false;
+      TNode node = symbolTable.lookupNameInCurrentScope(name);
+      for (; node != null; node = (TNode) node.getNextSibling() ) {
+        if(node.getType() == LITERAL_typedef) {
+            returnValue = true;
+            break;
+        }
+      }
+      return returnValue;
+    }
+
+
+    public String getAScopeName() {
+      return "" + (unnamedScopeCounter++);
+    }
+
+    public void pushScope(String scopeName) {
+      symbolTable.pushScope(scopeName);
+    }
+
+    public void popScope() {
+      symbolTable.popScope();
+    }
+
+        int traceDepth = 0;
+        public void reportError(RecognitionException ex) {
+          try {
+            System.err.println("ANTLR Parsing Error: "+ex + " token name:" + tokenNames[LA(1)]);
+            ex.printStackTrace(System.err);
+          }
+	  catch (TokenStreamException e) {
+            System.err.println("ANTLR Parsing Error: "+ex);
+            ex.printStackTrace(System.err);              
+          }
+        }
+        public void reportError(String s) {
+            System.err.println("ANTLR Parsing Error from String: " + s);
+        }
+        public void reportWarning(String s) {
+            System.err.println("ANTLR Parsing Warning from String: " + s);
+        }
+        public void match(int t) throws MismatchedTokenException {
+          boolean debugging = false;
+          
+          if ( debugging ) {
+           for (int x=0; x<traceDepth; x++) System.out.print(" ");
+           try {
+            System.out.println("Match("+tokenNames[t]+") with LA(1)="+
+                tokenNames[LA(1)] + ((inputState.guessing>0)?" [inputState.guessing "+ inputState.guessing + "]":""));
+           }
+           catch (TokenStreamException e) {
+            System.out.println("Match("+tokenNames[t]+") " + ((inputState.guessing>0)?" [inputState.guessing "+ inputState.guessing + "]":""));
+
+           }
+    
+          }
+          try {
+            if ( LA(1)!=t ) {
+                if ( debugging ){
+                    for (int x=0; x<traceDepth; x++) System.out.print(" ");
+                    System.out.println("token mismatch: "+tokenNames[LA(1)]
+                                + "!="+tokenNames[t]);
+                }
+	        throw new MismatchedTokenException(tokenNames, LT(1), t, false, getFilename());
+
+            } else {
+                // mark token as consumed -- fetch next token deferred until LA/LT
+                consume();
+            }
+          }
+          catch (TokenStreamException e) {
+          }
+    
+        }
+        public void traceIn(String rname) {
+          traceDepth += 1;
+          for (int x=0; x<traceDepth; x++) System.out.print(" ");
+          try {
+            System.out.println("> "+rname+"; LA(1)==("+ tokenNames[LT(1).getType()] 
+                + ") " + LT(1).getText() + " [inputState.guessing "+ inputState.guessing + "]");
+          }
+          catch (TokenStreamException e) {
+          }
+        }
+        public void traceOut(String rname) {
+          for (int x=0; x<traceDepth; x++) System.out.print(" ");
+          try {
+            System.out.println("< "+rname+"; LA(1)==("+ tokenNames[LT(1).getType()] 
+                + ") "+LT(1).getText() + " [inputState.guessing "+ inputState.guessing + "]");
+          }
+          catch (TokenStreamException e) {
+          }
+          traceDepth -= 1;
+        }
+    
+}
+
+
+
+translationUnit
+        :       externalList
+
+        |       /* Empty source files are *not* allowed.  */
+                {
+                System.err.println ( "Empty source file!" );
+                }
+        ;
+
+
+externalList
+        :       ( externalDef )+
+        ;
+
+
+externalDef
+        :       ( "typedef" | declaration )=> declaration
+        |       functionDef
+        |       asm_expr
+        ;
+
+
+asm_expr
+        :       "asm"^ 
+                ("volatile")? LCURLY! expr RCURLY! SEMI!
+        ;
+
+
+declaration
+                                        { AST ds1 = null; }
+        :       ds:declSpecifiers       { ds1 = astFactory.dupList(#ds); }
+                (                       
+                    initDeclList[ds1]
+                )?
+                SEMI!
+                                        { ## = #( #[NDeclaration], ##); }
+                
+        ;
+
+
+declSpecifiers 
+                                { int specCount=0; }
+        :       (               options { // this loop properly aborts when
+                                          //  it finds a non-typedefName ID MBZ
+                                          warnWhenFollowAmbig = false;
+                                        } :
+                  s:storageClassSpecifier
+                | typeQualifier
+                | ( "struct" | "union" | "enum" | typeSpecifier[specCount] )=>
+                        specCount = typeSpecifier[specCount]
+                )+
+        ;
+
+storageClassSpecifier
+        :       "auto"                  
+        |       "register"              
+        |       "typedef"               
+        |       functionStorageClassSpecifier
+        ;
+
+
+functionStorageClassSpecifier
+        :       "extern"
+        |       "static"
+        ;
+
+
+typeQualifier
+        :       "const"
+        |       "volatile"
+        ;
+
+typeSpecifier [int specCount] returns [int retSpecCount]
+                                                        { retSpecCount = specCount + 1; }
+        :
+        (       "void"
+        |       "char"
+        |       "short"
+        |       "int"
+        |       "long"
+        |       "float"
+        |       "double"
+        |       "signed"
+        |       "unsigned"
+        |       structOrUnionSpecifier
+        |       enumSpecifier
+        |       { specCount == 0 }? typedefName
+        )
+        ;
+
+
+typedefName
+        :       { isTypedefName ( LT(1).getText() ) }?
+                i:ID                    { ## = #(#[NTypedefName], #i); }
+        ;
+
+structOrUnionSpecifier
+                                        { String scopeName; }
+        :       sou:structOrUnion!
+                ( ( ID LCURLY )=> i:ID l:LCURLY
+                                            {
+                                            scopeName = #sou.getText() + " " + #i.getText();
+                                            #l.setText(scopeName);
+                                            pushScope(scopeName);
+                                            }
+                        structDeclarationList
+                                            { popScope();}
+                        RCURLY!
+                |   l1:LCURLY
+                                            {
+                                            scopeName = getAScopeName();
+                                            #l1.setText(scopeName);
+                                            pushScope(scopeName);
+                                            }
+                    structDeclarationList
+                                            { popScope(); }
+                    RCURLY!
+                | ID
+                )
+                                            {
+                                            ## = #( #sou, ## );
+                                            }
+        ;
+
+
+structOrUnion
+        :       "struct"
+        |       "union"
+        ;
+
+
+structDeclarationList
+        :       ( structDeclaration )+
+        ;
+
+
+structDeclaration
+        :       specifierQualifierList structDeclaratorList ( SEMI! )+
+        ;
+
+
+specifierQualifierList
+                                { int specCount = 0; }
+        :       (               options {   // this loop properly aborts when
+                                            // it finds a non-typedefName ID MBZ
+                                            warnWhenFollowAmbig = false;
+                                        } :
+                ( "struct" | "union" | "enum" | typeSpecifier[specCount] )=>
+                        specCount = typeSpecifier[specCount]
+                | typeQualifier
+                )+
+        ;
+
+
+structDeclaratorList
+        :       structDeclarator ( COMMA! structDeclarator )*
+        ;
+
+
+structDeclarator
+        :
+        (       COLON constExpr
+        |       declarator[false] ( COLON constExpr )?
+        )
+                                    { ## = #( #[NStructDeclarator], ##); }
+        ;
+
+
+enumSpecifier
+        :       "enum"^
+                ( ( ID LCURLY )=> i:ID LCURLY enumList[i.getText()] RCURLY!
+                | LCURLY enumList["anonymous"] RCURLY!
+                | ID
+                )
+        ;
+
+
+enumList[String enumName]
+        :       enumerator[enumName] ( COMMA! enumerator[enumName] )*  
+        ;
+
+enumerator[String enumName]
+        :       i:ID                { symbolTable.add(  i.getText(),
+                                                        #(   null,
+                                                            #[LITERAL_enum, "enum"],
+                                                            #[ ID, enumName]
+                                                         )
+                                                     );
+                                    }
+                (ASSIGN constExpr)?
+        ;
+
+
+initDeclList[AST declarationSpecifiers]
+        :       initDecl[declarationSpecifiers] 
+                ( COMMA! initDecl[declarationSpecifiers] )*
+        ;
+
+
+initDecl[AST declarationSpecifiers]
+                                        { String declName = ""; }
+        :       declName = d:declarator[false]
+                                        {   AST ds1, d1;
+                                            ds1 = astFactory.dupList(declarationSpecifiers);
+                                            d1 = astFactory.dupList(#d);
+                                            symbolTable.add(declName, #(null, ds1, d1) );
+                                        }
+                ( ASSIGN initializer
+                | COLON expr
+                )?
+                                        { ## = #( #[NInitDecl], ## ); }
+
+        ;
+
+pointerGroup
+        :       ( STAR ( typeQualifier )* )+    { ## = #( #[NPointerGroup], ##); }
+        ;
+
+
+
+idList
+        :       ID ( COMMA! ID )*
+        ;
+
+
+initializer
+        :       ( assignExpr
+                |       LCURLY initializerList ( COMMA! )? RCURLY!
+                )
+                        { ## = #( #[NInitializer], ## ); }
+        ;
+
+
+initializerList
+        :       initializer ( COMMA! initializer )*
+        ;
+
+
+declarator[boolean isFunctionDefinition] returns [String declName]
+                                                { declName = ""; }
+        :
+                ( pointerGroup )?               
+
+                ( id:ID                         { declName = id.getText(); }
+                | LPAREN declName = declarator[false] RPAREN
+                )
+
+                ( !  LPAREN
+                                                { 
+                                                    if (isFunctionDefinition) {
+                                                        pushScope(declName);
+                                                    }
+                                                    else {
+                                                        pushScope("!"+declName); 
+                                                    }
+                                                }
+                    (                           
+                        (declSpecifiers)=> p:parameterTypeList
+                                                {
+                                                ## = #( null, ##, #( #[NParameterTypeList], #p ) );
+                                                }
+
+                        | (i:idList)?
+                                                {
+                                                ## = #( null, ##, #( #[NParameterTypeList], #i ) );
+                                                }
+                    )
+                                                {
+                                                popScope();
+                                                }    
+                  RPAREN                        
+                | LBRACKET ( constExpr )? RBRACKET
+                )*
+                                                { ## = #( #[NDeclarator], ## ); }
+        ;
+ 
+parameterTypeList
+        :       parameterDeclaration
+                (   options {
+                            warnWhenFollowAmbig = false;
+                        } : 
+                  COMMA!
+                  parameterDeclaration
+                )*
+                ( COMMA!
+                  VARARGS
+                )?
+        ;
+
+
+parameterDeclaration
+                            { String declName; }
+        :       ds:declSpecifiers
+                ( ( declarator[false] )=> declName = d:declarator[false]
+                            {
+                            AST d2, ds2;
+                            d2 = astFactory.dupList(#d);
+                            ds2 = astFactory.dupList(#ds);
+                            symbolTable.add(declName, #(null, ds2, d2));
+                            }
+                | nonemptyAbstractDeclarator
+                )?
+                            {
+                            ## = #( #[NParameterDeclaration], ## );
+                            }
+        ;
+
+/* JTC:
+ * This handles both new and old style functions.
+ * see declarator rule to see differences in parameters
+ * and here (declaration SEMI)* is the param type decls for the
+ * old style.  may want to do some checking to check for illegal
+ * combinations (but I assume all parsed code will be legal?)
+ */
+
+functionDef
+                            { String declName; }
+        :       ( (functionDeclSpecifiers)=> ds:functionDeclSpecifiers
+                |  //epsilon
+                )
+                declName = d:declarator[true]
+                            {
+                            AST d2, ds2;
+                            d2 = astFactory.dupList(#d);
+                            ds2 = astFactory.dupList(#ds);
+                            symbolTable.add(declName, #(null, ds2, d2));
+                            pushScope(declName);
+                            }
+                ( declaration )* (VARARGS)? ( SEMI! )*
+                            { popScope(); }
+                compoundStatement[declName]
+                            { ## = #( #[NFunctionDef], ## );}
+        ;
+
+functionDeclSpecifiers
+                                { int specCount = 0; }
+        :       (               options {   // this loop properly aborts when
+                                            // it finds a non-typedefName ID MBZ
+                                            warnWhenFollowAmbig = false;
+                                        } :
+                  functionStorageClassSpecifier
+                | typeQualifier
+                | ( "struct" | "union" | "enum" | typeSpecifier[specCount] )=>
+                        specCount = typeSpecifier[specCount]
+                )+
+        ;
+
+declarationList
+        :       (               options {   // this loop properly aborts when
+                                            // it finds a non-typedefName ID MBZ
+                                            warnWhenFollowAmbig = false;
+                                        } :
+                ( declarationPredictor )=> declaration
+                )+
+        ;
+
+declarationPredictor
+        :       (options {      //only want to look at declaration if I don't see typedef
+                    warnWhenFollowAmbig = false;
+                }:
+                "typedef"
+                | declaration
+                )
+        ;
+
+
+compoundStatement[String scopeName]
+        :       LCURLY!
+                            {
+                                pushScope(scopeName);
+                            }
+                ( ( declarationPredictor)=> declarationList )?
+                ( statementList )?
+                            { popScope(); }
+                RCURLY!
+                            { ## = #( #[NCompoundStatement, scopeName], ##); }
+        ;
+
+    
+statementList
+        :       ( statement )+
+        ;
+statement
+        :       SEMI                    // Empty statements
+
+        |       compoundStatement[getAScopeName()]       // Group of statements
+
+        |       expr SEMI!               { ## = #( #[NStatementExpr], ## ); } // Expressions
+
+// Iteration statements:
+
+        |       "while"^ LPAREN! expr RPAREN! statement
+        |       "do"^ statement "while"! LPAREN! expr RPAREN! SEMI!
+        |!       "for"
+                LPAREN ( e1:expr )? SEMI ( e2:expr )? SEMI ( e3:expr )? RPAREN
+                s:statement
+                                    {
+                                        if ( #e1 == null) { #e1 = #[ NEmptyExpression ]; }
+                                        if ( #e2 == null) { #e2 = #[ NEmptyExpression ]; }
+                                        if ( #e3 == null) { #e3 = #[ NEmptyExpression ]; }
+                                        ## = #( #[LITERAL_for, "for"], #e1, #e2, #e3, #s );
+                                    }
+
+
+// Jump statements:
+
+        |       "goto"^ ID SEMI!
+        |       "continue" SEMI!
+        |       "break" SEMI!
+        |       "return"^ ( expr )? SEMI!
+
+
+// Labeled statements:
+        |       ID COLON! (options {warnWhenFollowAmbig=false;}:statement)? { ## = #( #[NLabel], ## ); }
+        |       "case"^ constExpr COLON! statement
+        |       "default"^ COLON! statement
+
+
+
+// Selection statements:
+
+        |       "if"^
+                 LPAREN! expr RPAREN! statement  
+                ( //standard if-else ambiguity
+                        options {
+                            warnWhenFollowAmbig = false;
+                        } :
+                "else" statement )?
+        |       "switch"^ LPAREN! expr RPAREN! statement
+        ;
+
+
+
+
+
+
+expr
+        :       assignExpr (options {
+                                /* MBZ:
+                                    COMMA is ambiguous between comma expressions and
+                                    argument lists.  argExprList should get priority,
+                                    and it does by being deeper in the expr rule tree
+                                    and using (COMMA assignExpr)*
+                                */
+                                warnWhenFollowAmbig = false;
+                            } :
+                            c:COMMA^ { #c.setType(NCommaExpr); } assignExpr         
+                            )*
+        ;
+
+
+assignExpr
+        :       conditionalExpr ( a:assignOperator! assignExpr { ## = #( #a, ## );} )?
+        ;
+
+assignOperator
+        :       ASSIGN
+        |       DIV_ASSIGN
+        |       PLUS_ASSIGN
+        |       MINUS_ASSIGN
+        |       STAR_ASSIGN
+        |       MOD_ASSIGN
+        |       RSHIFT_ASSIGN
+        |       LSHIFT_ASSIGN
+        |       BAND_ASSIGN
+        |       BOR_ASSIGN
+        |       BXOR_ASSIGN
+        ;
+
+
+conditionalExpr
+        :       logicalOrExpr
+                ( QUESTION^ expr COLON! conditionalExpr )?
+        ;
+
+
+constExpr
+        :       conditionalExpr
+        ;
+
+logicalOrExpr
+        :       logicalAndExpr ( LOR^ logicalAndExpr )*
+        ;
+
+
+logicalAndExpr
+        :       inclusiveOrExpr ( LAND^ inclusiveOrExpr )*
+        ;
+
+inclusiveOrExpr
+        :       exclusiveOrExpr ( BOR^ exclusiveOrExpr )*
+        ;
+
+
+exclusiveOrExpr
+        :       bitAndExpr ( BXOR^ bitAndExpr )*
+        ;
+
+
+bitAndExpr
+        :       equalityExpr ( BAND^ equalityExpr )*
+        ;
+
+
+
+equalityExpr
+        :       relationalExpr
+                ( ( EQUAL^ | NOT_EQUAL^ ) relationalExpr )*
+        ;
+
+
+relationalExpr
+        :       shiftExpr
+                ( ( LT^ | LTE^ | GT^ | GTE^ ) shiftExpr )*
+        ;
+
+
+
+shiftExpr
+        :       additiveExpr
+                ( ( LSHIFT^ | RSHIFT^ ) additiveExpr )*
+        ;
+
+
+additiveExpr
+        :       multExpr
+                ( ( PLUS^ | MINUS^ ) multExpr )*
+        ;
+
+
+multExpr
+        :       castExpr
+                ( ( STAR^ | DIV^ | MOD^ ) castExpr )*
+        ;
+
+
+castExpr
+        :       ( LPAREN typeName RPAREN )=>
+                LPAREN! typeName RPAREN! ( castExpr )
+                            { ## = #( #[NCast, "("], ## ); }
+
+        |       unaryExpr
+        ;
+
+
+typeName
+        :       specifierQualifierList (nonemptyAbstractDeclarator)?
+        ;
+
+nonemptyAbstractDeclarator
+        :   (
+                pointerGroup
+                (   (LPAREN  
+                    (   nonemptyAbstractDeclarator
+                        | parameterTypeList
+                    )?
+                    RPAREN)
+                | (LBRACKET (expr)? RBRACKET)
+                )*
+
+            |   (   (LPAREN  
+                    (   nonemptyAbstractDeclarator
+                        | parameterTypeList
+                    )?
+                    RPAREN)
+                | (LBRACKET (expr)? RBRACKET)
+                )+
+            )
+                            {   ## = #( #[NNonemptyAbstractDeclarator], ## ); }
+                                
+        ;
+
+/* JTC:
+
+LR rules:
+
+abstractDeclarator
+        :       nonemptyAbstractDeclarator
+        |       // null
+        ;
+
+nonemptyAbstractDeclarator
+        :       LPAREN  nonemptyAbstractDeclarator RPAREN
+        |       abstractDeclarator LPAREN RPAREN
+        |       abstractDeclarator (LBRACKET (expr)? RBRACKET)
+        |       STAR abstractDeclarator
+        ;
+*/
+
+unaryExpr
+        :       postfixExpr
+        |       INC^ unaryExpr
+        |       DEC^ unaryExpr
+        |       u:unaryOperator castExpr { ## = #( #[NUnaryExpr], ## ); }
+
+        |       "sizeof"^
+                ( ( LPAREN typeName )=> LPAREN typeName RPAREN
+                | unaryExpr
+                )
+        ;
+
+
+unaryOperator
+        :       BAND
+        |       STAR
+        |       PLUS
+        |       MINUS
+        |       BNOT
+        |       LNOT
+        ;
+
+postfixExpr
+        :       primaryExpr
+                ( 
+                postfixSuffix                   {## = #( #[NPostfixExpr], ## );} 
+                )?
+        ;
+postfixSuffix
+        :
+                ( PTR ID
+                | DOT ID
+                | functionCall
+                | LBRACKET expr RBRACKET
+                | INC
+                | DEC
+                )+
+        ;
+
+functionCall
+        :
+                LPAREN^ (a:argExprList)? RPAREN
+                        {
+                        ##.setType( NFunctionCallArgs );
+                        }
+        ;
+    
+
+primaryExpr
+        :       ID
+        |       charConst
+        |       intConst
+        |       floatConst
+        |       stringConst
+
+// JTC:
+// ID should catch the enumerator
+// leaving it in gives ambiguous err
+//      | enumerator
+        |       LPAREN! expr RPAREN!        { ## = #( #[NExpressionGroup, "("], ## ); }
+        ;
+
+argExprList
+        :       assignExpr ( COMMA! assignExpr )*
+        ;
+
+
+
+protected
+charConst
+        :       CharLiteral
+        ;
+
+
+protected
+stringConst
+        :       (StringLiteral)+                { ## = #(#[NStringSeq], ##); }
+        ;
+
+
+protected
+intConst
+        :       IntOctalConst
+        |       LongOctalConst
+        |       UnsignedOctalConst
+        |       IntIntConst
+        |       LongIntConst
+        |       UnsignedIntConst
+        |       IntHexConst
+        |       LongHexConst
+        |       UnsignedHexConst
+        ;
+
+
+protected
+floatConst
+        :       FloatDoubleConst
+        |       DoubleDoubleConst
+        |       LongDoubleConst
+        ;
+
+
+
+
+    
+
+dummy
+        :       NTypedefName
+        |       NInitDecl
+        |       NDeclarator
+        |       NStructDeclarator
+        |       NDeclaration
+        |       NCast
+        |       NPointerGroup
+        |       NExpressionGroup
+        |       NFunctionCallArgs
+        |       NNonemptyAbstractDeclarator
+        |       NInitializer
+        |       NStatementExpr
+        |       NEmptyExpression
+        |       NParameterTypeList
+        |       NFunctionDef
+        |       NCompoundStatement
+        |       NParameterDeclaration
+        |       NCommaExpr
+        |       NUnaryExpr
+        |       NLabel
+        |       NPostfixExpr
+        |       NRangeExpr
+        |       NStringSeq
+        |       NInitializerElementLabel
+        |       NLcurlyInitializer
+        |       NAsmAttribute
+        |       NGnuAsmExpr
+        |       NTypeMissing
+        ;
+
+
+
+    
+
+
+{
+        import CToken;
+        import java.io.*;
+        import LineObject;
+        import antlr.*;
+}
+
+class StdCLexer extends Lexer;
+
+options
+        {
+        k = 3;
+        exportVocab = STDC;
+        testLiterals = false;
+        }
+
+{
+  LineObject lineObject = new LineObject();
+  String originalSource = "";
+  PreprocessorInfoChannel preprocessorInfoChannel = new PreprocessorInfoChannel();
+  int tokenNumber = 0;
+  boolean countingTokens = true;
+  int deferredLineCount = 0;
+
+  public void setCountingTokens(boolean ct) 
+  {
+    countingTokens = ct;
+    if ( countingTokens ) {
+      tokenNumber = 0;
+    }
+    else {
+      tokenNumber = 1;
+    }
+  }
+
+  public void setOriginalSource(String src) 
+  {
+    originalSource = src;
+    lineObject.setSource(src);
+  }
+  public void setSource(String src) 
+  {
+    lineObject.setSource(src);
+  }
+  
+  public PreprocessorInfoChannel getPreprocessorInfoChannel() 
+  {
+    return preprocessorInfoChannel;
+  }
+
+  public void setPreprocessingDirective(String pre)
+  {
+    preprocessorInfoChannel.addLineForTokenNumber( pre, new Integer(tokenNumber) );
+  }
+  
+  protected Token makeToken(int t)
+  {
+    if ( t != Token.SKIP && countingTokens) {
+        tokenNumber++;
+    }
+    CToken tok = (CToken) super.makeToken(t);
+    tok.setLine(lineObject.line);
+    tok.setSource(lineObject.source);
+    tok.setTokenNumber(tokenNumber);
+
+    lineObject.line += deferredLineCount;
+    deferredLineCount = 0;
+    return tok;
+  }
+
+    public void deferredNewline() { 
+        deferredLineCount++;
+    }
+
+    public void newline() { 
+        lineObject.newline();
+    }
+
+
+
+
+
+
+}
+
+protected
+Vocabulary
+        :       '\3'..'\377'
+        ;
+
+
+/* Operators: */
+
+ASSIGN          : '=' ;
+COLON           : ':' ;
+COMMA           : ',' ;
+QUESTION        : '?' ;
+SEMI            : ';' ;
+PTR             : "->" ;
+
+
+// DOT & VARARGS are commented out since they are generated as part of
+// the Number rule below due to some bizarre lexical ambiguity shme.
+
+// DOT  :       '.' ;
+protected
+DOT:;
+
+// VARARGS      : "..." ;
+protected
+VARARGS:;
+
+
+LPAREN          : '(' ;
+RPAREN          : ')' ;
+LBRACKET        : '[' ;
+RBRACKET        : ']' ;
+LCURLY          : '{' ;
+RCURLY          : '}' ;
+
+EQUAL           : "==" ;
+NOT_EQUAL       : "!=" ;
+LTE             : "<=" ;
+LT              : "<" ;
+GTE             : ">=" ;
+GT              : ">" ;
+
+DIV             : '/' ;
+DIV_ASSIGN      : "/=" ;
+PLUS            : '+' ;
+PLUS_ASSIGN     : "+=" ;
+INC             : "++" ;
+MINUS           : '-' ;
+MINUS_ASSIGN    : "-=" ;
+DEC             : "--" ;
+STAR            : '*' ;
+STAR_ASSIGN     : "*=" ;
+MOD             : '%' ;
+MOD_ASSIGN      : "%=" ;
+RSHIFT          : ">>" ;
+RSHIFT_ASSIGN   : ">>=" ;
+LSHIFT          : "<<" ;
+LSHIFT_ASSIGN   : "<<=" ;
+
+LAND            : "&&" ;
+LNOT            : '!' ;
+LOR             : "||" ;
+
+BAND            : '&' ;
+BAND_ASSIGN     : "&=" ;
+BNOT            : '~' ;
+BOR             : '|' ;
+BOR_ASSIGN      : "|=" ;
+BXOR            : '^' ;
+BXOR_ASSIGN     : "^=" ;
+
+
+Whitespace
+        :       ( ( '\003'..'\010' | '\t' | '\013' | '\f' | '\016'.. '\037' | '\177'..'\377' | ' ' )
+                | "\r\n"                { newline(); }
+                | ( '\n' | '\r' )       { newline(); }
+                )                       { _ttype = Token.SKIP;  }
+        ;
+
+
+Comment
+        :       "/*"
+                ( { LA(2) != '/' }? '*'
+                | "\r\n"                { deferredNewline(); }
+                | ( '\r' | '\n' )       { deferredNewline();    }
+                | ~( '*'| '\r' | '\n' )
+                )*
+                "*/"                    { _ttype = Token.SKIP;  
+                                        }
+        ;
+
+
+CPPComment
+        :
+                "//" ( ~('\n') )* 
+                        {
+                        _ttype = Token.SKIP;
+                        }
+        ;
+
+PREPROC_DIRECTIVE
+options {
+  paraphrase = "a line directive";
+}
+
+        :
+        '#'
+        ( ( "line" || (( ' ' | '\t' | '\014')+ '0'..'9')) => LineDirective      
+            | (~'\n')*                                  { setPreprocessingDirective(getText()); }
+        )
+                {  
+                    _ttype = Token.SKIP;
+                }
+        ;
+
+protected  Space:
+        ( ' ' | '\t' | '\014')
+        ;
+
+protected LineDirective
+{
+        boolean oldCountingTokens = countingTokens;
+        countingTokens = false;
+}
+:
+                {
+                        lineObject = new LineObject();
+                        deferredLineCount = 0;
+                }
+        ("line")?  //this would be for if the directive started "#line", but not there for GNU directives
+        (Space)+
+        n:Number { lineObject.setLine(Integer.parseInt(n.getText())); } 
+        (Space)+
+        (       fn:StringLiteral {  try { 
+                                          lineObject.setSource(fn.getText().substring(1,fn.getText().length()-1)); 
+                                    } 
+                                    catch (StringIndexOutOfBoundsException e) { /*not possible*/ } 
+                                 }
+                | fi:ID { lineObject.setSource(fi.getText()); }
+        )?
+        (Space)*
+        ("1"            { lineObject.setEnteringFile(true); } )?
+        (Space)*
+        ("2"            { lineObject.setReturningToFile(true); } )?
+        (Space)*
+        ("3"            { lineObject.setSystemHeader(true); } )?
+        (Space)*
+        ("4"            { lineObject.setTreatAsC(true); } )?
+        (~('\r' | '\n'))*
+        ("\r\n" | "\r" | "\n")
+                {
+                        preprocessorInfoChannel.addLineForTokenNumber(new LineObject(lineObject), new Integer(tokenNumber));
+                        countingTokens = oldCountingTokens;
+                }
+        ;
+
+
+
+/* Literals: */
+
+/*
+ * Note that we do NOT handle tri-graphs nor multi-byte sequences.
+ */
+
+
+/*
+ * Note that we can't have empty character constants (even though we
+ * can have empty strings :-).
+ */
+CharLiteral
+        :       '\'' ( Escape | ~( '\'' ) ) '\''
+        ;
+
+
+/*
+ * Can't have raw imbedded newlines in string constants.  Strict reading of
+ * the standard gives odd dichotomy between newlines & carriage returns.
+ * Go figure.
+ */
+StringLiteral
+        :       '"'
+                ( Escape
+                | ( 
+                    '\r'        { deferredNewline(); }
+                  | '\n'        {
+                                deferredNewline();
+                                _ttype = BadStringLiteral;
+                                }
+                  | '\\' '\n'   {
+                                deferredNewline();
+                                }
+                  )
+                | ~( '"' | '\r' | '\n' | '\\' )
+                )*
+                '"'
+        ;
+
+
+protected BadStringLiteral
+        :       // Imaginary token.
+        ;
+
+
+/*
+ * Handle the various escape sequences.
+ *
+ * Note carefully that these numeric escape *sequences* are *not* of the
+ * same form as the C language numeric *constants*.
+ *
+ * There is no such thing as a binary numeric escape sequence.
+ *
+ * Octal escape sequences are either 1, 2, or 3 octal digits exactly.
+ *
+ * There is no such thing as a decimal escape sequence.
+ *
+ * Hexadecimal escape sequences are begun with a leading \x and continue
+ * until a non-hexadecimal character is found.
+ *
+ * No real handling of tri-graph sequences, yet.
+ */
+
+protected
+Escape  
+        :       '\\'
+                ( options{warnWhenFollowAmbig=false;}:
+                  'a'
+                | 'b'
+                | 'f'
+                | 'n'
+                | 'r'
+                | 't'
+                | 'v'
+                | '"'
+                | '\''
+                | '\\'
+                | '?'
+                | ('0'..'3') ( options{warnWhenFollowAmbig=false;}: Digit ( options{warnWhenFollowAmbig=false;}: Digit )? )?
+                | ('4'..'7') ( options{warnWhenFollowAmbig=false;}: Digit )?
+                | 'x' ( options{warnWhenFollowAmbig=false;}: Digit | 'a'..'f' | 'A'..'F' )+
+                )
+        ;
+
+
+/* Numeric Constants: */
+
+protected
+Digit
+        :       '0'..'9'
+        ;
+
+protected
+LongSuffix
+        :       'l'
+        |       'L'
+        ;
+
+protected
+UnsignedSuffix
+        :       'u'
+        |       'U'
+        ;
+
+protected
+FloatSuffix
+        :       'f'
+        |       'F'
+        ;
+
+protected
+Exponent
+        :       ( 'e' | 'E' ) ( '+' | '-' )? ( Digit )+
+        ;
+
+
+protected
+DoubleDoubleConst:;
+
+protected
+FloatDoubleConst:;
+
+protected
+LongDoubleConst:;
+
+protected
+IntOctalConst:;
+
+protected
+LongOctalConst:;
+
+protected
+UnsignedOctalConst:;
+
+protected
+IntIntConst:;
+
+protected
+LongIntConst:;
+
+protected
+UnsignedIntConst:;
+
+protected
+IntHexConst:;
+
+protected
+LongHexConst:;
+
+protected
+UnsignedHexConst:;
+
+
+
+
+Number
+        :       ( ( Digit )+ ( '.' | 'e' | 'E' ) )=> ( Digit )+
+                ( '.' ( Digit )* ( Exponent )?
+                | Exponent
+                )                       { _ttype = DoubleDoubleConst;   }
+                ( FloatSuffix           { _ttype = FloatDoubleConst;    }
+                | LongSuffix            { _ttype = LongDoubleConst;     }
+                )?
+
+        |       ( "..." )=> "..."       { _ttype = VARARGS;     }
+
+        |       '.'                     { _ttype = DOT; }
+                ( ( Digit )+ ( Exponent )?
+                                        { _ttype = DoubleDoubleConst;   }
+                  ( FloatSuffix         { _ttype = FloatDoubleConst;    }
+                  | LongSuffix          { _ttype = LongDoubleConst;     }
+                  )?
+                )?
+
+        |       '0' ( '0'..'7' )*       { _ttype = IntOctalConst;       }
+                ( LongSuffix            { _ttype = LongOctalConst;      }
+                | UnsignedSuffix        { _ttype = UnsignedOctalConst;  }
+                )?
+
+        |       '1'..'9' ( Digit )*     { _ttype = IntIntConst;         }
+                ( LongSuffix            { _ttype = LongIntConst;        }
+                | UnsignedSuffix        { _ttype = UnsignedIntConst;    }
+                )?
+
+        |       '0' ( 'x' | 'X' ) ( 'a'..'f' | 'A'..'F' | Digit )+
+                                        { _ttype = IntHexConst;         }
+                ( LongSuffix            { _ttype = LongHexConst;        }
+                | UnsignedSuffix        { _ttype = UnsignedHexConst;    }
+                )?
+        ;
+
+
+ID
+        options 
+                {
+                testLiterals = true; 
+                }
+        :       ( 'a'..'z' | 'A'..'Z' | '_' )
+                ( 'a'..'z' | 'A'..'Z' | '_' | '0'..'9' )*
+        ;
+
+



Re: svn commit: r446601 [2/3] - in /maven/plugins/trunk/maven-antlr-plugin: ./ src/main/java/org/apache/maven/plugin/antlr/ src/main/mdo/ src/site/ src/site/apt/ src/site/apt/examples/ src/site/fml/ src/test/java/org/apache/maven/plugin/antlr/ src/test/res...

Posted by Brett Porter <br...@apache.org>.
Is this really appropriately licensed to include, even though its in  
a test case?

On 15/09/2006, at 11:05 PM, vsiveton@apache.org wrote:

> Added: maven/plugins/trunk/maven-antlr-plugin/src/test/resources/ 
> unit/java-grammar-inheritance-test/src/main/antlr/GnuCParser.g
> URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antlr- 
> plugin/src/test/resources/unit/java-grammar-inheritance-test/src/ 
> main/antlr/GnuCParser.g?view=auto&rev=446601
> ====================================================================== 
> ========
> --- maven/plugins/trunk/maven-antlr-plugin/src/test/resources/unit/ 
> java-grammar-inheritance-test/src/main/antlr/GnuCParser.g (added)
> +++ maven/plugins/trunk/maven-antlr-plugin/src/test/resources/unit/ 
> java-grammar-inheritance-test/src/main/antlr/GnuCParser.g Fri Sep  
> 15 06:05:57 2006
> @@ -0,0 +1,850 @@
> +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
> %%%
> +
> +        Copyright (c) Non, Inc. 1998 -- All Rights Reserved
> +
> +PROJECT:        C Compiler
> +MODULE:         GnuCParser
> +FILE:           GnuCParser.g
> +
> +AUTHOR:         Monty Zukowski (jamz@cdsnet.net) April 28, 1998
> +
> +DESCRIPTION:
> +                This is a grammar for the GNU C compiler.  It is a
> +                grammar subclass of StdCParser, overriding only those
> +                rules which are different from Standard C.
> +
> +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
> %*/
> +

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org