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

Sameh W. Zaky sameh.wz at gmail.com
Sat May 22 11:34:42 PDT 2010


Dear Brat,

You're right..

But now I need to change my question because I found out that Parser.java
generated from this action is different than Parser.java generated when I
click 'Run..' in ANTLRWorks and give it an input text..

So my new question is: How, from the command line, do I run the grammar
(giving it an input text file, let's say)?

On Sat, May 22, 2010 at 1:54 PM, Bart Kiers <bkiers at gmail.com> wrote:

> 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.
> **
>



-- 
Sameh W. Zaky


More information about the antlr-interest mailing list