-
Notifications
You must be signed in to change notification settings - Fork 1
/
lis.ps
85 lines (74 loc) · 1.67 KB
/
lis.ps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
%!
(util.ps) run
(lambda.ps) run
(eval.ps) run
/pdict_states <<
(lambda) { /pdict pdict_lambda def mark }
(quote) { /pdict pdict_quote def }
>> def
/pdict_default <<
40 { count 0 eq { mark } { isMark not { mark } if } ifelse mark } % '('
41 { isMark { pop } { genStr transit } ifelse eval mark } % ')'
32 { isMark not { genStr transit mark } if } % ' '
>> def
/pdict_lambda <<
40 { } % '(' do not delete
41 { isMark { pop } { genStr } ifelse ] mark /pdict pdict_default def } % ')'
32 { isMark not { genStr mark } if } % ' '
>> def
/open_brackets 1 def
/pdict_quote <<
40 { /open_brackets open_brackets 1 add def 40 } % '('
41 { % ')'
/open_brackets open_brackets 1 sub def
open_brackets 0 eq
{
/open_brackets open_brackets 1 add def
genStr eval mark
/pdict pdict_default def
}
{ 41 } ifelse
}
>> def
/pdict pdict_default def
/transit {
dup pdict_states exch known
{
dup pdict_states exch get exec
} if
} def
/parse {
dup 0 get 40 ne % if the stmnt starts with no brackets
{ getVal }
{
{
dup pdict exch known
{ pdict exch get exec }
if
} forall
open_brackets 1 eq
{ pop exec } % clear_par_arr is here just for testing
{ (Some brackets have not been closed\n) print }
ifelse
} ifelse
} def
/lisps
{
(Lisp Interpreter by Alex and Gabriel\n)
print
{
(lis.ps >) print flush
readLineStdin % - string bool
not
{ pop exit }
if
dup () ne % if no empty stmnt
{ parse }
if
dup () ne % if not None
{ pstack } % print stack
if
clear % clear stack
} loop
clearvars
} def