[antlr-interest] Implementing "include" functionality with Cruntime

Jim Idle jimi at temporal-wave.com
Tue Jun 19 08:44:35 PDT 2007


That is about correct, but I need to look at the implications of it.
Trakc:

 

http://www.antlr.org:8888/browse/ANTLR-144

 

And then I will let you know in the resolution of the bug just what to
do correctly. What you have here though is not terrible and I may just
have a setCharStream 'method' for the token factory. There is not a
token factory in the Java version of course, so it does not come up.
There may be other quirks I have to cater for, but if that works for you
know, just use it as a hack J

 

Please send the money for dinner and drinks, which I will gladly accept
- but I am not that kind of guy.

 

Jim

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Cameron Esfahani
Sent: Monday, June 18, 2007 7:38 PM
To: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Implementing "include" functionality with
Cruntime

 

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
<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/20070619/d1b06f77/attachment.html 


More information about the antlr-interest mailing list