[antlr-interest] Creating a main() for C++ code,
passing params on command line
Bryan Ewbank
ewbank at gmail.com
Sat Apr 15 16:02:29 PDT 2006
Paul D Watson wrote:
>
> It is clearly evident that I am new to antlr. I have searched quite a bit
> through the ANTLR Reference Manual and with Google to find out about how a
> main() is created for antlr generated programs. There are main.cpp and
> Main*.cpp files around in the examples directory. But I am hoping to find
> some reference documentation that will tell what must, or must not, go into a
> main() for antlr generated programs.
Welcome to ANTLR :)
For C++, the main thing you need is to define the necessary factory; the
reference manual, in the section on C++ code, should describe it. Without this
step, your program will crash the first time it tries to create an AST node.
There are several ways to pass information to the ANTLR-generated class
objects; think of it as a normal C++ class, and you should see what I mean.
- class-global (i.e., static) items, to control the behavior of all
instances created.
- as constructor argument, to bind a specific instance of the class
with specific information. for example, you must pass a lexer to the
default constructor for a parser. this requires the most "hacking"
because you need must suppress the normal constructors if they do not
make sense. the end of the reference manual talks about
noDefaultConstructor, I think.
- as arguments to specific productions or member functions that are
defined in the header of the class definition.
Hope this helps; no specific information, but general ideas. Take a look at
the (default) generated code for C++, and you should see that the interface
(the generated *.hpp) is actually not that unusual.
- Bryan Ewbank
More information about the antlr-interest
mailing list