revLISP (actually is scheme...) Some doubts on implementation.

Andre Garzia soapdog at mac.com
Fri Mar 26 00:32:06 EST 2004


Hi Dar,

It's trickier than I first thought. Once while coursing engineering I 
implemented a Scheme interpreter in Scheme, that was like cheating, 
scheme knows how to parse itself, implementing some scheme-like thing 
in Rev is a brand new thing.

First I am trying to work the parser out. It's harder than I thought. I 
am looping the string with many functions searching it. My first design 
is to parse it all to a nice table, I am parsing from outtermost 
expression to innermost expression, I wanted to do different, to parse 
and evaluate from inner expression to outter, but didn't know how to do 
it, so I'll parse from top to bottom, then evaluate from bottom to 
up...  My trick is to go parsing, found something put it in the symbol 
table, found a right parenthesis, evaluate that list. Since the first 
right parenthesis should always tag us that we can finally try to 
evaluate something. The parser is almost character by character based, 
meaning, it looks for the first char in a string, if it's a char then 
it passes the expression to a handler that will extract that word and 
create the symbol, if it is a number the same but with a number been 
created in the symbol table, if its a parenthesis tag the damn thing 
for latter organization, yes there's a problem with '() construct, but 
that's easily solved.

Your old box prime is here by my side, and it's aiding me very much, 
almost all programs I make use it. The thing I am trying to solve now 
is the matching parenthesis issue, I don't know if I try to solve it in 
the parser, or parse everything to a table and allow the evaluation 
function to handle everything. For now it's like, supposed you have 
this code:

(+ 1000 1)

this is parsed to the following table:
#lp
+
1000
1
#rp

where #lp and #rp are used for parenthesis identification and thus 
ilegal to use in the code. I thought to work like this, everytime 
create_symbol function is called with an #rp value, it will go poping 
the stack/table and evaluating it till find a #lp entry. This way, when 
the ) is parsed and #rp is sent to create_symbol, it will first pop '1' 
and since it's nothing but a number it will put in the stack, then it 
will pop '1000' and to the same, then it will pop '+' this is a 
predicate, that evaluate the first to things in the stack, this will 
execute. and be put in the stack, when reaching a #lp entry, the first 
thing in the stack will be inserted in the symbol table. Is this clear? 
Is this a nice approach?

Am I the first one to try to implement a language in Rev? =)

Cheers



-- 
Andre Alves Garzia ð 2004 ð BRAZIL
http://studio.soapdog.org



More information about the use-livecode mailing list