[antlr-interest] Grammar inheritance: clarification needed.

Bharath Sundararaman bharath at starthis.com
Tue Jul 27 10:00:37 PDT 2004


Hi antlers,

Doc/inheritance.html says:

"Rules may be overridden to change their signatures such as their parameters
or return types. ANTLR will generate a warning, however: warning: rule
Derived.a has different signature than Base.a .Because of this ability, the
subgrammars do not actually inherit, in the Java-sense, from the
supergrammar.  Different signatures on the generated methods would prevent
the parser from compiling. "

My understanding is this:
-------------------------
In the super-g, if there is a rule "type : signed_Int PLUS Int;", I can
extend it to "type returns [IntType t;]: signed_Int PLUS Int;" in the sub-g
but if the super-g rule was "type returns [IntType t;]....", I cannot extend
it to "type returns [RealType r;]...". I am raising this question because
the number of different_signature_warnings is too many and I would love to
get rid of them somehow (without creating new rules in the sub-g). 

Should I just ignore the warnings and get on with it?

Thanks!

Bharath.
P.S. If you are using ECLIPSE PLUGIN FOR ANTLR and YOU NEED TO CREATE A
SUBGRAMMAR: RIGHT-CLICK ON GRAMMAR -> PROPERTIES -> ANTLR GRAMMAR OPTIONS
and specify the SUPERGRAMMAR and OUTPUT FOLDER. IT SOUNDS TRIVIAL, BUT I
TRIED TO DO THE SAME WITHIN AN ANT TASK AND WASTED 8 MAN HOURS IN TRYING TO
DEBUG THE PROBLEM.



-----Original Message-----
From: Ric Klaren [mailto:klaren at cs.utwente.nl] 
Sent: Tuesday, July 27, 2004 8:41 AM
To: antlr-interest at yahoogroups.com
Subject: Re: [antlr-interest] Code generation error?


Hi,

On Tue, Jul 27, 2004 at 12:56:40PM -0000, jm_newton wrote:
> STRING : !QUOTE ('a'..'z')* !QUOTE
>        ;

First off I think you intend:

STRING : QUOTE! ('a'..'z')* QUOTE! ;

> which results in the following generated c++ code. Unfourtunately in 
> the middle of that lot is the statement text.setLength(). setLength() 
> is not a valid member function of std::basic_string so compilation 
> fails...

Nevertheless you caught something that's been in the codegen since ages...
congrats :)

The fix is easy though replace the only occurence of
text.setLength(_saveIndex) in CppCodegenerator.java with a
text.erase(_saveIndex) and rebuild antlr.

> I'm not sure if I'm trying to do the impossible with my parser or 
> found a real problem here. Environment: cantlr -> 2.7.4 from WWW site
> antlr-2.7.4

Not the impossible, if rebuilding of antlr is not an option then the (I
hope) corrected rule above does not trigger the bug.

Thanks for the report!

Ric
--
-----+++++*****************************************************+++++++++
-----+++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893755  ----
-----+++++*****************************************************+++++++++
-----+++++-------
  "You can't expect to wield supreme executive power just because some
   watery tot throws a sword at you!"
  --- Monty Python and the Holy Grail



 
Yahoo! Groups Links



 




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list