[antlr-interest] Howto #include other files while parsing?
John Woods
jqwoods at gmail.com
Tue Apr 15 20:19:58 PDT 2008
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