Related articles |
---|
Smalltalk 'cascades' Timothy_S_Coffey@mail.bankone.com (2000-05-18) |
Re: Smalltalk 'cascades' bonzini@gnu.org (2000-05-20) |
From: | bonzini@gnu.org |
Newsgroups: | comp.compilers |
Date: | 20 May 2000 13:20:22 -0400 |
Organization: | Mailgate.ORG Server - http://www.Mailgate.ORG |
Keywords: | parse, smalltalk |
Mail-From: | sci0627@ccrd200.cdc.polimi.it at ccrd200.cdc.polimi.it [131.175.6.2] |
>I was wondering if anyone knows if it is possible to construct a parse
>table for 'cascades' in Smalltalk.
Yes it is. I don't remember the exact rules, but they are in GNU
Smalltalk's lib/gst.y file (get it from ftp.gnu.org/gnu/smalltalk).
The real problem is generating the code, as you pointed out. GNU
Smalltalk uses a hack that tells some other parts of the parse tree walker
to generate `dup stack top' bytecodes. An example of the generated
bytecodes is (to the right is a snapshot of the stack):
receiver rec
dup stack top rec rec
first message send rec result
pop stack top rec
dup stack top rec rec
second message send rec result
pop stack top rec
...
dup stack top rec rec
(n-1)th message send rec result
pop stack top rec
n-th message send rec result
You might create a bytecode combining pop & dup (what was it called in
Forth?). <ADVERTISING> BTW GNU Smalltalk also includes a peephole
optimizer for bytecodes and alpha versions include a (not working yet)
bytecode-to-something-resembling-a-parse-tree converter to be used by the
just in time compiler to native code. </ADVERTISING>
The easiest solution is to use a different parse node type: a `cascade
node' which contains a receiver and a list of `message send node' parse
nodes. This is done by GNU Smalltalk's Smalltalk-in-Smalltalk compiler
(that is the compiler written in Smalltalk -- the above referred to the
compiler written in C). That compiler, though, uses a recursive descent
parser (manually written) rather than a bison bottom-up parser.
Paolo Bonzini
Return to the
comp.compilers page.
Search the
comp.compilers archives again.