| 1 |
<HTML> |
| 2 |
|
| 3 |
<HEAD> |
| 4 |
<TITLE>AQL - - BNF syntax (Version 4_8b)</TITLE> |
| 5 |
<LINK REL="stylesheet" TYPE="text/css" HREF="./aql.css" TITLE="Style sheet for AQL docs"> |
| 6 |
</HEAD> |
| 7 |
<BODY> |
| 8 |
|
| 9 |
|
| 10 |
<H2>AQL - BNF syntax (Version 4_8b)</H2> |
| 11 |
|
| 12 |
The syntax for the Acedb query language was developed at the ACE97 |
| 13 |
workshop (8/8/97) and further refined during implementation and |
| 14 |
testing. The syntax is given in BNF notation, which is kept |
| 15 |
in sync with the actual parser of the current AQL version. |
| 16 |
<P> |
| 17 |
The reserved keyword are printed in <B>bold</B>. |
| 18 |
All additional tokens are quoted in 'single quotes'. |
| 19 |
<P> |
| 20 |
Note that some "factoring" of the grammar has occurred, i.e. the |
| 21 |
introduction of <I>safe_table</I>. |
| 22 |
|
| 23 |
|
| 24 |
<HR> |
| 25 |
|
| 26 |
<pre> |
| 27 |
|
| 28 |
query: table_expr |
| 29 |
| query ';' query |
| 30 |
| '@' Identifier ':=' table_expr |
| 31 |
| '$' Identifier ':=' expr |
| 32 |
|
| 33 |
table_expr: safe_table |
| 34 |
| <b>select</b> fieldlist <b>from</b> fwlist |
| 35 |
| <b>select <A HREF="overview.shtml#DEF_ITERATOR">all</A></b> fwlist |
| 36 |
| <b>select <A HREF="overview.shtml#DEF_ITERATOR">all</A> from</b> fwlist |
| 37 |
| table_expr <b><A HREF="overview.shtml#ORDER_BY">order</A></b> // default left to right ascending |
| 38 |
| table_expr <b><A HREF="overview.shtml#ORDER_BY">order</A></b> Ordering |
| 39 |
| table_expr <b><A HREF="overview.shtml#ORDER_BY">order</A> <A HREF="overview.shtml#ORDER_BY">by</A></b> sortlist |
| 40 |
| table_expr <b>union</b> table_expr |
| 41 |
| table_expr <b>intersect</b> table_expr |
| 42 |
| table_expr <b>diff</b> table_expr | table_expr <b>except</b> table_expr |
| 43 |
|
| 44 |
safe_table: '(' table_expr ')' |
| 45 |
| '@' Identifier |
| 46 |
|
| 47 |
sortlist: sort_criterion |
| 48 |
| sortlist ',' sort_criterion |
| 49 |
|
| 50 |
<A HREF="overview.shtml#ORDER_BY">sort_criterion</A>: ':' Identifier // select column by name |
| 51 |
| ':' Number // select by column number |
| 52 |
| ':' Identifier Ordering |
| 53 |
| ':' Number Ordering |
| 54 |
|
| 55 |
Ordering: <B>asc</B> // ascending order - default |
| 56 |
| <B>desc</B> // descending order |
| 57 |
|
| 58 |
fieldlist: field |
| 59 |
| fieldlist ',' field |
| 60 |
|
| 61 |
field: expr |
| 62 |
| Identifier '::' expr // name alias for field-expression |
| 63 |
|
| 64 |
fwlist: fw |
| 65 |
| fw <b>where</b> expr // expr is evaluated in boolean context |
| 66 |
| fwlist ',' fw |
| 67 |
| fwlist ',' fw <b>where</b> expr // expr is evaluated in boolean context |
| 68 |
|
| 69 |
fw: <A HREF="overview.shtml#DEF_ITERATOR">basic_decl</A> // <A HREF="overview.shtml#DEF_ITERATOR">unnamed declaration</A> |
| 70 |
| Identifier <b>in</b> basic_decl |
| 71 |
| basic_decl <b>as</b> Identifier |
| 72 |
| basic_decl Identifier |
| 73 |
|
| 74 |
basic_decl: expr // i.e. a locator or anything that returns a value |
| 75 |
| safe_table |
| 76 |
| <b>class</b> Identifier |
| 77 |
|
| 78 |
<A HREF="overview.shtml#LOCATOR">locator</A>: Identifier |
| 79 |
| <b>object</b> '(' expr ',' expr ')' // create object (class, key) |
| 80 |
| locator '->' Identifier // follow into object by tag name |
| 81 |
| locator '->' Number // follow into object by position |
| 82 |
| locator '[' Identifier ']' // locate in current object by tag name |
| 83 |
| locator '[' Number ']' // locate in current object by position |
| 84 |
| locator ':' Identifier // row variable - select column by name |
| 85 |
| locator ':' Number // row variable - select column by number |
| 86 |
| locator '.' Method // <A HREF="overview.shtml#LOC_METHOD">locator method</A> |
| 87 |
| '->' Identifier // <A HREF="overview.shtml#DEF_ITERATOR">unnamed iterator</A> - follow by tag name |
| 88 |
| '->' Number // <A HREF="overview.shtml#DEF_ITERATOR">unnamed iterator</A> - follow by position |
| 89 |
| '[' Identifier ']' // <A HREF="overview.shtml#DEF_ITERATOR">unnamed iterator</A> - locate by tag name |
| 90 |
| '[' Number ']' // <A HREF="overview.shtml#DEF_ITERATOR">unnamed iterator</A> - locate by position |
| 91 |
| ':' Identifier // <A HREF="overview.shtml#DEF_ROW_VAR">unnamed row variable</A> - select column by name |
| 92 |
| ':' Number // <A HREF="overview.shtml#DEF_ROW_VAR">unnamed row variable</A> - select column by number |
| 93 |
| '.' Method // <A HREF="overview.shtml#DEF_ITERATOR">unnamed iterator</A> - <A HREF="overview.shtml#LOC_METHOD">locator method</A> |
| 94 |
| safe_table ':' Identifier // table expression - select column by name |
| 95 |
| safe_table ':' Number // table expression - select column by number |
| 96 |
|
| 97 |
|
| 98 |
Comparator: '=' | '!=' | '<' | '>' | '<=' | '>=' | <B>like</B> |
| 99 |
|
| 100 |
|
| 101 |
<A HREF="overview.shtml#EXPR_ARITH">expr</A><A NAME="EXPR">:</A> locator |
| 102 |
| <b>exists</b> locator // boolean true/false whether locator value is non-NULL |
| 103 |
| <b>exists</b> '(' locator ')' |
| 104 |
| <b>exists_tag</b> locator // whether the tag of the locator exists (does not fetch value) |
| 105 |
| <b>exists_tag</b> '(' locator ')' |
| 106 |
| '$' Identifier // a scalar variable |
| 107 |
| StringLiteral // test in double-quotes |
| 108 |
| Number |
| 109 |
| FloatLiteral |
| 110 |
| Date |
| 111 |
| <B>true</B> // i.e. boolean literal |
| 112 |
| <B>false</B> |
| 113 |
| expr Comparator expr // returns boolean result |
| 114 |
| <b>not</b> expr // negates boolean value |
| 115 |
| expr <b>and</b> expr |
| 116 |
| expr <b>or</b> expr |
| 117 |
| expr <b>xor</b> expr |
| 118 |
| expr '+' expr |
| 119 |
| expr '-' expr |
| 120 |
| expr '*' expr |
| 121 |
| expr '/' expr |
| 122 |
| expr '%' expr // positive remainder (also 'mod' or 'modulo') |
| 123 |
| '-' expr // negative value |
| 124 |
| '(' expr ')' |
| 125 |
| <B>mod</B> '(' expr ',' expr ')' // positive remainder (also '%' or `modulo') |
| 126 |
| <B>abs</B> '(' expr ')' // absolute value |
| 127 |
| DateFunc '(' expr ',' expr ')' |
| 128 |
| TableFunc safe_table |
| 129 |
| TableFunc safe_table ':' Number |
| 130 |
| TableFunc safe_table ':' Identifier |
| 131 |
|
| 132 |
<A HREF="overview.shtml#LOC_METHOD">Method</A>: <B>name</B> // get Object name as Text-type |
| 133 |
| <B>class</B> // get class-Object of Object-value |
| 134 |
| <B>length</B> // get length of <I>Text</I>-value |
| 135 |
| <B>create_session</B> // timestamp-object when the object was created |
| 136 |
| <B>create_time</B> // same, but as DateType-result |
| 137 |
| <B>update_session</B> // timestamp-object when the object was last modified |
| 138 |
| <B>update_time</B> // same, but as DateType-result |
| 139 |
| <B>node_session</B> // timestamp-object when the tag, or datafields was last added/modified |
| 140 |
| <B>node_time</B> // same, but as DateType-result |
| 141 |
|
| 142 |
<A HREF="overview.shtml#TABLE_FUNC">TableFunc</A>: <B>count</B> |
| 143 |
| <B>min</B> |
| 144 |
| <B>max</B> |
| 145 |
| <B>sum</B> |
| 146 |
| <B>avg</B> |
| 147 |
<!-- new as of 4.8 --> |
| 148 |
| <B>first</B> |
| 149 |
| <B>last</B> |
| 150 |
|
| 151 |
<A HREF="overview.shtml#DATE_FUNC">DateFunc</A>: <B>yeardiff</B> |
| 152 |
| <B>monthdiff</B> |
| 153 |
<!-- | <B>weekdiff</B> --> |
| 154 |
| <B>daydiff</B> |
| 155 |
| <B>hourdiff</B> |
| 156 |
| <B>mindiff</B> |
| 157 |
| <B>secdiff</B> |
| 158 |
|
| 159 |
Identifier: [A-Za-z][A-Za-z0-9_]* // starts with letter, followed by letters or numbers |
| 160 |
|
| 161 |
Number: [0-9]+ |
| 162 |
|
| 163 |
FloatLiteral: [0-9]+[eE][+-]?[0-9]+ |
| 164 |
| [0-9]+'.'[0-9]*[eE][+-]?[0-9]+ |
| 165 |
| '.'[0-9]+[eE][+-]?[0-9]+ |
| 166 |
| [0-9]+'.'[0-9]* |
| 167 |
| '.'[0-9]+ |
| 168 |
|
| 169 |
StringLiteral: \"([^"]|\\["\n])*\" // anything enclosed in quotes |
| 170 |
// quotes within a string can be escaped by backslash |
| 171 |
|
| 172 |
<A HREF="overview.shtml#DATE_TIME">Date</A>: <b>now</b> // current date/time as YYYY-MM-DD_HH:MM:SS |
| 173 |
| <b>today</b> // current date as YYYY-MM-DD |
| 174 |
| DateLiteral |
| 175 |
|
| 176 |
|
| 177 |
<A NAME="DATE_LITERAL"> |
| 178 |
DateLiteral:</A> '<B>`</B>'[12][90][0-9][0-9]'-'[01][0-9]'-'[0-3][0-9]'_'[0-2][0-9]':'[0-5][0-9]':'[0-5][0-9] |
| 179 |
| '<B>`</B>'[12][90][0-9][0-9]'-'[01][0-9]'-'[0-3][0-9]'_'[0-2][0-9]':'[0-5][0-9] |
| 180 |
| '<B>`</B>'[12][90][0-9][0-9]'-'[01][0-9]'-'[0-3][0-9]'_'[0-2][0-9] |
| 181 |
| '<B>`</B>'[12][90][0-9][0-9]'-'[01][0-9]'-'[0-3][0-9] |
| 182 |
| '<B>`</B>'[12][90][0-9][0-9]'-'[01][0-9] |
| 183 |
| '<B>`</B>'[12][90][0-9][0-9] |
| 184 |
|
| 185 |
|
| 186 |
</pre> |
| 187 |
|
| 188 |
<HR> |
| 189 |
<ADDRESS><A HREF="mailto:[email protected]">[email protected]</A></ADDRESS> |
| 190 |
|
| 191 |
</BODY> |
| 192 |
</HTML> |