[antlr-interest] ANTLR & equals()/Equals() [Re: A way to find all subtrees of a particular type?]
lgcraymer
lgc at mail1.jpl.nasa.gov
Wed May 21 22:05:56 PDT 2003
In other words, you wanted a context-dependent equality for ASTs.
That strikes me as a really bad idea--AST nodes represent elements
in context-free grammars and ANTLR manipulates these as context-free
entities unless the programmer specifies the context dependency via
semantic predicates. The "text and type" approach is much more
natural for the problem domain.
--Loring
--- In antlr-interest at yahoogroups.com, "micheal_jor"
<open.zone at v...> wrote:
> > There is a quick fix. Redefine "equals" in your base AST class
so
> > that some text string--say ""--matches anything.
>
> <SNIP>
>
> Sorry for hijacking this thread but this reminded of one of the
items
> on my ANTLR to-do list (no, seriously):
>
> "Moan about ANTLR's use of equals() in Java/C++ (and Equals() in
C#)."
>
> We recently had a situation where we wished to consider Tokens/AST-
> Nodes equal only if they had the same type, text and came from the
> same file. Simply re-defining equals/Equals for our Token/AST
> subclass would have been the natural approach however, that broke
> many other little bits since ANTLR generated code sometimes
depends
> on it's (re-)definition of equality.
>
> Can we move ANTLR's notion of equality to some other method -
perhaps
> hasSameTypeAndText()/HasSameTypeAndText()- so that equals()/Equals
()
> can once again assume their intended meanings please?
>
> Cheers,
>
> Micheal
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list