[antlr-interest] Problem using code from ANTLR 3 FAQ How do I implement include files?
Rob Finneran
robfinneran at gmail.com
Sat Oct 6 14:35:16 PDT 2007
Hi Gavin,
Thanks for the reply. You are correct.
I'm not actually parsing C# files. I don't have a name for my language yet.
I want to build a translator that traverses my project directory
structure based on the "using DirName1.DirName2;" and includes these
files into a single character input or token stream. This allows me
to physically separate my source code files and still process the
individual files as if they were a single file. Without this mechanism
I would have undefined types and symbols.
Additionally I would might want to exclude files from being processed:
using MyProject.Ecommerce exclude types Order, LineItem;
Not sure why I would want to do this because I would like the
translator to figure out what types are needed to be included
automatically.
I have not had time to look at the ANTLR code too closely. There must
be some class I can inherit from such as TokenStream or something.
Maybe I can have multiple lexer instances that create a single token
stream into a single parser. I'm not sure I like too much Java code in
my grammar file anyways. There must be a way to do this.
As a temporary solution I'm working on a preprocessor that combines
the files into a temporary file which will become the input for the
ANTLR lexer/parser. The preprocessor approach seems a little old
fashioned and probably slows my translator down.
I'm also thinking about having a manifest compiled from each source
file. The manifest would be used for things like reflection and an
easy to process list of symbol dependencies. I could then load
manifest files into symbol tables before processing the AST tree.
Building your own language is fun. But there sure is a lot of work to do.
Thanks Again!
On 10/6/07, Gavin Lambert <antlr at mirality.co.nz> wrote:
> At 06:46 7/10/2007, Rob Finneran wrote:
> >I have modified someone's code example to enhance the C-style
> >include file example to support reading all include files in
> >a directory in a similar fashion to C# "using" statements.
>
> You know that C# "using" statements are the equivalent of C++
> "using namespace" statements, and don't actually involve including
> any extra code, right? In fact it's perfectly valid to have a C#
> file that refers to symbols in other files/assemblies without a
> single "using" statement ever being used....
>
>
More information about the antlr-interest
mailing list