[antlr-interest] class declaration in grammar file

Safiye Celik safisce at gmail.com
Wed Aug 5 03:00:55 PDT 2009


Hi,
I am using ANTLR v3 with Java. What I want to ask is, when we should write
"class MyParser extends Parser;" statement at the beginning of the .g
grammar, and when we should write "grammar MyGrammar;" instead of that class
statement. I have MyGrammar.g as below:

grammar MyGrammar;
options {}
tokens{}
//and rules here

and when this grammar file is compiled, MyGrammarLexer.java and
MyGrammarParser.java files are automatically generated and I had no problem
till now. But I will add treewalker usage in my grammar file now, and in an
example in v2, "grammar xxx;" is not used and instead, class declaration is
used for xxxLexer, xxxParser and xxxTreeWalker. So, I try to do so, but I
get "unexpected token:class" and some other errors when I comment out
"grammar MyGrammar;" line and write "class MyParser extends Parser;"
instead.
What differs when I write "class MyParser extends Parser;" statement at the
beginning of the grammar? And how can I get rid of the errors I get when I
do so?
-- 
-safiye
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090805/8c0cef5c/attachment.html 


More information about the antlr-interest mailing list