blob: 0d4060f0065453ab7e7425d4268802169c93eca7 (
plain)
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
|
##### LM #####
context si
lex
literal `! `a
token SEMI_NL /';\n'/
token id /'a'|'b'/
{
input.push( make_token( trans_id_to input.pull(match_length) ) )
}
token super_id //
token foo //
ignore ws / [ \n\t]+ /
end
trans_id_to: int
def e1
[]
{
print( 'old_id = ' trans_id_to '\n' )
trans_id_to = typeid<foo>
print( 'new_id = ' trans_id_to '\n' )
}
def item1
msg: str
[ e1 `! `a super_id super_id `a]
{
lhs.msg = 'this is item1\n'
}
def e2
[]
{
print( 'old_id = ' trans_id_to '\n' )
trans_id_to = typeid<super_id>
print( 'new_id = ' trans_id_to '\n' )
}
def item2
msg: str
[ e2 `! `a super_id super_id `a]
{
lhs.msg = 'this is item2\n'
}
def start
[item1 SEMI_NL]
| [item2 SEMI_NL]
{
match lhs [Item2:item2 ';\n']
print( Item2.msg )
}
end # si
cons SuperId: si[]
parse S: si::start(SuperId)[stdin]
print_xml( S )
print( '\n' )
##### IN #####
!a b b a;
##### EXP #####
old_id = NIL
new_id = 14
old_id = NIL
new_id = 13
this is item2
<si::start><si::item2><si::e2></si::e2><si::_literal_0001>!</si::_literal_0001><si::_literal_0003>a</si::_literal_0003><si::super_id>b</si::super_id><si::super_id>b</si::super_id><si::_literal_0003>a</si::_literal_0003></si::item2><si::SEMI_NL>;
</si::SEMI_NL></si::start>
|