[antlr-interest] Re: Please Help: Simple C Parsing Problem

lgcraymer lgc at mail1.jpl.nasa.gov
Sun Jul 25 03:08:32 PDT 2004


Monty will probably have something to say, but if I remember
correctly, the GNU C grammar has no preprocessor support.  You need to
run cpp over the input file before sending it through the C processor.

--Loring


--- In antlr-interest at yahoogroups.com, "JonFroehlich" <jfroehli at i...>
wrote:
> I'm using the John Mitchell and Monty Zukowski GNU C Grammar from 
> antlr.org. I can run the test input .c files fine; however, when I 
> create my own simple tests, the parser fails.
> 
> For example, testfile.c contains two lines
> 
> #include <stdio.h>
> FILE *filePtr;
> 
> When I parse this, I get the following error:
> 
> ANTLR Parsing Error: line 2:26: unexpected token: * token name:STAR
> line 2:26: unexpected token: *
> 	at GnuCParser.initDecl(GnuCParser.java:3454)
> 	at GnuCParser.initDeclList(GnuCParser.java:1107)
> 	at GnuCParser.typelessDeclaration(GnuCParser.java:832)
> 	at GnuCParser.externalDef(GnuCParser.java:496)
> 	at GnuCParser.externalList(GnuCParser.java:233)
> 	at GnuCParser.translationUnit(GnuCParser.java:193)
> 	at Test.main(Test.java:55)
> 
> 
> So, I realize the issue revolves around the notion of "typeless 
> declaration." E.g. if we change testfile.c to read the following, 
> there is no problem.
> 
> #include <stdio.h>
> int *filePtr;
> 
> How do I change the grammar file (if this is even necessary) to be 
> able to detect new types so that a non-primitive type variable 
> declaration, like FILE, is treated the same way as an int 
> declaration.  This seems like such an easy thing but unfortunately I 
> can't figure it out.
> 
> j



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list