Changing back to use a tuple for the parsed s-expression

db4
James Cash 2008-04-27 03:03:49 -04:00
parent 0c10c13e4d
commit a6f25c55fc
2 changed files with 10 additions and 7 deletions

View File

@ -7,7 +7,7 @@ IN: lisp
DEFER: convert-form
: convert-body ( s-exp -- quot )
[ convert-form ] map [ ] [ compose ] reduce ; inline
[ convert-form ] map reverse [ ] [ compose ] reduce ; inline
: convert-if ( s-exp -- quot )
1 tail [ convert-form ] map reverse first3 [ % , , if ] bake ;
@ -18,17 +18,17 @@ DEFER: convert-form
: convert-cond ( s-exp -- quot )
1 tail [ [ convert-body map ] map ] [ % cond ] bake ;
: convert-general-form ( s-exp -- quot )
: convert-general-form ( s-exp -- quot )
unclip swap convert-body [ % , ] bake ;
<PRIVATE
: localize-body ( vars body -- newbody )
[ dup lisp-symbol? [ tuck name>> swap member? [ name>> make-local ] [ ] if ]
[ dup vector? [ localize-body ] [ nip ] if ] if ] with map ; inline
[ dup s-exp? [ body>> localize-body <s-exp> ] [ nip ] if ] if ] with map ;
PRIVATE>
: convert-lambda ( s-exp -- quot )
1 tail unclip reverse [ name>> ] map dup make-locals dup push-locals
first3 -rot nip [ body>> ] bi@ reverse [ name>> ] map dup make-locals dup push-locals
[ swap localize-body convert-body ] dipd pop-locals swap <lambda> ;
: convert-list-form ( s-exp -- quot )
@ -41,7 +41,7 @@ PRIVATE>
} case ] [ drop convert-general-form ] if ;
: convert-form ( lisp-form -- quot )
{ { [ dup vector? ] [ convert-list-form ] }
{ { [ dup s-exp? ] [ body>> convert-list-form ] }
[ [ , ] [ ] make ]
} cond ;

View File

@ -6,6 +6,9 @@ IN: lisp.parser
TUPLE: lisp-symbol name ;
C: <lisp-symbol> lisp-symbol
TUPLE: s-exp body ;
C: <s-exp> s-exp
EBNF: lisp-expr
_ = (" " | "\t" | "\n")*
LPAREN = "("
@ -29,5 +32,5 @@ atom = number
| identifier
| string
list-item = _ (atom|s-expression) _ => [[ second ]]
s-expression = LPAREN (list-item)* RPAREN => [[ second ]]
;EBNF
s-expression = LPAREN (list-item)* RPAREN => [[ second <s-exp> ]]
;EBNF