[antlr-interest] Implementing "include" functionality with C runtime

Cameron Esfahani dirty at apple.com
Mon Jun 18 19:38:20 PDT 2007


It looks like I need to switch the input in the token factory as  
well.  I added the following code to switch the token factory input  
to the new input and things look better:

			gLexer->pLexer->tokFactory->unTruc.input = SavedStream;

Of course, I'd love it if someone with some C runtime background  
could tell me if I'm doing incredibly rude and outrageous things to it.

And all without buying it dinner and drinks.

On Jun 18, 2007, at 6:54 PM, Cameron Esfahani wrote:

> When I was prototyping with the Java runtime, I had implemented the  
> "include" functionality based on code from the wiki:
>
> http://www.antlr.org/wiki/pages/viewpage.action?pageId=557057
>
> And this worked great.
>
> Now that I've switched over to the C runtime, I'm having some  
> trouble porting the above solution over.
>
> I've hooked into the nextToken() vector of the lexer's token  
> source, and I set up a simple stack to save and restore the pLexer- 
> >input ANTLR3_INPUT_STREAM.
>
> I make sure to call mark() on the current ANTLR3_INPUT_STREAM so  
> when it gets switched back in by the nextToken() override, I can  
> just call rewindLast() on it.
>
> The problem is at the end of the parsing, when I'm dumping out the  
> AST.  The text from included file isn't there.  In fact, the  
> original "include" string is there.  It seems to me that the C  
> runtime doesn't like how I've swapped out one stream for another.
>
> Is there some cached state I need to reset?
>

Cameron Esfahani
dirty at apple.com

"There are times in the life of a nation when the only place a decent  
man can find himself is in prison."



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070618/56c619d8/attachment-0001.html 


More information about the antlr-interest mailing list