[antlr-interest] Java Target - How to Generate the Parser and Lexer at Runtime?

Bart Kiers bkiers at gmail.com
Sat May 22 04:54:41 PDT 2010


On Sat, May 22, 2010 at 1:33 PM, Sameh W. Zaky <sameh.wz at gmail.com> wrote:

> Greetings,
>
> I am still an ANTLR beginner..
>
> I run a software where I generate the .g grammar file automatically. So I
> would love to know how to generate the lexer and parser at runtime given
> the
> .g file?
>

When generating lexers/parser on the command line, you'd do something like
this:

java -cp .:antlr-3.2.jar org.antlr.Tool /path/to/your/grammar.g

(the Tool class has a static main method taking a command line parameter!)
So generating them in your own code would look like:

String yourGrammarFile = "/path/to/your/grammar.g";
org.antlr.Tool.main(new String[]{yourGrammarFile});

Kind regards,

Bart.
**


More information about the antlr-interest mailing list