[antlr-interest] Re: Please - can someone help me out?

John D. Mitchell johnm-antlr at non.net
Sun Nov 7 11:18:50 PST 2004


>>>>> "Geir" == Geir Ove Skjaervik <geiroves at online.no> writes:
[...]

> Q1: As for how to use ANTLR to implement a Stack Machine: Couldn't I
> simply emit the stack instructions from the Parser part of ANTLR?
> (That's what I did in the hand coded lexer / parser I wrote). What are
> the benefits of doing it walking an AST tree?

Can you do a purely syntax-directed translation for your language?  E.g.,
the answer is basically "no" if you have unresolved forward references that
you have to fix up.  [Of course, you could have your stack machine
evaluator be more complicated and do the fix-ups for you but that is, in
essence, another pass so you've just moved the problem from one place to
another.]


> I feel pretty comfortable setting up the Lexer and Parser part in ANTLR
> (I think), but the TreeParser part is unfamiliar ground although I think
> I grasp the basics.

> Q2: What would be easier: Implementing a debugger for the Stack Machine
> or the solution where code is executed walking the tree (is this called a
> register machine?)

(A) They are basically equivalent given good engineering (i.e., good
factoring).  The stack evaluator is a bit more localized but the tree
evaluator has the explicit context of the tree.

(B) A register machine is something that looks like a CPU.  I.e., it's
model wherein there are (banks of) registers in which computation takes
place, usually some form of "hardware" supported stack, and general/heap
memory.  GCC's RTL is an example of an intermediate representation (IR)
of a register machine model.

Hope this helps,
		John


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list