[antlr-interest] Parsing beginners question

mzukowski at yci.com mzukowski at yci.com
Wed Jan 28 09:20:23 PST 2004


You can use the option codeGenBitsetTestThreshold = 999999; in order to turn
off the bitset generation and be able to see the actual tokens it is trying
to match.  Also, have you run it through antlr with the -trace option?  That
could help with debugging too.

Actually you do need that syntactic predicate ": ("typedef" | declaration)=>
declaration".  The parser doesn't know if it is looking at a declaration or
definition until it sees the semicolon which can be very far (undefined,
unbounded length) into the file.

Monty

-----Original Message-----
From: jenlhunt2003 [mailto:steam at tapisinc.com] 
Sent: Tuesday, January 27, 2004 10:54 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Parsing beginners question

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/ 


 

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