2005-02-09 22:35:11 -05:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2004-07-16 02:26:21 -04:00
|
|
|
IN: parser
|
2005-04-25 19:54:21 -04:00
|
|
|
USING: kernel lists namespaces sequences words ;
|
2004-07-21 19:26:41 -04:00
|
|
|
|
2005-01-14 14:56:19 -05:00
|
|
|
: parse-loop ( -- )
|
|
|
|
scan-word [
|
|
|
|
dup parsing? [ execute ] [ swons ] ifte parse-loop
|
|
|
|
] when* ;
|
|
|
|
|
2004-09-14 23:23:05 -04:00
|
|
|
: (parse) ( str -- )
|
2005-01-14 14:56:19 -05:00
|
|
|
"line" set 0 "col" set
|
|
|
|
parse-loop
|
|
|
|
"line" off "col" off ;
|
2004-07-18 19:52:01 -04:00
|
|
|
|
|
|
|
: parse ( str -- code )
|
2004-07-16 02:26:21 -04:00
|
|
|
#! Parse the string into a parse tree that can be executed.
|
2005-03-25 21:43:06 -05:00
|
|
|
[ f swap (parse) reverse ] with-parser ;
|
2004-11-20 16:57:01 -05:00
|
|
|
|
2005-03-25 21:43:06 -05:00
|
|
|
: eval ( "X" -- X ) parse call ;
|