[antlr-interest] Re: Please - can someone help me out?
Geir Ove Skjaervik
geiroves at online.no
Sun Nov 7 11:42:42 PST 2004
Hello,
and thanks for the clarifying answers! I see what you mean by
unsolved references problem: I think I did a two pass in my hand
coded parser: Thus, I will probably be better of Walking the Tree
(line :-)). And as you say; I get the conext info for "free" which
can be usefull for the debugger.
The next thing I would love to get my hands on, is this: An ANTLR
example aka. the Calc example, but that also adds: function
definition and function call AND walks a tree to execute the stuff.
The problem with the provided examples like TinyBasic is that it is
to big, to much to grasp. A very simple example makes it easier to
grasp the principle and get flying. I am currently reading the ANTLR
Reference Manual, but that is a time consuming feat....
Geir Ove
--- In antlr-interest at yahoogroups.com, "John D. Mitchell" <johnm-
antlr at n...> wrote:
> >>>>> "Geir" == Geir Ove Skjaervik <geiroves at o...> 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