fjsc: add \ word functionality

darcs
chris.double 2006-12-15 08:03:13 +00:00
parent 0850fd1277
commit 51f22055d1
1 changed files with 16 additions and 0 deletions

View File

@ -11,6 +11,7 @@ TUPLE: ast-quotation expression ;
TUPLE: ast-array elements ; TUPLE: ast-array elements ;
TUPLE: ast-define name expression ; TUPLE: ast-define name expression ;
TUPLE: ast-expression values ; TUPLE: ast-expression values ;
TUPLE: ast-word value ;
TUPLE: ast-alien return method args ; TUPLE: ast-alien return method args ;
LAZY: 'digit' ( -- parser ) LAZY: 'digit' ( -- parser )
@ -78,6 +79,10 @@ LAZY: 'array' ( -- parser )
'expression' &> 'expression' &>
"}" token sp <& [ <ast-array> ] <@ ; "}" token sp <& [ <ast-array> ] <@ ;
LAZY: 'word' ( -- parser )
"\\" token sp
'identifier' sp &> [ ast-identifier-value <ast-word> ] <@ ;
LAZY: 'atom' ( -- parser ) LAZY: 'atom' ( -- parser )
'identifier' 'number' <|> 'string' <|> ; 'identifier' 'number' <|> 'string' <|> ;
@ -89,6 +94,7 @@ LAZY: 'alien' ( -- parser )
LAZY: 'expression' ( -- parser ) LAZY: 'expression' ( -- parser )
'define' sp 'define' sp
'word' sp <|>
'alien' sp <|> 'alien' sp <|>
'atom' sp <|> 'atom' sp <|>
'quotation' sp <|> 'quotation' sp <|>
@ -173,6 +179,16 @@ M: ast-alien (compile)
")" , ")" ,
] when ; ] when ;
M: ast-word (literal)
"factor.words[\"" ,
ast-word-value ,
"\"]" , ;
M: ast-word (compile)
"factor.data_stack.push(" ,
(literal)
")" , ;
: fjsc-compile ( ast -- string ) : fjsc-compile ( ast -- string )
[ [
[ (compile) ] { } make [ write ] each [ (compile) ] { } make [ write ] each