2 USING: kernel sequences quotations assocs math math.parser
3 combinators.lib vars lsys.strings combinators.short-circuit ;
5 IN: lsys.strings.interpret
7 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
11 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
13 : exec-command ( string -- ) command-table> at >quotation call ;
15 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
17 : command ( string -- command ) 1 head ;
19 : parameter ( string -- parameter )
20 [ drop 2 ] [ length 1- ] [ ] tri subseq string>number ;
22 : exec-command* ( string -- )
23 [ parameter ] [ command ] bi
25 [ 1 tail* call ] [ 2drop ] if ;
27 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
29 : (interpret) ( slice -- )
30 { { [ empty? ] [ drop ] }
31 { [ has-param? ] [ next+rest* [ exec-command* ] [ (interpret) ] bi* ] }
32 { [ t ] [ next+rest [ exec-command ] [ (interpret) ] bi* ] } }
35 : interpret ( string -- ) <flat-slice> (interpret) ;