blob: a4a0b88ab37e7b8e0d6c9d8dba8ff84f38a286c6 (
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
95
96
97
98
99
100
|
##### LM #####
# Or-literal scanner
lex
token orlit_dash /'-' /
token orlit_close /']'/
rl orlit_specials /[\-\]]/
token orlit_chr /^orlit_specials | '\\' any/
end
def orlit_item
[orlit_chr]
| [orlit_chr orlit_dash orlit_chr]
def orlit
[orlit_item*]
# Regex scanner
lex
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/
end
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
token ident /[a-zA-Z_]+/
token number /[0-9]+/
token string /s_string | d_string/
literal '+', '-', '*', ';', '/'
token slash /'/'/
token semi /';'/
ignore wp /[ \t\n]+/
end
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*]
parse S: start[ stdin ]
for I:orlit_item in S {
if match I [orlit_chr] {
print( I '\n' )
}
}
print_xml( S )
print( '\n' )
##### IN #####
2 / /[^gu-zy].*o[\d-xa]*/;
##### EXP #####
g
y
a
<start><_repeat_statement><statement><expr><term><term><factor><number>2</number></factor></term><_literal_0021>/</_literal_0021><factor><_literal_0021>/</_literal_0021><regex_body><_repeat_regex_item><regex_item><regex_base><orlit_neg_open>[^</orlit_neg_open><orlit><_repeat_orlit_item><orlit_item><orlit_chr>g</orlit_chr></orlit_item><orlit_item><orlit_chr>u</orlit_chr><orlit_dash>-</orlit_dash><orlit_chr>z</orlit_chr></orlit_item><orlit_item><orlit_chr>y</orlit_chr></orlit_item></_repeat_orlit_item></orlit><orlit_close>]</orlit_close></regex_base><regex_rep></regex_rep></regex_item><regex_item><regex_base><regex_dot>.</regex_dot></regex_base><regex_rep><regex_star>*</regex_star></regex_rep></regex_item><regex_item><regex_base><regex_chr>o</regex_chr></regex_base><regex_rep></regex_rep></regex_item><regex_item><regex_base><orlit_open>[</orlit_open><orlit><_repeat_orlit_item><orlit_item><orlit_chr>\d</orlit_chr><orlit_dash>-</orlit_dash><orlit_chr>x</orlit_chr></orlit_item><orlit_item><orlit_chr>a</orlit_chr></orlit_item></_repeat_orlit_item></orlit><orlit_close>]</orlit_close></regex_base><regex_rep><regex_star>*</regex_star></regex_rep></regex_item></_repeat_regex_item></regex_body><regex_close>/</regex_close></factor></term></expr><_literal_001f>;</_literal_001f></statement></_repeat_statement></start>
|