AQL is a proposed new query language for acedb. Here I give the syntax for AQL as working at the end of the ACE97 workshop (8/8/97). The syntax given below is marked up directly from the yacc file, except that I represent ":=" and "->" as tokens in true yacc. The keywords are shown in bold. There is also a "walk through" document that gives a more human-friendly introduction to the language.
Things I personally would like to change are:
'_' from the default table variable nameall when the select
fields are identical to the from variables.We also need, or need to think about:
@ variables - we need to be able to
store/retrive them from the databaselike for full regexp matchinggrep and neighbours operators.
grep is not the same like. It
searches all object names and text in the whole database.$ as a prefix for sets.
table_expr: safe_table
| table_expr ';' table_expr
| select fieldlist from fwlist
| select all fwlist
| table_expr order_BY sortlist
| table_expr union table_expr
| table_expr intersect table_expr
| table_expr diff table_expr
| '@' Identifier ":=" table_expr
;
safe_table: '(' table_expr ')'
| '@' Identifier
| '@' '_'
;
sortlist: sort_criterion
| sortlist ',' sort_criterion
;
sort_criterion: '.' Identifier
| '[' Number ']'
| '.' Identifier Ordering
| '[' Number ']' Ordering
;
fieldlist: field
| fieldlist ',' field
;
field: expr
| Identifier ':' expr
;
fwlist: fw
| fw where bool_expr
| fwlist ',' fw
| fwlist ',' fw where bool_expr
;
fw: basic_decl
| Identifier in basic_decl
| basic_decl as Identifier
| basic_decl Identifier
;
basic_decl: locator
| safe_table
| class Identifier
;
bool_expr:
|
| exists locator
| exists_tag locator
| expr Comparator expr
| not bool_expr
| bool_expr and bool_expr
| bool_expr or bool_expr
| bool_expr xor bool_expr
| '(' bool_expr ')'
;
locator: Identifier
| object '(' expr ',' expr ')'
| locator '.' Identifier
| locator "->" Identifier
| locator '[' Number ']'
| locator "->" '[' Number ']'
| safe_table '.' Identifier
| safe_table '[' Number ']'
| '.' Identifier
| "->" Identifier
| '[' Number ']'
| "->" '[' Number ']'
;
expr: locator
| StringLiteral
| Number
| FloatLiteral
| date
| name '(' locator ')'
| class '(' locator ')'
| TableFunc safe_table
| DateFunc '(' expr ',' expr ')'
| expr '+' expr
| expr '-' expr
| expr '*' expr
| expr '/' expr
| '-' expr %prec UMINUS
| '(' expr ')'
;
date: now
| today
| DateStart
| DateStart DateEnd
The relevant lex definitions are given below (in a kind of hybrid
lex/yacc notation). We could probably tighten them, e.g. forbid
numbers starting with '0', require date years to be two or four digits
(we recognize 50 to 49 as 1950 to 2049, but also accept full dates).
TableFunc: count | first | last | min | max | sum | avg
DateFunc: yeardiff | monthdiff | weekdiff | daydiff
| hourdiff | mindiff | secdiff
Ordering: asc | desc
Comparator: "=" | "<" | ">" | "!=" | "<=" | ">="
Identifier: [A-Za-z][A-Za-z0-9_]*
Number: [0-9]+
FloatLiteral: [0-9]+[eE][+-]?[0-9]+
| [0-9]+"."[0-9]*[eE][+-]?[0-9]+
| "."[0-9]+[eE][+-]?[0-9]+
| [0-9]+"."[0-9]*
| "."[0-9]+
StringLiteral: \"([^"]|\\["\n])*\"
DateStart: "`"[1-9][0-9]+
| "`"[1-9][0-9]+"-"[0-1][0-9]
| "`"[1-9][0-9]+"-"[0-1][0-9]"-"[0-3][0-9]
DateEnd: "_"[0-2][0-9]:[0-5][0-9]:[0-5][0-9]
| "_"[0-2][0-9]:[0-5][0-9]
| "_"[0-2][0-9]