-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.ps
119 lines (103 loc) · 2.17 KB
/
util.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
% generates an array from num to zero
/array_to { % num - num num-1 num-2 ... 0
dup 0 ge
{ mark exch dup { dup 1 sub } repeat ] }
{ [] }
ifelse
} def
/printdict {
mark exch { } forall pstack ] pop
} def
/isMark {
dup mark eq
} def
/genStr {
counttomark dup string exch { dup 3 -1 roll exch counttomark 3 sub 3 -1 roll put } repeat exch pop
} def
/isOpenPT % string - string bool
{
isEmpty not % isNotEmpty
{ % == (
dup 0 0 3 1 roll exch isOpenPTWithoutWhiteSpace
}
{ false }
ifelse
} def
/isOPT {
dup 40 eq
} def
/isCPT {
dup 41 eq
} def
/isWhiteChar {
dup dup 32 eq exch 9 eq or
} def
/isOpenPTWithoutWhiteSpace % string (base string) integer (base counter) string (copy of base string for get) integer (counter for get) - string bool
{
isEmpty % if string is already empty
{ false }
{
exch get dup dup
32 eq exch 9 eq % true if tab or blank current character in string on stack
or {
pop
exch dup 3 1 roll exch % setup for call of isOpenPTWithoutWhiteSpace
1 add dup 3 1 roll exch
isOpenPTWithoutWhiteSpace
}
{ 40 eq exch pop } % true if char = '('
ifelse
}
ifelse
} def
/getTokenName % token - string
{
dup length string cvs
} def
/readLineStdin % - string
{
(%stdin) (r) file =string readline
} def
/isEmpty % string - string bool
{
dup length 0 eq
} def
/gotoline % file line# - file
{
{
dup =string readline pop pop
} repeat
} def
/test % test# - bool
{
(Lisp Interpreter Tester by Alex and Gabriel\n)
print
dup =string cvs print (.Test\n) print flush
1 sub
{
dup (test/tests) (r) file exch readLineAtNumber % - string bool
not
{ pop exit }
if
% line# string
parse
% line# erg
dup type 1 type eq
% line# erg bool
(test/ergebnisse) (r) file 4 -1 roll readLineAtNumber % - string bool
not
{ pop exit }
if
% erg bool erg2
exch { cvi } if
pstack % print stack
eq
% bool
(----------\n) print pstack
clear % clear stack
} exec %loop
} def
/readLineAtNumber % file line# - string bool
{
gotoline =string readline
} def