[antlr-interest] Sample automatic visitor

Scott Stanchfield scott at javadude.com
Thu Sep 29 07:13:46 PDT 2011


Sorry for the delayed reply. I think you've hit the nail on the head with
the sample case (picking out pieces). This is exactly what Eclipse does; it
generates an AST and you create a subclass of ASTVisitor overriding methods
to examine specific stuctures. I've used it a few times in the past for some
simple API analysis tools.

-- Scott
(sent from my droid... please excuse brevity)
On Sep 8, 2011 8:45 PM, "Terence Parr" <parrt at cs.usfca.edu> wrote:
> Hi Scott. Thanks for the feedback. I think you're right. it was bugging me
a little bit too because I split things up compared to a normal visitor, but
I like this listener thingie. so you're cool with ParseTreeWalker? make
sense to me.
>
> Do you have any thoughts on the suitability of these listeners for
building language applications? clearly is not suitable for a lot of things,
perhaps even evaluating expression trees, but it seems like it would be
really easy if you want to pick out all of the declarations from a Java
file, for example.
>
> Ter
> On Sep 8, 2011, at 3:23 PM, Scott Stanchfield wrote:
>
>> Just to be pedantic (as I teach Design Patterns at JHU)... using the word
>> "visitor" here isn't quite correct (per GoF), and is apt to cause
confusion
>> for people who are familiar with the GoF visitor pattern.
>>
>> The TListener and its implementations are actually closer to the role of
>> "visitor" per GoF.
>>
>> I'd recommend renaming what you're calling the "visitor" to "walker" or
>> something similar, and keep the TListener.
>>
>> What you're doing here is much simpler to understand than the GoF visitor
>> pattern and more direct anyway...
>> -- Scott
>>
>> ----------------------------------------
>> Scott Stanchfield
>> http://javadude.com
>>
>>
>> On Thu, Sep 8, 2011 at 5:32 PM, Terence Parr <parrt at cs.usfca.edu> wrote:
>>
>>> Hi, I have a prototype working for the automatic parse tree construction
>>> and automatic visitor generation, which I've described here:
>>>
>>>
>>>
http://www.antlr.org/wiki/display/~admin/2011/09/08/Sample+v4+generated+visitor
>>>
>>> Feedback is very welcome, and now is a good time to speak up ;)
>>>
>>> It makes me a bit nervous to generate 2 extra files from every grammar,
but
>>> I'm guessing it will be one of the most popular ways to use ANTLR. My
goal
>>> is to make ANTLR very easy to use out-of-the-box while still allowing
>>> performance minded experts to get what they need.
>>>
>>> Ter
>>>
>>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>>> Unsubscribe:
>>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>>
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address


More information about the antlr-interest mailing list