[antlr-interest] Howto #include other files while parsing?

siemsen at ucar.edu siemsen at ucar.edu
Tue Apr 15 22:16:44 PDT 2008


I have a grammar that does this, using the method described on the  
ANTLR Wiki at

     http://www.antlr.org/wiki/pages/viewpage.action?pageId=557057

-- Pete


On Apr 15, 2008, at 9:46 PM, Peter Nann wrote:

>
> Well, I was about to tackle that problem any day now, so look  
> forward to
> your solution!
> (Or, surely there is a standard solution to this...)
>
> Are you writing it in Java?
> Any chance you could flick your code to me once it's working?
> ;-) I'd owe you one...
>
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of John Woods
> Sent: Wednesday, 16 April 2008 1:20 PM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Howto #include other files while parsing?
>
> I'm creating a parser for a file format which has a #include statement
> much like the C preprocessor. The solution I'm thinking of would  
> involve
> creating an InputStream subclass that reads from one file, then when  
> the
> parser parses a #include statement, the parser tells the InputStream  
> to
> switch to reading the #included file, and when that file is exhausted,
> the InputStream pops back to the previous file, continuing reading  
> where
> it left off -- immediately after the #include statement.
>
> Is there any guarantee that the lexer won't read past the #include
> statement when it is parsed? Because if it did read ahead, then the
> #included file would essentially be "inserted" at the wrong position  
> in
> the InputStream.
>
> Is there a better way to approach this problem?
>
> Thanks.



More information about the antlr-interest mailing list