dcsimg
Behaviour in tree walkers (applying the visitor pattern)
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jeremy_Laycock
Posted On:   Monday, August 4, 2003 12:35 PM

I currently have a hand crafted recursive descent parser (written in Java) of a relatively simple language. The parser generates a heterogeneous AST with a set of associated behaviours captured as visitors. Without going into too much detail and to simplify there is a printVisitor and a doSomethingVisitor. My hand crafted AST has a simple visit method per node which knows which actual visit method call on the associated Visitor. The hard work and effective tree walking is done by the specific Visitor implementation.. The question is how best can I capture this behaviour using Antlr.. I could A) use Antlr to parse my language and generate a tree using my AST classes (after I've made them use BaiscAST) and so simply re-use the Visitors. or B) Have the tree parser ac   More>>

I currently have a hand crafted recursive descent parser (written in Java) of a relatively simple language. The parser generates a heterogeneous AST with a set of associated behaviours captured as visitors. Without going into too much detail and to simplify there is a printVisitor and a doSomethingVisitor. My hand crafted AST has a simple visit method per node which knows which actual visit method call on the associated Visitor. The hard work and effective tree walking is done by the specific Visitor implementation.. The question is how best can I capture this behaviour using Antlr.. I could A) use Antlr to parse my language and generate a tree using my AST classes (after I've made them use BaiscAST) and so simply re-use the Visitors. or B) Have the tree parser act "like" a Visitor and effectively initialise it with a behaviour and get each node to call behaviour.dostuff() changing the behaviour class for each Visitor...

Any suggestions welcome, examples would be nice :-)

Cheers

Jezza

   <<Less
About | Sitemap | Contact