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

Peter Nann peter.nann at vecommerce.com.au
Tue Apr 15 20:46:37 PDT 2008


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