-
Notifications
You must be signed in to change notification settings - Fork 0
/
quuz.leg
251 lines (188 loc) · 6.43 KB
/
quuz.leg
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
start = intertokenSpace datum
hashBang = '#!' (!lineEnding .)* lineEnding
# 7.1.1 Lexical structure
delimiter = whitespace | '(' | ')' | '\"' | ';' | '|'
lineEnding = '\n' | '\r' | '\r\n'
intralineWhitespace = ' ' | '\t'
whitespace = intralineWhitespace | lineEnding
comment = ';' (!lineEnding .)*
| nestedComment
| '#;' atmosphere datum
nestedComment = '#|' commentText commentCont* '|#'
commentText = (!('#|' | '|#') .)*
commentCont = nestedComment commentText
atmosphere = whitespace | comment
intertokenSpace = atmosphere*
identifier = initial subsequent*
| '|' {concat_string('|');} symbolElement* '|' {concat_string('|');}
| peculiarIdentifier
initial = < letter > {concat_string(*yytext);}
| < specialInitial > {concat_string(*yytext);}
| ihe:inlineHexEscape {concat_string(ihe);}
letter = [a-zA-Z]
specialInitial = '!' | '$' | '%' | '&'
| '*' | '/' | ':' | '<' | '=' | '>'
| '?' | '^' | '_' | '~'
subsequent = initial
| < digit > {concat_string(*yytext);}
| specialSubsequent
digit = [0-9]
hexDigit = digit | [a-fA-F]
explicitSign = < ('+' | '-') > {concat_string(*yytext);}
specialSubsequent = explicitSign
| '.' {concat_string('.');}
| '@' {concat_string('@');}
inlineHexEscape = '\\x' hexScalarValue ';'
hexScalarValue = < hexDigit+ > {$$ = strtol(yytext, NULL, 16);}
peculiarIdentifier = explicitSign
| explicitSign signSubsequent subsequent*
| explicitSign '.' {concat_string('.');} dotSubsequent subsequent*
| '.' {concat_string('.');} nonDigit subsequent*
nonDigit = dotSubsequent | explicitSign
dotSubsequent = signSubsequent
| '.' {concat_string('.');}
signSubsequent = initial
| explicitSign
| '@' {concat_string('@');}
symbolElement = < [^|\\] > {concat_string(*yytext);}
| ihe:inlineHexEscape {concat_string(ihe);}
boolean = ('#true' | '#t') {$$ = 1;}
| ('#false' | '#f') {$$ = 0;}
character = '#\\' characterName
| '#\\x' hexScalarValue
| '#\\' < . > {$$ = *yytext;}
characterName = 'alarm' {$$ = '\a';}
| 'backspace' {$$ = '\b';}
| 'delete' {$$ = '\x7F';}
| 'escape' {$$ = '\x1B';}
| 'newline' {$$ = '\n';}
| 'null' {$$ = '\0';}
| 'return' {$$ = '\r';}
| 'space' {$$ = ' ';}
| 'tab' {$$ = '\t';}
string = '\"' stringElement* '\"'
stringElement = lineEnding {concat_string('\n');}
| < [^"\\] > {concat_string(*yytext);}
| '\\a' {concat_string('\a');}
| '\\b' {concat_string('\b');}
| '\\t' {concat_string('\t');}
| '\\n' {concat_string('\n');}
| '\\r' {concat_string('\r');}
| '\\\"' {concat_string('"');}
| '\\\\' {concat_string('\\');}
| '\\' intralineWhitespace lineEnding intralineWhitespace
| ihe:inlineHexEscape {concat_string(ihe);}
bytevector = {push_bytevector();} bytevectorBeginToken byte* listEndToken {pop();}
byte = n:numberToken {concat_bytevector(n);}
number = num2 | num8 | num10 | num16
num2 = prefix2 complex2
num8 = prefix8 complex8
num10 = prefix10 complex10
num16 = prefix16 complex16
complex2 = real2
# | real2 '@' real2
# | real2 '+' ureal2 'i' | real2 '-' ureal2 'i'
# | real2 '+i' | real2 '-i' | real2 infinity 'i'
# | '+' ureal2 'i' | '-' ureal2 'i'
# | infinity 'i' | '+i' | '-i'
complex8 = real8
# | real8 '@' real8
# | real8 '+' ureal8 'i' | real8 '-' ureal8 'i'
# | real8 '+i' | real8 '-i' | real8 infinity 'i'
# | '+' ureal8 'i' | '-' ureal8 'i'
# | infinity 'i' | '+i' | '-i'
complex10 = real10
# | real10 '@' real10
# | real10 '+' ureal10 'i' | real10 '-' ureal10 'i'
# | real10 '+i' | real10 '-i' | real10 infinity 'i'
# | '+' ureal10 'i' | '-' ureal10 'i'
# | infinity 'i' | '+i' | '-i'
complex16 = real16
# | real16 '@' real16
# | real16 '+' ureal16 'i' | real16 '-' ureal16 'i'
# | real16 '+i' | real16 '-i' | real16 infinity 'i'
# | '+' ureal16 'i' | '-' ureal16 'i'
# | infinity 'i' | '+i' | '-i'
real2 = < sign ureal2 > {$$ = strtol(yytext, NULL, 2);}
# | infinity
real8 = < sign ureal8 > {$$ = strtol(yytext, NULL, 8);}
# | infinity
real10 = < sign ureal10 > {$$ = strtol(yytext, NULL, 10);}
# | infinity
real16 = < sign ureal16 > {$$ = strtol(yytext, NULL, 16);}
# | infinity
ureal2 = uinteger2
| uinteger2 '/' uinteger2
ureal8 = uinteger8
| uinteger8 '/' uinteger8
ureal10 = uinteger10
| uinteger10 '/' uinteger10
| decimal10
ureal16 = uinteger16
| uinteger16 '/' uinteger16
decimal10 = uinteger10 suffix
| '.' digit10+ suffix
| digit10+ '.' digit10* suffix
uinteger2 = digit2+
uinteger8 = digit8+
uinteger10 = digit10+
uinteger16 = digit16+
prefix2 = radix2 exactness
| exactness radix2
prefix8 = radix8 exactness
| exactness radix8
prefix10 = radix10 exactness
| exactness radix10
prefix16 = radix16 exactness
| exactness radix16
#infinity = '+inf.0' | '-inf.0' | '+nan.0'
suffix = (exponentMarker sign digit10+)?
exponentMarker = 'e' | 's' | 'f' | 'd' | 'l'
sign = ('+' | '-')?
exactness = ('#i' | '#e')?
radix2 = '#b'
radix8 = '#o'
radix10 = '#d'?
radix16 = '#x'
digit2 = [0-1]
digit8 = [0-7]
digit10 = digit
digit16 = hexDigit
identifierToken = identifier (&delimiter | !.) intertokenSpace
booleanToken = boolean (&delimiter | !.) intertokenSpace
numberToken = number (&delimiter | !.) intertokenSpace
characterToken = character (&delimiter | !.) intertokenSpace
stringToken = string (&delimiter | !.) intertokenSpace
listBeginToken = '(' intertokenSpace
listEndToken = ')' intertokenSpace
vectorBeginToken = '#(' intertokenSpace
bytevectorBeginToken = '#u8(' intertokenSpace
dotToken = '.' intertokenSpace
quoteToken = '\'' intertokenSpace
quasiquoteToken = '`' intertokenSpace
unquoteToken = ',' intertokenSpace
unquoteSplicingToken = ',@' intertokenSpace
# 7.1.2 External representations
datum = simpleDatum
| compoundDatum
| label '=' datum
| label '#' intertokenSpace # not specified but seemed to be the intent
simpleDatum = b:booleanToken {append_bool(b);}
| n:numberToken {append_number(n);}
| c:characterToken {append_char(c);}
| {push_string();} stringToken {pop();}
| {push_string();} symbol {pop_sym();}
| bytevector
symbol = identifierToken
compoundDatum = list
| vector
list = {push_pair();} listBeginToken datum* listEndToken {pop();}
| {push_pair();} listBeginToken datum+ dotToken datum listEndToken {elide_pair();pop();}
| abbreviation
abbreviation = {push_pair();} abbrevPrefix datum {pop();}
abbrevPrefix = quoteToken {append_sym("quote");}
| quasiquoteToken {append_sym("quasiquote");}
| unquoteSplicingToken {append_sym("unquote-splicing");}
| unquoteToken {append_sym("unquote");}
vector = {push_vector();} vectorBeginToken datum* listEndToken {pop();}
label = '#' digit+