[antlr-interest] Which approach for an Interpreter: Tree Grammar vs AST-Visitor

bill punch punch at cse.msu.edu
Wed Feb 2 17:36:38 PST 2011


I'm designing a project for my compiler class, and we are at the stage
of building an interpreter for our grammar. Before going farther, let me
say first that ANTLR is great and makes the whole process a lot easier.
However, I'm converting the course and, being new to ANTLR, have a few
questions. Here is one.

I was using Pattern 25, the Pie language,  from LIP as a guideline, but
I'm a little confused about the best approach. Pattern 25, Pie,
constructs an AST then uses hand-written code to do the visiting. I like
the approach, as more complex code can be embedded in the visitor code.
However, instead of writing my own visitor, I could have the students
write a tree grammar to visit the AST nodes. But it seems that I would
still be better off putting the exec type code in a separate file.

So would it be better to have an example like the Pie language use a
tree grammar or is the hand-written visitor code a better approach? What
are the pros and cons? Any help appreciated.

-- 
      >>>bill<<<



More information about the antlr-interest mailing list