comparison tests/agcl/parsifal/sql.syn @ 0:13d2b8934445

Import AnaGram (near-)release tree into Mercurial.
author David A. Holland
date Sat, 22 Dec 2007 17:52:45 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:13d2b8934445
1 /*
2 * AnaGram, A System for Syntax Directed Programming
3 * Copyright 1993-2002 Parsifal Software. All Rights Reserved.
4 * See the file COPYING for license and usage terms.
5 */
6
7 // Define character sets
8
9 blank = ' ' + '\t' + '\r'
10 digit = '0-9'
11 eof = 0
12 letter = 'a-z' + 'A-Z' + '#' + '@' + '$'
13 simple char = ~eof - ('\'' + '\\' + '\n')
14 string char = ~eof - ('"' + '\\' + '\n')
15
16
17 CHAR = {"CHAR" | "CHARACTER"}
18 DECIMAL = {"DEC" | "DECIMAL" | "NUM" | "NUMERIC"}
19 DECLARE SECTION = {"DECLARE", "SECTION"}
20 DELETE FROM = {"DELETE", "FROM"}
21 NOT NULL = {"NOT", "NULL"}
22 PACKAGE = {"PACKAGE" | "PROGRAM"}
23 PRIMARY KEY = {"PRIMARY", "KEY"}
24 USING DESCRIPTOR = {"USING", "DESCRIPTOR"}
25
26 [
27 distinguish keywords { letter} //Avoid problems with partial matches
28 disregard white space
29 lexeme {ordinary identifier, delimited identifier, integer,
30 decimal constant, character string constant}
31 distinguish lexemes
32 //sticky {ordinary identifier}
33 ~case sensitive
34 far tables
35 ]
36
37 // Define white space to include both C and C++ style comments
38 white space
39 -> blank
40 -> "//", ~(eof + '\n')?..., '\n'
41 -> ["--", ~(eof + '\n')?...], '\n'
42 -> "/*", ~eof?..., "*/"
43
44 identifier
45 -> ordinary identifier
46 -> delimited identifier
47
48 qualified identifier
49 -> identifier, '.', identifier
50
51 any identifier
52 -> identifier
53 -> qualified identifier
54
55 ordinary identifier
56 -> letter
57 -> ordinary identifier, letter + digit + '_'
58
59 delimited identifier
60 -> '"', delimited identifier text, '"'
61
62 delimited identifier text
63 -> delimited identifier char
64 -> delimited identifier text, delimited identifier char
65
66 delimited identifier char
67 -> ~eof - '"'
68 -> "\"\""
69
70 host identifier
71 -> 'a-z' + 'A-Z' + '_'
72 -> host identifier, 'a-z' + 'A-Z' + '0-9' + '_'
73
74 descriptor name
75 -> ':', host identifier
76
77 host variable
78 -> descriptor name
79 -> descriptor name, descriptor name
80
81 expression
82 -> term
83 -> expression, addop, term
84
85 addop
86 -> '+'
87 -> '-'
88
89 term
90 -> factor
91 -> term, multop, factor
92
93 multop
94 -> '*'
95 -> '/'
96
97 factor
98 -> special register
99 -> simple factor
100 -> simple factor, duration
101 -> sign, factor
102
103 simple factor
104 -> function
105 -> '(', expression, ')'
106 -> constant
107 -> column name
108 -> host variable
109
110 sign
111 -> '-' | '+'
112
113 column name
114 -> any identifier
115
116 constant
117 -> integer
118 -> decimal constant
119 -> floating point constant
120 -> character string constant
121
122 integer
123 -> digit
124 -> integer, digit
125
126 decimal constant
127 -> integer, '.'
128 -> decimal constant, digit
129
130 floating point constant
131 -> integer, "E", signed integer
132 -> decimal constant, "E", signed integer
133
134 signed integer
135 -> '+'?, integer
136 -> '-', integer
137
138 character string constant
139 -> '\'', character string char?..., '\''
140
141 character string char
142 -> ~eof - '\''
143 -> "''"
144
145 duration
146 -> "YEAR"
147 -> "YEARS"
148 -> "MONTH"
149 -> "MONTHS"
150 -> "DAY"
151 -> "DAYS"
152 -> "HOUR"
153 -> "HOURS"
154 -> "MINUTE"
155 -> "MINUTES"
156 -> "SECOND"
157 -> "SECONDS"
158 -> "MICROSECOND"
159 -> "MICROSECONDS"
160
161
162 // PREDICATES
163
164 predicate
165 -> expression, comparison operator, comparand
166 -> expression, between operator, expression, "AND", expression
167 -> expression, "IS", "NULL"
168 -> expression, "IS", NOT NULL
169 -> expression, similarity operator, like operand
170 -> expression, existence operator, set designation
171 -> "EXISTS", '(', fullselect, ')'
172
173 existence operator
174 -> "IN"
175 -> "NOT", "IN"
176
177 between operator
178 -> "BETWEEN"
179 -> "NOT", "BETWEEN"
180
181 similarity operator
182 -> "LIKE"
183 -> "NOT", "LIKE"
184
185 comparison operator
186 -> '=' | "<>" | '>' | "<=" | ">="
187
188 comparand
189 -> expression
190 -> '(', fullselect, ')'
191 -> quantifier, '(', fullselect, ')'
192
193 quantifier
194 -> "SOME"
195 -> "ANY"
196 -> "ALL"
197
198 like operand
199 -> "USER"
200 -> host variable
201 -> character string constant
202
203 set designation
204 -> '(', fullselect, ')'
205 -> '(', expression, {',', expression}..., ')'
206 -> expression
207
208 special register
209 -> "USER"
210 -> "CURRENT", "DATE"
211 -> "CURRENT", "TIME"
212 -> "CURRENT", "TIMESTAMP"
213
214 simple search condition
215 -> predicate
216 -> '(', search condition, ')'
217 -> "NOT", simple search condition
218
219 search condition
220 -> simple search condition
221 -> search condition, logical op, simple search condition
222
223 logical op
224 -> "AND"
225 -> "OR"
226
227 // FUNCTIONS
228
229 function
230 -> aggregate function
231 -> count function
232 -> char function
233 -> function name, '(', args, ')'
234
235 aggregate function name
236 -> "AVG" | "MAX" | "MIN" | "SUM"
237
238 aggregate function
239 -> aggregate function name, '(', "ALL"?, expression, ')'
240 -> aggregate function name, distinct column name
241
242 count function
243 -> "COUNT", distinct column name
244 -> "COUNT", '(', '*', ')'
245
246 distinct column name
247 -> '(', "DISTINCT", column name, ')'
248
249 char function
250 -> "CHAR", '(', expression, date type, ')'
251
252 date type
253 -> //not specified, use default
254 -> ',', "ISO"
255 -> ',', "USA"
256 -> ',', "EUR"
257 -> ',', "JIS"
258 -> ',', "LOCAL"
259
260 function name
261 -> "DATE" | "DAY" | "DAYS" | "HOUR" | "LENGTH" |
262 "MICROSECOND" | "MINUTE" | "MONTH" |
263 "SECOND" | "TIME" | "YEAR" |
264 "SUBSTR" | "TIMESTAMP" | "TRANSLATE"
265
266 args
267 -> expression
268 -> args, ',', expression
269
270 // QUERIES
271
272 subselect
273 -> select clause, from clause,
274 where clause?, group by clause?, having clause?
275
276 select clause
277 -> "SELECT", ["ALL" | "DISTINCT"], { '*' | select list}
278
279 select list
280 -> select item
281 -> select list, ',', select item
282
283 select item
284 -> expression
285 -> identifier, '.', '*'
286 -> identifier, '.', identifier, '.', '*'
287
288 from clause
289 -> "FROM", from list
290
291 from list
292 -> from item
293 -> from list, ',', from item
294
295 from item
296 -> any identifier
297 -> any identifier, any identifier
298
299 where clause
300 -> "WHERE", search condition
301
302 group by clause
303 -> "GROUP", "BY", identifier list
304
305 identifier list
306 -> any identifier
307 -> identifier list, ',', any identifier
308
309 paren identifier list
310 -> '(', identifier list, ')'
311
312 having clause
313 -> "HAVING", search condition
314
315 simple select
316 -> subselect
317 -> '(', fullselect, ')'
318
319 fullselect
320 -> simple select
321 -> fullselect, set operator, simple select
322
323 set operator
324 -> "UNION" | "UNION", "ALL" | "EXCEPT" | "EXCEPT", "ALL" |
325 "INTERSECT" | "INTERSECT", "ALL"
326
327 select statement
328 -> fullselect
329 -> fullselect, order by clause
330 -> fullselect, fetch clause
331 -> fullselect, order by clause, fetch clause
332 -> fullselect, update clause
333
334 order by clause
335 -> "ORDER", "BY", sort list
336
337 sort list
338 -> sort item
339 -> sort list, ',', sort item
340
341 sort item
342 -> any identifier, sort direction
343 -> integer, sort direction
344
345 sort direction
346 -> // not specified, use default
347 -> "ASC"
348 -> "DESC"
349
350 update clause
351 -> "FOR", "UPDATE", "OF", identifier list
352
353 fetch clause
354 -> "FOR", "FETCH", "ONLY"
355
356 // STATEMENTS
357
358 grammar
359 -> statements?, eof
360
361 statements
362 -> drop hack
363 -> statement
364 -> statements, statement
365
366 statement
367 -> "ALTER", "TABLE", any identifier, alter table item list, drop hack?...
368 -> "BEGIN", DECLARE SECTION
369 -> "CLOSE", identifier
370 -> "COMMENT", "ON", comment object, "IS", character string constant
371 -> "COMMIT", "WORK"?
372 -> create statement
373 -> "DECLARE", identifier, "CURSOR", ["WITH", "HOLD"], "FOR",
374 {select statement | identifier}
375 -> delete statement
376 -> "DESCRIBE", identifier, "INTO", descriptor name
377 -> "END", DECLARE SECTION
378 -> execute statement
379 -> fetch statement
380 -> "GRANT", privileges, "ON", privileged object, "TO", grantee
381 -> "INCLUDE", {"SQLCA" | "SQLDA"}
382 -> insert statement
383 -> "LOCK", "TABLE", any identifier, "IN", {"SHARE" | "EXCLUSIVE"}, "MODE"
384 -> open statement
385 -> "PREPARE", identifier, ["INTO", descriptor name], "FROM", host variable
386 -> "REVOKE", privileges, "ON", privileged object, "FROM", grantee
387 -> "ROLLBACK", "WORK"?
388 -> select into statement
389 -> update statement
390 -> "WHENEVER", {"NOT", "FOUND" | "SQLERROR" | "SQLWARNING"},
391 {"CONTINUE" | "GO", "TO", host identifier}
392
393 privileged object
394 -> privileged object type, any identifier
395 -> "DATABASE"
396
397 privileged object type
398 -> // defaults to table
399 -> "INDEX"
400 -> PACKAGE
401 -> "TABLE"
402
403 alter table item list
404 -> alter table item
405 -> alter table item list, alter table item
406
407 alter table item
408 -> "ADD", alter column definition
409 -> PRIMARY KEY, paren identifier list
410 -> referential constraint
411 -> "DROP", PRIMARY KEY
412 -> "DROP", "FOREIGN", "KEY", identifier
413
414 drop hack
415 -> "DROP", {"PACKAGE" | "PROGRAM" | "INDEX" | "TABLE" | "VIEW"}, identifier
416
417
418 alter column definition
419 -> any identifier, data type, alter column attribute list
420
421 alter column attribute list
422 ->
423 -> alter column attribute list, alter column attribute
424
425 alter column attribute
426 -> "FOR", "BIT", "DATA"
427 -> references
428 -> alter column identifier, references
429
430 alter column identifier
431 -> any identifier
432
433 referential constraint
434 -> referential constraint head, paren identifier list, references
435
436 referential constraint head
437 -> "FOREIGN", "KEY"
438 -> "FOREIGN", "KEY", any identifier
439
440 references
441 -> "REFERENCES", any identifier, rules
442
443 rules
444 ->
445 -> delete rule
446 -> delete rule, "ON", "UPDATE", "RESTRICT"
447 -> "ON", "UPDATE", "RESTRICT", delete rule?
448
449 // IBM SQL spec allows delete rule to be empty. Very ambiguous.
450
451 delete rule
452 -> "ON", "DELETE", {"RESTRICT" | "CASCADE" | "SET", "NULL"}
453
454 data type
455 -> "INT" | "INTEGER" | "SMALLINT"
456 -> "FLOAT"
457 -> DECIMAL
458 -> {CHAR | "VARCHAR"}, '(', integer, ')'
459 -> DECIMAL, '(', integer, ')'
460 -> DECIMAL, '(', integer, ',', integer, ')'
461 -> CHAR
462 -> "LONG", "VARCHAR"
463 -> "DATE" | "TIME" | "TIMESTAMP"
464
465 comment object
466 -> "TABLE", any identifier
467 -> "COLUMN", qualified identifier
468
469 create statement
470 -> "CREATE", "UNIQUE"?, "INDEX", any identifier, "ON", any identifier,
471 '(', sort list, ')'
472 -> "CREATE", "TABLE", any identifier, '(', create table list, ')'
473 -> "CREATE", "VIEW", any identifier, paren identifier list?,
474 "AS", fullselect, ["WITH", "CHECK", "OPTION"]
475
476 create table list
477 -> create table item
478 -> create table list, ',', create table item
479
480 create table item
481 -> create column definition
482 -> PRIMARY KEY, paren identifier list
483 -> referential constraint
484
485 create column definition
486 -> any identifier, data type
487 -> create column definition, create column attribute
488
489 create column attribute
490 -> "FOR", "BIT", "DATA"
491 -> NOT NULL
492 -> NOT NULL, PRIMARY KEY
493 -> references
494 -> any identifier, references
495
496
497 delete statement
498 -> DELETE FROM, any identifier, where clause?
499 -> DELETE FROM, any identifier, any identifier, where clause?
500 -> DELETE FROM, any identifier, where current clause
501
502 where current clause
503 -> "WHERE", "CURRENT", "OF", any identifier
504
505
506 execute statement
507 -> "EXECUTE", identifier
508 -> "EXECUTE", identifier, "USING", host variable list
509 -> "EXECUTE", identifier, USING DESCRIPTOR, descriptor name
510 -> "EXECUTE", "IMMEDIATELY", host variable
511
512 host variable list
513 -> host variable
514 -> host variable list, ',', host variable
515
516
517 fetch statement
518 -> "FETCH", any identifier, "INTO", host variable list
519 -> "FETCH", any identifier, USING DESCRIPTOR, descriptor name
520
521 grantee
522 -> "PUBLIC"
523 -> identifier list
524
525 privileges
526 -> "ALL", "PRIVILEGES"?
527 -> privilege list
528
529 privilege list
530 -> privilege
531 -> privilege list, ',', privilege
532
533 privilege
534 -> "BINDADD" | "CONNECT" | "CREATETAB" | "DBADM"
535 -> "ALTER" | "BIND" | "CONTROL" | "DELETE" | "EXECUTE" |
536 "INDEX" | "INSERT" | "REFERENCES" | "SELECT" | "UPDATE"
537
538 insert statement
539 -> "INSERT", "INTO", any identifier,
540 {fullselect | "VALUES", '(', value list, ')'}
541 -> "INSERT", "INTO", any identifier, paren identifier list,
542 {fullselect | "VALUES", '(', value list, ')'}
543
544 value list
545 -> value
546 -> value list, ',', value
547
548 value
549 -> host variable
550 -> constant
551 -> special register
552 -> "NULL"
553
554 open statement
555 -> "OPEN", any identifier
556 -> "OPEN", any identifier, "USING", host variable list
557 -> "OPEN", any identifier, USING DESCRIPTOR, descriptor name
558
559 select into statement
560 -> select clause, "INTO", host variable list, from clause,
561 where clause?, group by clause?, having clause?
562
563 update statement
564 -> "UPDATE", any identifier, set clause
565 -> "UPDATE", any identifier, any identifier, set clause
566 -> "UPDATE", any identifier, conditioned set clause
567 -> "UPDATE", any identifier, any identifier, conditioned set clause
568 -> "UPDATE", any identifier, set clause, where current clause
569
570 set clause
571 -> "SET", assignment list
572
573 conditioned set clause
574 -> set clause, where clause
575
576 assignment list
577 -> assignment
578 -> assignment list, ',', assignment
579
580 assignment
581 -> identifier, '=', {expression | "NULL"}