[antlr-interest] Parsing beginners question

jenlhunt2003 steam at tapisinc.com
Tue Jan 27 22:54:16 PST 2004


Hi,
Sorry to bother you with what will undoubtably turn out to be a dumb question, but I'm not closing in on the problem so thought I'd ask.

I'm trying to get the cgram (the 'C' grammer) code to run in CPP mode.  For now I am only building the StdCParser.g file 
which I modified by commenting out all Java code, changing the options and header files etc.  It builds okay (I think)
under VC6.0 and kind of runs (it accepts an input file and displays errors).

If the input file is:

double i;
int j;

int main(int argc, char **argv)
	{
	i = j + 3;
	}

it doesn't like it, giving this error:
unexpected token: double

In trying to debug the code I find that it drops down through:
translationUnit,
externalList,
and gets to externalDef where it fails here:

	try {      // for error handling
	if ((_tokenSet_2.member(LA(1))) && (_tokenSet_3.member(LA(2)))) {
		declaration();
		if (inputState->guessing==0) {
		astFactory->addASTChild( currentAST, returnAST );
		}
	externalDef_AST = currentAST.root;

It never drops down into declaration.  Somehow _tokenSet_3.member(LA(2)))) winds up being false.  
I've checked the incoming token stream from StdCLexer.cpp and it seems like what I would expect,
but somehow this code in StdCParser.cpp seems to be getting the wrong tokens, or something.

Incidently, I replaced ": ("typedef" | declaration)=> declaration" with simply "declaration", thinking the problem 
might be there so the parser code in part is:

translationUnit
        :       externalList

        |       /* Empty source files are *not* allowed.  */
                {
                //System.err.println ( "Empty source file!" );
                }
        ;

externalList
        :       ( externalDef )+
        ;

externalDef
/*        :       ( "typedef" | declaration )=> declaration */
		: declaration
        |       functionDef
        |       asm_expr
        ;

I know that cgram (in Java mode) has been thoroughly checked out, so I've done something wrong. 

Thank you in advance for any help,

Henry




 

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