blob: 514a8e6f4c685a5ca022b850ffb90e0585ff9c14 (
plain) (
blame)
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
|
class TokenList inherits System {
token: IToken;
next: TokenList;
init(value: IToken, tail: Object) : TokenList {{
assert(not (isvoid value), "init", "value argument cannot be void!");
assert(isvoid token, "init", "List has already been initialised!");
token <- value;
if isvoid tail then
void
else
case tail of
tl: TokenList => next <- tl;
o: Object => assert(false, "init", "tail argument can be either a TokenList or void!");
esac
fi;
self;
}};
push(value: IToken) : TokenList {{
assert(not (isvoid value), "push", "value argument cannot be void!");
if isvoid token
then
token <- value
else if isvoid next
then
next <- (new TokenList).init(value, void)
else
next.push(value)
fi
fi;
self;
}};
out() : Object {{
if isvoid token
then
void
else
out_string("<")
.out_string(token.name())
.out_string(">")
fi;
if isvoid next
then
void
else {
out_string(" ");
next.out();
}
fi;
}};
};
|