]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/lsys/strings/interpret/interpret.factor
Merge branch 'master' into experimental (untested!)
[factor.git] / unmaintained / lsys / strings / interpret / interpret.factor
1
2 USING: kernel sequences quotations assocs math math.parser
3        combinators.lib vars lsys.strings combinators.short-circuit ;
4
5 IN: lsys.strings.interpret
6
7 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
8
9 VAR: command-table
10
11 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12
13 : exec-command ( string -- ) command-table> at >quotation call ;
14
15 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16
17 : command ( string -- command ) 1 head ;
18
19 : parameter ( string -- parameter )
20   [ drop 2 ] [ length 1- ] [ ] tri subseq string>number ;
21
22 : exec-command* ( string -- )
23   [ parameter ] [ command ] bi
24   command-table> at dup
25   [ 1 tail* call ] [ 2drop ] if ;
26
27 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
28
29 : (interpret) ( slice -- )
30   { { [ empty? ]     [ drop ] }
31     { [ has-param? ] [ next+rest* [ exec-command* ] [ (interpret) ] bi* ] }
32     { [ t ]          [ next+rest  [ exec-command  ] [ (interpret) ] bi* ] } }
33   switch ;
34
35 : interpret ( string -- ) <flat-slice> (interpret) ;