blob: 1d8b4f5842b26baa411b87fe16db3e0a2c344e93 (
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# Or-literal scanner
lex orlit
{
token orlit_dash /'-' /
token orlit_close /']'/
rl orlit_specials /[\-\]]/
token orlit_chr /^orlit_specials | '\\' any/
}
def orlit_item
[orlit_chr]
| [orlit_chr orlit_dash orlit_chr]
def orlit
[orlit_item*]
# Regex scanner
lex regex
{
token orlit_open /'['/
token orlit_neg_open /'[^'/
token regex_dot /'.'/
token regex_star /'*'/
token regex_close /'/'/
rl regex_specials /[\[\.\*\/\\]/
token regex_chr /(^regex_specials)+ | '\\' any/
}
def regex_rep
[regex_star]
| []
def regex_base
[regex_chr]
| [regex_dot]
| [orlit_open orlit orlit_close]
| [orlit_neg_open orlit orlit_close]
def regex_item
[regex_base regex_rep]
def regex_body
[regex_item*]
rl s_string /"'" ([^'\\\n] | '\\' any )* "'"/
rl d_string /'"' ([^"\\\n] | '\\' any )* '"'/
# Root scanner
lex start
{
token ident /[a-zA-Z_]+/
token number /[0-9]+/
token string /s_string | d_string/
literal '+', '-', '*', ';', '/'
token slash /'/'/
token semi /';'/
ignore wp /[ \t\n]+/
}
def factor
[ident]
| [number]
| [string]
| ['/' regex_body regex_close]
def term
[term '*' factor]
| [term '/' factor]
| [factor]
def expr
[expr '+' term]
| [expr '-' term]
| [term]
def statement
[expr ';']
def start
[statement*]
S: start = parse start( stdin )
for I:orlit_item in S {
if match I [orlit_chr] {
print( I '\n' )
}
}
print_xml( S )
|