Tutorial :ANTLRv3: Setting a custom Lexer and Parser Class names


Is there a way to specify custom class name (meaning independent of the grammar name) for the ANTLRv3 generated Parser and Lexer classes?

So in the case of

grammar MDD;    //other stufff  

Automatically it would crate MDDParser and MDDLexer, but I would like to have them as MDDBaseParser and MDDLexer.


No, in a combined grammar like MDD, the parser and lexer are named MDDParser and MDDLexer. A combined grammar is a grammar where you don't specify the type (parser or lexer).

You could define a separate parser- and lexer-grammar:

// put this in a file called MDDBaseParser.g  parser grammar MDDBaseParser;    parse    :  Token+    ;  


// put this in a file called MDDLexer.g  lexer grammar MDDLexer;    Token    :  'a'..'z'    ;  

Now both the parser and lexer source files will get the same name as their grammar file.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »