[antlr-interest] #include handling - newbie question
Ric Klaren
klaren at cs.utwente.nl
Thu Jul 15 08:10:19 PDT 2004
On Wed, Jul 14, 2004 at 04:47:16PM -0000, Bill Clark wrote:
> I'm looking for tips on the simplest way to handle #include
> directives in a file to be parsed by ANTLR. I've seen the advice
> that it's not a problem that ANTLR is well-suited to solve, but I'm
> not sure what's the best way to go about this. I can easily write a
> preprocessor that just inserts the contents of the included file in
> the stream that's handed to the lexer, but then I don't see a good
> way to provide line numbers/filenames in error messages.
>
> It seems like there ought to be a simple way to deal with this
> general problem; am I missing it?
You might get some inspiration from this code:
http://wwwhome.cs.utwente.nl/~klaren/antlr/CPPParser.tar.bz2
It's a modification of the C++ parser from David Wigg. It adds custom
tokens with file names and rudimentary #include handling inclusive include
guards. (it was a bit of an experiment the code is rough be sure to read
the readme coming with it) One extra step that could be added is custom
ast's with file/line info. The includeFile C++ example Monty mentioned is a
lot simpler though if you're new to antlr.
Cheers,
Ric
--
-----+++++*****************************************************+++++++++-------
---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893755 ----
-----+++++*****************************************************+++++++++-------
"Don't call me stupid." "Oh, right. To call you stupid would be an insult
to stupid people. I've known sheep that could outwit you! I've worn
dresses with higher IQs!" --- A Fish Called Wanda
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list