[antlr-interest] Article against TreeWalkers

Andy Tripp antlr at jazillian.com
Fri Mar 10 10:03:43 PST 2006

Right, sorry, this discussion is off track onto switches vs. interfaces 
and the Strategy pattern.
Has nothing to do with treewalkers, and I didn't mean to imply anything 
about what Terence
might think on switch statements vs. interfaces.

Terence Parr wrote:

> On Mar 10, 2006, at 9:21 AM, Andy Tripp wrote:
>> Anthony Youngman wrote:
>> Design Patterns book...Strategy p315....read through the mumbo  
>> jumbo...OK, I got it, a big switch
>> statement can be hard to maintain when things get complicated, so  
>> you could create an interface,
>> many classes that each implement the interface and then each do  
>> their own thing rather than you doing it
>> all for them in a big switch.
> hi, everybody!  Actually, I don't do that.  I create methods, one for  
> each rule and switch on the lookahead to jump to the rule...not a big  
> fan of lots of classes to do this for me--this is why I build tree  
> recognizers not hand-built heterogeneous classes just to switch on  
> token type.  Seems people are getting all sorts of stuff  
> confused...got no time to clarify my position (hands still out of  
> action too).
>> OK, that all sounds fine, but things aren't that complicated here.  Each
>> switch case is quite trivial. Not worth it to get fancy here. I'll  
>> keep my big switch as is, and now add
>> Strategy to my list of Design Patterns that I think I understand :)
> Don't forget that lookahead computation is complicated by hand and in  
> my experience people get it wrong.  Grammars allow automatic  
> computation and more importantly warnings when you have specified  
> something that would by hand go unnoticed.  Lookahead can change in  
> one spot from changes elsewhere in the grammar you'll recall.  Do we  
> really need to have the handbuilt parser vs grammar discussion in  
> this group?  Perhaps we're not talking about parsing anymore...just  
> coding.  if so, please move random coding discussions off the  
> list...thanks!
> Terence "if grammars are good enough for tokens, they're good enough  
> for tree nodes" Parr

More information about the antlr-interest mailing list