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

JonFroehlich jfroehli at ics.uci.edu
Sun Jul 25 10:02:43 PDT 2004


Ack, I was afraid of that. I wonder if there are any other 
approaches/altneratives I may pursue.

Basically what I am trying to do is parse C code (or C++ code, but 
let's stick with C for now) and create, for example, a tree-explorer 
view of the code like one might find in an IDE. The explorer view 
would list the .c "global" declarations for each file as well as its 
functions. This is only one example of what I plan to do, but I 
think it illustrates my main motivation -- nothing too complicated 
here (at least I don't think so).

I use Terence Parr's "Java parser and tree parser" to support Java 
parsing for exactly this same functionality and it seems to work 
great.

Any feedback would be much appreciated!

Thanks for the responses so far,

j

--- In antlr-interest at yahoogroups.com, Monty Zukowski <monty at c...> 
wrote:
> Exactly.
> 
> Monty
> 
> On Jul 25, 2004, at 3:08 AM, lgcraymer wrote:
> 
> > 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
> >
> >
> >
> >
> >
> >
> >



 
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