blob: 99057f8d6f67ebf9002fd97da8b8d5979c3a1901 [file] [log] [blame]
vinayakb38b7ca42012-03-05 05:44:15 +00001options {
2
3
4 STATIC = false;
5
6}
7
8
9PARSER_BEGIN(AQLParser)
10
11package edu.uci.ics.asterix.aql.parser;
12
13import java.io.*;
14import java.util.List;
15import java.util.ArrayList;
vinayakb38b7ca42012-03-05 05:44:15 +000016import java.util.Map;
17import java.util.HashMap;
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +000018import java.util.LinkedHashMap;
Till Westmann96c1f172013-08-01 02:05:48 -070019
20import org.apache.xerces.util.IntStack;
21
vinayakb38b7ca42012-03-05 05:44:15 +000022import edu.uci.ics.asterix.aql.literal.FloatLiteral;
23import edu.uci.ics.asterix.aql.literal.DoubleLiteral;
24import edu.uci.ics.asterix.aql.literal.FalseLiteral;
ilovesoupc9fef1d2012-07-08 19:30:42 +000025import edu.uci.ics.asterix.aql.base.Literal;
vinayakb38b7ca42012-03-05 05:44:15 +000026import edu.uci.ics.asterix.aql.literal.IntegerLiteral;
ilovesoupc9fef1d2012-07-08 19:30:42 +000027import edu.uci.ics.asterix.aql.literal.LongIntegerLiteral;
vinayakb38b7ca42012-03-05 05:44:15 +000028import edu.uci.ics.asterix.aql.literal.NullLiteral;
29import edu.uci.ics.asterix.aql.literal.StringLiteral;
30import edu.uci.ics.asterix.aql.literal.TrueLiteral;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000031import edu.uci.ics.asterix.metadata.bootstrap.MetadataConstants;
vinayakb38b7ca42012-03-05 05:44:15 +000032
33import edu.uci.ics.asterix.aql.base.*;
34import edu.uci.ics.asterix.aql.expression.*;
35import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType;
36import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType;
37import edu.uci.ics.asterix.aql.expression.visitor.AQLPrintVisitor;
38import edu.uci.ics.asterix.aql.expression.UnaryExpr.Sign;
39import edu.uci.ics.asterix.aql.base.Statement.Kind;
40import edu.uci.ics.asterix.aql.context.Scope;
41import edu.uci.ics.asterix.aql.context.RootScopeFactory;
42import edu.uci.ics.asterix.common.annotations.*;
43import edu.uci.ics.asterix.common.exceptions.AsterixException;
ramangrover29a13f2422012-03-15 23:01:27 +000044import edu.uci.ics.asterix.om.functions.AsterixFunction;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000045import edu.uci.ics.asterix.common.functions.FunctionSignature;
alexander.behm07617fd2012-07-25 10:13:50 +000046import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
47import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +000048import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
49import edu.uci.ics.hyracks.algebricks.common.utils.Pair;
50import edu.uci.ics.hyracks.algebricks.common.utils.Triple;
51
52
vinayakb38b7ca42012-03-05 05:44:15 +000053
54
55public class AQLParser extends ScopeChecker {
56
vinayakb38b7ca42012-03-05 05:44:15 +000057 // optimizer hints
58 private static final String HASH_GROUP_BY_HINT = "hash";
59 private static final String BROADCAST_JOIN_HINT = "bcast";
alexander.behm07617fd2012-07-25 10:13:50 +000060 private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl";
vinayakb38b7ca42012-03-05 05:44:15 +000061 private static final String INMEMORY_HINT = "inmem";
62 private static final String VAL_FILE_HINT = "val-files";
63 private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx";
64 private static final String INTERVAL_HINT = "interval";
65 private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files";
66 private static final String INSERT_RAND_INT_HINT = "insert-rand-int";
67 private static final String LIST_VAL_FILE_HINT = "list-val-file";
68 private static final String LIST_HINT = "list";
69 private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
70 private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
71 private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
72 private static final String AUTO_HINT = "auto";
73
74 private static final String GEN_FIELDS_HINT = "gen-fields";
75
76 // data generator hints
77 private static final String DGEN_HINT = "dgen";
Till Westmann31c21f92013-05-08 09:21:53 -070078
79 private static class IndexParams {
80 public IndexType type;
81 public int gramLength;
82
83 public IndexParams(IndexType type, int gramLength) {
84 this.type = type;
85 this.gramLength = gramLength;
86 }
87 };
vinayakb38b7ca42012-03-05 05:44:15 +000088
ramangrover299f76a5e2013-06-18 10:25:17 -070089 private static class FunctionName {
90 public String dataverse = null;
91 public String library = null;
92 public String function = null;
93 }
94
vinayakb38b7ca42012-03-05 05:44:15 +000095 private static String getHint(Token t) {
Till Westmann31c21f92013-05-08 09:21:53 -070096 if (t.specialToken == null) {
97 return null;
98 }
99 String s = t.specialToken.image;
100 int n = s.length();
101 if (n < 2) {
102 return null;
103 }
104 return s.substring(1).trim();
vinayakb38b7ca42012-03-05 05:44:15 +0000105 }
Till Westmann77cb2f42013-07-15 16:44:19 -0700106
107 private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
108 IRecordFieldDataGen rfdg = null;
109 String splits[] = hint.split(" +");
110 if (splits[0].equals(VAL_FILE_HINT)) {
111 File[] valFiles = new File[splits.length - 1];
112 for (int k=1; k<splits.length; k++) {
113 valFiles[k-1] = new File(splits[k]);
114 }
115 rfdg = new FieldValFileDataGen(valFiles);
116 } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
117 rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
118 } else if (splits[0].equals(LIST_VAL_FILE_HINT)) {
119 rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3]));
120 } else if (splits[0].equals(LIST_HINT)) {
121 rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
122 } else if (splits[0].equals(INTERVAL_HINT)) {
123 FieldIntervalDataGen.ValueType vt;
124 if (splits[1].equals("int")) {
125 vt = FieldIntervalDataGen.ValueType.INT;
126 } else if (splits[1].equals("long")) {
127 vt = FieldIntervalDataGen.ValueType.LONG;
128 } else if (splits[1].equals("float")) {
129 vt = FieldIntervalDataGen.ValueType.FLOAT;
130 } else if (splits[1].equals("double")) {
131 vt = FieldIntervalDataGen.ValueType.DOUBLE;
132 } else {
133 throw new ParseException("Unknown type for interval data gen: " + splits[1]);
134 }
135 rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
136 } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
137 rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
138 } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
139 rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
140 } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) {
141 rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]));
142 } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) {
143 rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]);
144 } else if (splits[0].equals(AUTO_HINT)) {
145 rfdg = new AutoDataGen(splits[1]);
146 }
147 return rfdg;
148 }
vinayakb38b7ca42012-03-05 05:44:15 +0000149
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000150 public AQLParser(String s){
Till Westmann31c21f92013-05-08 09:21:53 -0700151 this(new StringReader(s));
152 super.setInput(s);
153 }
vinayakb38b7ca42012-03-05 05:44:15 +0000154
Till Westmann31c21f92013-05-08 09:21:53 -0700155 public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException {
156 File file = new File(args[0]);
157 Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
158 AQLParser parser = new AQLParser(fis);
159 List<Statement> st = parser.Statement();
160 //st.accept(new AQLPrintVisitor(), 0);
161 }
vinayakb38b7ca42012-03-05 05:44:15 +0000162}
163
164PARSER_END(AQLParser)
165
166
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000167List<Statement> Statement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000168{
vinayakb38b7ca42012-03-05 05:44:15 +0000169 scopeStack.push(RootScopeFactory.createRootScope(this));
170 List<Statement> decls = new ArrayList<Statement>();
Till Westmann31c21f92013-05-08 09:21:53 -0700171 Statement stmt = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000172}
173{
Till Westmann31c21f92013-05-08 09:21:53 -0700174 ( stmt = SingleStatement() (";") ?
vinayakb38b7ca42012-03-05 05:44:15 +0000175 {
Till Westmann31c21f92013-05-08 09:21:53 -0700176 decls.add(stmt);
177 }
178 )*
179 <EOF>
180 {
181 return decls;
182 }
183}
184
185Statement SingleStatement() throws ParseException:
186{
187 Statement stmt = null;
188}
189{
190 (
191 stmt = DataverseDeclaration()
192 | stmt = FunctionDeclaration()
193 | stmt = CreateStatement()
194 | stmt = LoadStatement()
195 | stmt = DropStatement()
196 | stmt = WriteStatement()
197 | stmt = SetStatement()
198 | stmt = InsertStatement()
199 | stmt = DeleteStatement()
200 | stmt = UpdateStatement()
201 | stmt = FeedStatement()
202 | stmt = Query()
203 )
204 {
205 return stmt;
206 }
207}
208
209DataverseDecl DataverseDeclaration() throws ParseException:
210{
Till Westmann14a20a72013-05-09 00:06:24 -0700211 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700212}
213{
Till Westmanna4242bc2013-05-08 17:49:55 -0700214 "use" "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700215 {
Till Westmann14a20a72013-05-09 00:06:24 -0700216 defaultDataverse = dvName;
217 return new DataverseDecl(new Identifier(dvName));
Till Westmann31c21f92013-05-08 09:21:53 -0700218 }
219}
220
221Statement CreateStatement() throws ParseException:
222{
223 String hint = null;
224 boolean dgen = false;
225 Statement stmt = null;
226}
227{
228 "create"
229 (
230 {
231 hint = getHint(token);
232 if (hint != null && hint.startsWith(DGEN_HINT)) {
233 dgen = true;
234 }
235 }
236 stmt = TypeSpecification(hint, dgen)
237 | stmt = NodegroupSpecification()
238 | stmt = DatasetSpecification()
239 | stmt = IndexSpecification()
240 | stmt = DataverseSpecification()
241 | stmt = FunctionSpecification()
ramangrover29a774ef22013-07-17 09:29:18 -0700242 | stmt = FeedSpecification()
Till Westmann31c21f92013-05-08 09:21:53 -0700243 )
244 {
245 return stmt;
246 }
247}
248
249TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
250{
251 Pair<Identifier,Identifier> nameComponents = null;
252 boolean ifNotExists = false;
253 TypeExpression typeExpr = null;
254}
255{
ramangrover299f76a5e2013-06-18 10:25:17 -0700256 "type" nameComponents = TypeName() ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700257 "as" typeExpr = TypeExpr()
258 {
259 long numValues = -1;
260 String filename = null;
261 if (dgen) {
262 String splits[] = hint.split(" +");
263 if (splits.length != 3) {
264 throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
265 }
266 filename = splits[1];
267 numValues = Long.parseLong(splits[2]);
268 }
269 TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
270 return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
271 }
272}
273
274
275NodegroupDecl NodegroupSpecification() throws ParseException:
276{
Till Westmann14a20a72013-05-09 00:06:24 -0700277 String name = null;
278 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700279 boolean ifNotExists = false;
280 List<Identifier>ncNames = null;
281}
282{
Till Westmanna4242bc2013-05-08 17:49:55 -0700283 "nodegroup" name = Identifier()
284 ifNotExists = IfNotExists() "on" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700285 {
286 ncNames = new ArrayList<Identifier>();
Till Westmann14a20a72013-05-09 00:06:24 -0700287 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700288 }
Till Westmann96c1f172013-08-01 02:05:48 -0700289 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700290 {
Till Westmann14a20a72013-05-09 00:06:24 -0700291 ncNames.add(new Identifier(tmp));
Till Westmann31c21f92013-05-08 09:21:53 -0700292 }
293 )*
294 {
Till Westmann14a20a72013-05-09 00:06:24 -0700295 return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700296 }
297}
298
299DatasetDecl DatasetSpecification() throws ParseException:
300{
301 Pair<Identifier,Identifier> nameComponents = null;
302 boolean ifNotExists = false;
Till Westmann14a20a72013-05-09 00:06:24 -0700303 String typeName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700304 String adapterName = null;
305 Map<String,String> properties = null;
306 FunctionSignature appliedFunction = null;
307 List<String> primaryKeyFields = null;
Till Westmann14a20a72013-05-09 00:06:24 -0700308 String nodeGroupName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700309 Map<String,String> hints = new HashMap<String,String>();
310 DatasetDecl dsetDecl = null;
311}
312{
313 (
Till Westmanna4242bc2013-05-08 17:49:55 -0700314 "external" <DATASET> nameComponents = QualifiedName()
315 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
316 ifNotExists = IfNotExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700317 "using" adapterName = AdapterName() properties = Configuration()
318 ( "hints" hints = Properties() )?
319 {
320 ExternalDetailsDecl edd = new ExternalDetailsDecl();
321 edd.setAdapter(adapterName);
322 edd.setProperties(properties);
Till Westmann14a20a72013-05-09 00:06:24 -0700323 dsetDecl = new DatasetDecl(nameComponents.first,
324 nameComponents.second,
325 new Identifier(typeName),
326 hints,
327 DatasetType.EXTERNAL,
328 edd,
329 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700330 }
331
Till Westmannd7dcb122013-05-16 13:19:09 -0700332 | ("internal")? <DATASET> nameComponents = QualifiedName()
Till Westmanna4242bc2013-05-08 17:49:55 -0700333 <LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
334 ifNotExists = IfNotExists()
335 primaryKeyFields = PrimaryKey() ("on" nodeGroupName = Identifier() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700336 ( "hints" hints = Properties() )?
337 {
Till Westmann14a20a72013-05-09 00:06:24 -0700338 InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null
339 ? new Identifier(nodeGroupName)
340 : null,
341 primaryKeyFields);
342 dsetDecl = new DatasetDecl(nameComponents.first,
343 nameComponents.second,
344 new Identifier(typeName),
345 hints,
346 DatasetType.INTERNAL,
347 idd,
348 ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700349 }
350 )
351 {
352 return dsetDecl;
353 }
354}
355
356CreateIndexStatement IndexSpecification() throws ParseException:
357{
358 CreateIndexStatement cis = new CreateIndexStatement();
Till Westmann14a20a72013-05-09 00:06:24 -0700359 String indexName = null;
360 String fieldExpr = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700361 boolean ifNotExists = false;
362 Pair<Identifier,Identifier> nameComponents = null;
363 IndexParams indexType = null;
364}
365{
Till Westmanna4242bc2013-05-08 17:49:55 -0700366 "index" indexName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700367 ifNotExists = IfNotExists()
368 "on" nameComponents = QualifiedName()
Till Westmann14a20a72013-05-09 00:06:24 -0700369 <LEFTPAREN> ( fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700370 {
Till Westmann14a20a72013-05-09 00:06:24 -0700371 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700372 }
Till Westmann96c1f172013-08-01 02:05:48 -0700373 ) (<COMMA> fieldExpr = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700374 {
Till Westmann14a20a72013-05-09 00:06:24 -0700375 cis.addFieldExpr(fieldExpr);
Till Westmann31c21f92013-05-08 09:21:53 -0700376 }
377 )* <RIGHTPAREN> ( "type" indexType = IndexType() )?
378 {
Till Westmann14a20a72013-05-09 00:06:24 -0700379 cis.setIndexName(new Identifier(indexName));
Till Westmann31c21f92013-05-08 09:21:53 -0700380 cis.setIfNotExists(ifNotExists);
381 cis.setDataverseName(nameComponents.first);
382 cis.setDatasetName(nameComponents.second);
383 if (indexType != null) {
384 cis.setIndexType(indexType.type);
385 cis.setGramLength(indexType.gramLength);
386 }
387 return cis;
388 }
389}
390
391IndexParams IndexType() throws ParseException:
392{
393 IndexType type = null;
394 int gramLength = 0;
395}
396{
397 ("btree"
398 {
399 type = IndexType.BTREE;
400 }
401 | "rtree"
402 {
403 type = IndexType.RTREE;
404 }
405 | "keyword"
406 {
JIMAHNb75446d2013-06-03 08:35:27 -0700407 type = IndexType.LENGTH_PARTITIONED_WORD_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700408 }
409 | "ngram" <LEFTPAREN> <INTEGER_LITERAL>
410 {
JIMAHNb75446d2013-06-03 08:35:27 -0700411 type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX;
Till Westmann31c21f92013-05-08 09:21:53 -0700412 gramLength = Integer.valueOf(token.image);
413 }
414 <RIGHTPAREN>)
415 {
416 return new IndexParams(type, gramLength);
417 }
418}
419
420CreateDataverseStatement DataverseSpecification() throws ParseException :
421{
Till Westmann14a20a72013-05-09 00:06:24 -0700422 String dvName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700423 boolean ifNotExists = false;
424 String format = null;
425}
426{
Till Westmanna4242bc2013-05-08 17:49:55 -0700427 "dataverse" dvName = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700428 ifNotExists = IfNotExists()
Till Westmann7d535322013-05-09 00:40:02 -0700429 ( "with format" format = StringLiteral() )?
Till Westmann31c21f92013-05-08 09:21:53 -0700430 {
Till Westmann14a20a72013-05-09 00:06:24 -0700431 return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700432 }
433}
434
435CreateFunctionStatement FunctionSpecification() throws ParseException:
436{
437 FunctionSignature signature;
438 boolean ifNotExists = false;
439 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
440 String functionBody;
ramangrover29bdba1a82013-06-21 17:17:52 -0700441 VarIdentifier var = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700442 Expression functionBodyExpr;
443 Token beginPos;
444 Token endPos;
ramangrover299f76a5e2013-06-18 10:25:17 -0700445 FunctionName fctName = null;
446
Till Westmann31c21f92013-05-08 09:21:53 -0700447 createNewScope();
448}
449{
ramangrover299f76a5e2013-06-18 10:25:17 -0700450 "function" fctName = FunctionName()
Till Westmann31c21f92013-05-08 09:21:53 -0700451 ifNotExists = IfNotExists()
Till Westmannd7dcb122013-05-16 13:19:09 -0700452 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -0700453 <LEFTBRACE>
Raman Groverf6b4b292013-09-24 11:11:20 +0530454 {
455 beginPos = token;
456 }
Till Westmann96c1f172013-08-01 02:05:48 -0700457 functionBodyExpr = Expression() <RIGHTBRACE>
Till Westmannd7dcb122013-05-16 13:19:09 -0700458 {
459 endPos = token;
460 functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn);
ramangrover299f76a5e2013-06-18 10:25:17 -0700461 // TODO use fctName.library
462 signature = new FunctionSignature(fctName.dataverse, fctName.function, paramList.size());
Till Westmannd7dcb122013-05-16 13:19:09 -0700463 getCurrentScope().addFunctionDescriptor(signature, false);
464 return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists);
465 }
466}
467
ramangrover29a774ef22013-07-17 09:29:18 -0700468CreateFeedStatement FeedSpecification() throws ParseException:
469{
470 Pair<Identifier,Identifier> nameComponents = null;
471 boolean ifNotExists = false;
472 String adaptorName = null;
473 Map<String,String> properties = null;
474 FunctionSignature appliedFunction = null;
475 CreateFeedStatement cfs = null;
476}
477{
478 (
479 "feed" nameComponents = QualifiedName()
480 ifNotExists = IfNotExists()
481 "using" adaptorName = AdapterName() properties = Configuration()
482 (appliedFunction = ApplyFunction())?
483 {
484 cfs = new CreateFeedStatement(nameComponents.first,
485 nameComponents.second, adaptorName, properties, appliedFunction, ifNotExists);
486 }
487
488 )
489 {
490 return cfs;
491 }
492}
493
494
495
Till Westmannd7dcb122013-05-16 13:19:09 -0700496List<VarIdentifier> ParameterList() throws ParseException:
497{
498 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
499 VarIdentifier var = null;
500}
501{
Till Westmann31c21f92013-05-08 09:21:53 -0700502 <LEFTPAREN> (<VARIABLE>
503 {
504 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700505 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700506 paramList.add(var);
507 getCurrentScope().addNewVarSymbolToScope(var);
508 }
Till Westmann96c1f172013-08-01 02:05:48 -0700509 (<COMMA> <VARIABLE>
Till Westmann31c21f92013-05-08 09:21:53 -0700510 {
511 var = new VarIdentifier();
Till Westmanna4242bc2013-05-08 17:49:55 -0700512 var.setValue(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700513 paramList.add(var);
514 getCurrentScope().addNewVarSymbolToScope(var);
515 }
Till Westmannd7dcb122013-05-16 13:19:09 -0700516 )*)? <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700517 {
Till Westmannd7dcb122013-05-16 13:19:09 -0700518 return paramList;
Till Westmann31c21f92013-05-08 09:21:53 -0700519 }
520}
521
522boolean IfNotExists() throws ParseException:
523{
524}
525{
526 ( "if not exists"
527 {
528 return true;
529 }
530 )?
531 {
532 return false;
533 }
534}
535
536FunctionSignature ApplyFunction() throws ParseException:
537{
538 FunctionSignature funcSig = null;
539}
540{
541 "apply" "function" funcSig = FunctionSignature()
542 {
543 return funcSig;
544 }
545}
546
ramangrover29566b3a92013-05-28 09:07:10 -0700547String GetPolicy() throws ParseException:
548{
549 String policy = null;
550}
551{
552 "using" "policy" policy = Identifier()
553 {
554 return policy;
555 }
556
557}
558
Till Westmann31c21f92013-05-08 09:21:53 -0700559FunctionSignature FunctionSignature() throws ParseException:
560{
ramangrover299f76a5e2013-06-18 10:25:17 -0700561 FunctionName fctName = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700562 int arity = 0;
563}
564{
ramangrover299f76a5e2013-06-18 10:25:17 -0700565 fctName = FunctionName() "@" <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700566 {
Till Westmanna4242bc2013-05-08 17:49:55 -0700567 arity = new Integer(token.image);
Till Westmann31c21f92013-05-08 09:21:53 -0700568 if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
569 throw new ParseException(" invalid arity:" + arity);
570 }
571
ramangrover299f76a5e2013-06-18 10:25:17 -0700572 // TODO use fctName.library
ramangrover2993dd8232013-07-03 22:51:25 -0700573 String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
574 return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -0700575 }
576}
577
578List<String> PrimaryKey() throws ParseException:
579{
Till Westmann14a20a72013-05-09 00:06:24 -0700580 String tmp = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700581 List<String> primaryKeyFields = new ArrayList<String>();
582}
583{
Till Westmann14a20a72013-05-09 00:06:24 -0700584 "primary" "key" tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700585 {
Till Westmann14a20a72013-05-09 00:06:24 -0700586 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700587 }
Till Westmann96c1f172013-08-01 02:05:48 -0700588 ( <COMMA> tmp = Identifier()
Till Westmann31c21f92013-05-08 09:21:53 -0700589 {
Till Westmann14a20a72013-05-09 00:06:24 -0700590 primaryKeyFields.add(tmp);
Till Westmann31c21f92013-05-08 09:21:53 -0700591 }
592 )*
593 {
594 return primaryKeyFields;
595 }
596}
597
598Statement DropStatement() throws ParseException:
599{
Till Westmann14a20a72013-05-09 00:06:24 -0700600 String id = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700601 Pair<Identifier,Identifier> pairId = null;
602 Triple<Identifier,Identifier,Identifier> tripleId = null;
603 FunctionSignature funcSig = null;
604 boolean ifExists = false;
605 Statement stmt = null;
606}
607{
608 "drop"
609 (
610 <DATASET> pairId = QualifiedName() ifExists = IfExists()
611 {
612 stmt = new DropStatement(pairId.first, pairId.second, ifExists);
613 }
614 | "index" tripleId = DoubleQualifiedName() ifExists = IfExists()
615 {
616 stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists);
617 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700618 | "nodegroup" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700619 {
Till Westmann14a20a72013-05-09 00:06:24 -0700620 stmt = new NodeGroupDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700621 }
ramangrover299f76a5e2013-06-18 10:25:17 -0700622 | "type" pairId = TypeName() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700623 {
624 stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists);
625 }
Till Westmanna4242bc2013-05-08 17:49:55 -0700626 | "dataverse" id = Identifier() ifExists = IfExists()
Till Westmann31c21f92013-05-08 09:21:53 -0700627 {
Till Westmann14a20a72013-05-09 00:06:24 -0700628 stmt = new DataverseDropStatement(new Identifier(id), ifExists);
Till Westmann31c21f92013-05-08 09:21:53 -0700629 }
630 | "function" funcSig = FunctionSignature() ifExists = IfExists()
631 {
632 stmt = new FunctionDropStatement(funcSig, ifExists);
633 }
ramangrover29a774ef22013-07-17 09:29:18 -0700634 | "feed" pairId = QualifiedName() ifExists = IfExists()
635 {
636 stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
637 }
Till Westmann31c21f92013-05-08 09:21:53 -0700638 )
639 {
640 return stmt;
641 }
642}
643
644boolean IfExists() throws ParseException :
645{
646}
647{
Till Westmann96c1f172013-08-01 02:05:48 -0700648 ( <IF> "exists"
Till Westmann31c21f92013-05-08 09:21:53 -0700649 {
650 return true;
651 }
652 )?
653 {
654 return false;
vinayakb38b7ca42012-03-05 05:44:15 +0000655 }
656}
657
658InsertStatement InsertStatement() throws ParseException:
659{
Till Westmann31c21f92013-05-08 09:21:53 -0700660 Pair<Identifier,Identifier> nameComponents = null;
661 Query query;
vinayakb38b7ca42012-03-05 05:44:15 +0000662}
663{
Till Westmann31c21f92013-05-08 09:21:53 -0700664 "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query()
665 {
666 return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter());
667 }
vinayakb38b7ca42012-03-05 05:44:15 +0000668}
669
670DeleteStatement DeleteStatement() throws ParseException:
671{
Till Westmann31c21f92013-05-08 09:21:53 -0700672 VariableExpr var = null;
673 Expression condition = null;
674 Pair<Identifier, Identifier> nameComponents;
vinayakb38b7ca42012-03-05 05:44:15 +0000675}
676{
Till Westmann31c21f92013-05-08 09:21:53 -0700677 "delete" var = Variable()
678 {
679 getCurrentScope().addNewVarSymbolToScope(var.getVar());
680 }
681 "from" <DATASET> nameComponents = QualifiedName()
Till Westmann96c1f172013-08-01 02:05:48 -0700682 (<WHERE> condition = Expression())?
Till Westmann31c21f92013-05-08 09:21:53 -0700683 {
684 return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, getVarCounter());
685 }
vinayakb38b7ca42012-03-05 05:44:15 +0000686}
687
688UpdateStatement UpdateStatement() throws ParseException:
689{
Till Westmann31c21f92013-05-08 09:21:53 -0700690 VariableExpr vars;
691 Expression target;
692 Expression condition;
693 UpdateClause uc;
694 List<UpdateClause> ucs = new ArrayList<UpdateClause>();
vinayakb38b7ca42012-03-05 05:44:15 +0000695}
696{
Till Westmann96c1f172013-08-01 02:05:48 -0700697 "update" vars = Variable() <IN> target = Expression()
698 <WHERE> condition = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700699 <LEFTPAREN> (uc = UpdateClause()
700 {
701 ucs.add(uc);
702 }
Till Westmann96c1f172013-08-01 02:05:48 -0700703 (<COMMA> uc = UpdateClause()
Till Westmann31c21f92013-05-08 09:21:53 -0700704 {
705 ucs.add(uc);
706 }
707 )*) <RIGHTPAREN>
708 {
709 return new UpdateStatement(vars, target, condition, ucs);
710 }
vinayakb38b7ca42012-03-05 05:44:15 +0000711}
712
vinayakb38b7ca42012-03-05 05:44:15 +0000713UpdateClause UpdateClause() throws ParseException:
714{
Till Westmann31c21f92013-05-08 09:21:53 -0700715 Expression target = null;
716 Expression value = null ;
717 InsertStatement is = null;
718 DeleteStatement ds = null;
719 UpdateStatement us = null;
720 Expression condition = null;
721 UpdateClause ifbranch = null;
722 UpdateClause elsebranch = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000723}
724{
Till Westmann96c1f172013-08-01 02:05:48 -0700725 "set" target = Expression() <ASSIGN> value = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -0700726 | is = InsertStatement()
727 | ds = DeleteStatement()
728 | us = UpdateStatement()
Till Westmann96c1f172013-08-01 02:05:48 -0700729 | <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
730 <THEN> ifbranch = UpdateClause()
731 [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
Till Westmann31c21f92013-05-08 09:21:53 -0700732 {
733 return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
734 }
vinayakb38b7ca42012-03-05 05:44:15 +0000735}
736
vinayakb38b7ca42012-03-05 05:44:15 +0000737Statement SetStatement() throws ParseException:
738{
739 String pn = null;
Till Westmann31c21f92013-05-08 09:21:53 -0700740 String pv = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000741}
742{
Till Westmann7d535322013-05-09 00:40:02 -0700743 "set" pn = Identifier() pv = StringLiteral()
Till Westmann31c21f92013-05-08 09:21:53 -0700744 {
Till Westmann31c21f92013-05-08 09:21:53 -0700745 return new SetStatement(pn, pv);
746 }
vinayakb38b7ca42012-03-05 05:44:15 +0000747}
748
749Statement WriteStatement() throws ParseException:
750{
Till Westmann14a20a72013-05-09 00:06:24 -0700751 String nodeName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000752 String fileName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000753 Query query;
754 String writerClass = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000755 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000756}
757{
Till Westmann96c1f172013-08-01 02:05:48 -0700758 "write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
Till Westmann7d535322013-05-09 00:40:02 -0700759 ( "using" writerClass = StringLiteral() )?
Till Westmann35a0f702013-07-01 14:06:34 -0700760 {
761 return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
vinayakb38b7ca42012-03-05 05:44:15 +0000762 }
763}
764
vinayakb38b7ca42012-03-05 05:44:15 +0000765LoadFromFileStatement LoadStatement() throws ParseException:
766{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000767 Identifier dataverseName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000768 Identifier datasetName = null;
769 boolean alreadySorted = false;
ramangrover29669d8f62013-02-11 06:03:32 +0000770 String adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000771 Map<String,String> properties;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000772 Pair<Identifier,Identifier> nameComponents = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000773}
774{
Till Westmann31c21f92013-05-08 09:21:53 -0700775 "load" <DATASET> nameComponents = QualifiedName()
vinayakb38b7ca42012-03-05 05:44:15 +0000776 {
Till Westmann31c21f92013-05-08 09:21:53 -0700777 dataverseName = nameComponents.first;
778 datasetName = nameComponents.second;
vinayakb38b7ca42012-03-05 05:44:15 +0000779 }
Till Westmann31c21f92013-05-08 09:21:53 -0700780 "using" adapterName = AdapterName() properties = Configuration()
781 ("pre-sorted"
vinayakb38b7ca42012-03-05 05:44:15 +0000782 {
Till Westmann31c21f92013-05-08 09:21:53 -0700783 alreadySorted = true;
vinayakb38b7ca42012-03-05 05:44:15 +0000784 }
785 )?
Till Westmann31c21f92013-05-08 09:21:53 -0700786 {
787 return new LoadFromFileStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
788 }
vinayakb38b7ca42012-03-05 05:44:15 +0000789}
790
vinayakb38b7ca42012-03-05 05:44:15 +0000791
Till Westmann31c21f92013-05-08 09:21:53 -0700792String AdapterName() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000793{
ramangrover29669d8f62013-02-11 06:03:32 +0000794 String adapterName = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000795}
796{
Till Westmann68d99652013-05-09 11:15:21 -0700797 adapterName = Identifier()
vinayakb38b7ca42012-03-05 05:44:15 +0000798 {
Till Westmann7d535322013-05-09 00:40:02 -0700799 return adapterName;
vinayakb38b7ca42012-03-05 05:44:15 +0000800 }
vinayakb38b7ca42012-03-05 05:44:15 +0000801}
802
Till Westmann31c21f92013-05-08 09:21:53 -0700803Statement FeedStatement() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000804{
ramangrover29a774ef22013-07-17 09:29:18 -0700805 Pair<Identifier,Identifier> feedNameComponents = null;
806 Pair<Identifier,Identifier> datasetNameComponents = null;
807
Till Westmann31c21f92013-05-08 09:21:53 -0700808 Map<String,String> configuration = null;
809 Statement stmt = null;
ramangrover29566b3a92013-05-28 09:07:10 -0700810 String policy = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000811}
812{
Till Westmann31c21f92013-05-08 09:21:53 -0700813 (
ramangrover29a774ef22013-07-17 09:29:18 -0700814 "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
Till Westmann31c21f92013-05-08 09:21:53 -0700815 {
ramangrover29a774ef22013-07-17 09:29:18 -0700816 stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
Till Westmann31c21f92013-05-08 09:21:53 -0700817 }
ramangrover29a774ef22013-07-17 09:29:18 -0700818 | "disconnect" "feed" feedNameComponents = QualifiedName() "from" <DATASET> datasetNameComponents = QualifiedName()
Till Westmann31c21f92013-05-08 09:21:53 -0700819 {
ramangrover29a774ef22013-07-17 09:29:18 -0700820 stmt = new DisconnectFeedStatement(feedNameComponents, datasetNameComponents);
Till Westmann31c21f92013-05-08 09:21:53 -0700821 }
822 )
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000823 {
Till Westmann31c21f92013-05-08 09:21:53 -0700824 return stmt;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +0000825 }
826}
827
Till Westmann31c21f92013-05-08 09:21:53 -0700828Map<String,String> Configuration() throws ParseException :
vinayakb38b7ca42012-03-05 05:44:15 +0000829{
diegogiorgini@gmail.comeb1910e2013-02-14 07:43:00 +0000830 Map<String,String> configuration = new LinkedHashMap<String,String>();
Till Westmann31c21f92013-05-08 09:21:53 -0700831 Pair<String, String> keyValuePair = null;
vinayakb38b7ca42012-03-05 05:44:15 +0000832}
833{
Till Westmann31c21f92013-05-08 09:21:53 -0700834 <LEFTPAREN> ( keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000835 {
Till Westmann31c21f92013-05-08 09:21:53 -0700836 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000837 }
Till Westmann96c1f172013-08-01 02:05:48 -0700838 ( <COMMA> keyValuePair = KeyValuePair()
vinayakb38b7ca42012-03-05 05:44:15 +0000839 {
Till Westmann31c21f92013-05-08 09:21:53 -0700840 configuration.put(keyValuePair.first, keyValuePair.second);
vinayakb38b7ca42012-03-05 05:44:15 +0000841 }
Till Westmann31c21f92013-05-08 09:21:53 -0700842 )* )? <RIGHTPAREN>
843 {
844 return configuration;
845 }
846}
847
848Pair<String, String> KeyValuePair() throws ParseException:
849{
850 String key;
851 String value;
852}
853{
Till Westmann96c1f172013-08-01 02:05:48 -0700854 <LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
Till Westmann31c21f92013-05-08 09:21:53 -0700855 {
856 return new Pair<String, String>(key, value);
vinayakb38b7ca42012-03-05 05:44:15 +0000857 }
Till Westmann31c21f92013-05-08 09:21:53 -0700858}
859
860Map<String,String> Properties() throws ParseException:
861{
862 Map<String,String> properties = new HashMap<String,String>();
863 Pair<String, String> property;
864}
865{
866 ( <LEFTPAREN> property = Property()
867 {
868 properties.put(property.first, property.second);
869 }
Till Westmann96c1f172013-08-01 02:05:48 -0700870 ( <COMMA> property = Property()
Till Westmann31c21f92013-05-08 09:21:53 -0700871 {
872 properties.put(property.first, property.second);
873 }
874 )* <RIGHTPAREN> )?
875 {
876 return properties;
877 }
878}
879
880Pair<String, String> Property() throws ParseException:
881{
882 String key;
883 String value;
884}
885{
Till Westmann96c1f172013-08-01 02:05:48 -0700886 key = Identifier() <EQ> ( value = StringLiteral() | <INTEGER_LITERAL>
Till Westmann31c21f92013-05-08 09:21:53 -0700887 {
888 try {
889 value = "" + Long.valueOf(token.image);
890 } catch (NumberFormatException nfe) {
891 throw new ParseException("inapproriate value: " + token.image);
892 }
893 }
894 )
895 {
896 return new Pair<String, String>(key.toUpperCase(), value);
897 }
vinayakb38b7ca42012-03-05 05:44:15 +0000898}
899
900TypeExpression TypeExpr() throws ParseException:
901{
902 TypeExpression typeExpr = null;
903}
904{
905 (
906 typeExpr = RecordTypeDef()
907 | typeExpr = TypeReference()
908 | typeExpr = OrderedListTypeDef()
909 | typeExpr = UnorderedListTypeDef()
910 )
911 {
912 return typeExpr;
913 }
914}
915
916RecordTypeDefinition RecordTypeDef() throws ParseException:
917{
918 RecordTypeDefinition recType = new RecordTypeDefinition();
919 RecordTypeDefinition.RecordKind recordKind = null;
920}
921{
922 ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
923 | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
Till Westmann96c1f172013-08-01 02:05:48 -0700924 <LEFTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000925 {
926 String hint = getHint(token);
927 if (hint != null) {
928 String splits[] = hint.split(" +");
929 if (splits[0].equals(GEN_FIELDS_HINT)) {
930 if (splits.length != 5) {
931 throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
932 }
933 if (!splits[1].equals("int")) {
934 throw new ParseException("The only supported type for gen-fields is int.");
935 }
936 UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
937 Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
938 recType.setUndeclaredFieldsDataGen(ufdg);
939 }
940 }
941
942 }
943 (
944 RecordField(recType)
Till Westmann96c1f172013-08-01 02:05:48 -0700945 ( <COMMA> RecordField(recType) )*
vinayakb38b7ca42012-03-05 05:44:15 +0000946 )?
Till Westmann96c1f172013-08-01 02:05:48 -0700947 <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +0000948 {
949 if (recordKind == null) {
950 recordKind = RecordTypeDefinition.RecordKind.OPEN;
951 }
952 recType.setRecordKind(recordKind);
953 return recType;
954 }
955}
956
957void RecordField(RecordTypeDefinition recType) throws ParseException:
958{
Till Westmann77cb2f42013-07-15 16:44:19 -0700959 String fieldName;
960 TypeExpression type = null;
961 boolean nullable = false;
vinayakb38b7ca42012-03-05 05:44:15 +0000962}
963{
Till Westmann77cb2f42013-07-15 16:44:19 -0700964 fieldName = Identifier()
965 {
966 String hint = getHint(token);
967 IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
968 }
Till Westmann96c1f172013-08-01 02:05:48 -0700969 <COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
Till Westmann77cb2f42013-07-15 16:44:19 -0700970 {
971 recType.addField(fieldName, type, nullable, rfdg);
972 }
vinayakb38b7ca42012-03-05 05:44:15 +0000973}
974
975TypeReferenceExpression TypeReference() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +0000976{
Till Westmann14a20a72013-05-09 00:06:24 -0700977 String id = null;
Till Westmanna4242bc2013-05-08 17:49:55 -0700978}
979{
980 id = Identifier()
981 {
Till Westmann14a20a72013-05-09 00:06:24 -0700982 return new TypeReferenceExpression(new Identifier(id));
Till Westmanna4242bc2013-05-08 17:49:55 -0700983 }
vinayakb38b7ca42012-03-05 05:44:15 +0000984}
985
986OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
987{
988 TypeExpression type = null;
989}
990{
Till Westmann96c1f172013-08-01 02:05:48 -0700991 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +0000992 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -0700993 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +0000994 {
995 return new OrderedListTypeDefinition(type);
996 }
997}
998
999
1000UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
1001{
1002 TypeExpression type = null;
1003}
1004{
Till Westmann96c1f172013-08-01 02:05:48 -07001005 <LEFTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001006 ( type = TypeExpr() )
Till Westmann96c1f172013-08-01 02:05:48 -07001007 <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001008 {
1009 return new UnorderedListTypeDefinition(type);
1010 }
1011}
1012
ramangrover299f76a5e2013-06-18 10:25:17 -07001013FunctionName FunctionName() throws ParseException:
1014{
1015 String first = null;
1016 String second = null;
1017 String third = null;
1018 boolean secondAfterDot = false;
1019}
1020{
1021 first = Identifier() ( "." second = Identifier()
1022 {
1023 secondAfterDot = true;
1024 }
1025 ("#" third = Identifier())? | "#" second = Identifier() )?
1026 {
1027 FunctionName result = new FunctionName();
1028 if (second == null) {
1029 result.dataverse = defaultDataverse;
1030 result.library = null;
1031 result.function = first;
1032 } else if (third == null) {
1033 if (secondAfterDot) {
1034 result.dataverse = first;
1035 result.library = null;
1036 result.function = second;
1037 } else {
1038 result.dataverse = defaultDataverse;
1039 result.library = first;
1040 result.function = second;
1041 }
1042 } else {
1043 result.dataverse = first;
1044 result.library = second;
1045 result.function = third;
1046 }
1047 return result;
1048 }
1049}
Till Westmann31c21f92013-05-08 09:21:53 -07001050
ramangrover299f76a5e2013-06-18 10:25:17 -07001051
1052Pair<Identifier,Identifier> TypeName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001053{
Till Westmann31c21f92013-05-08 09:21:53 -07001054 Pair<Identifier,Identifier> name = null;
1055}
1056{
1057 name = QualifiedName()
1058 {
1059 if (name.first == null) {
1060 name.first = new Identifier(defaultDataverse);
1061 }
1062 return name;
1063 }
1064}
1065
Till Westmann14a20a72013-05-09 00:06:24 -07001066String Identifier() throws ParseException:
Till Westmanna4242bc2013-05-08 17:49:55 -07001067{
Till Westmann68d99652013-05-09 11:15:21 -07001068 String lit = null;
Till Westmanna4242bc2013-05-08 17:49:55 -07001069}
1070{
1071 <IDENTIFIER>
1072 {
Till Westmann14a20a72013-05-09 00:06:24 -07001073 return token.image;
Till Westmanna4242bc2013-05-08 17:49:55 -07001074 }
Till Westmann68d99652013-05-09 11:15:21 -07001075 | lit = StringLiteral()
1076 {
1077 return lit;
1078 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001079}
1080
Till Westmann7d535322013-05-09 00:40:02 -07001081String StringLiteral() throws ParseException:
1082{
1083}
1084{
1085 <STRING_LITERAL>
1086 {
1087 return removeQuotesAndEscapes(token.image);
1088 }
1089}
1090
Till Westmann31c21f92013-05-08 09:21:53 -07001091Pair<Identifier,Identifier> QualifiedName() throws ParseException:
1092{
Till Westmann14a20a72013-05-09 00:06:24 -07001093 String first = null;
1094 String second = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001095}
1096{
Till Westmann96c1f172013-08-01 02:05:48 -07001097 first = Identifier() (<DOT> second = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001098 {
Till Westmann14a20a72013-05-09 00:06:24 -07001099 Identifier id1 = null;
1100 Identifier id2 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001101 if (second == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001102 id2 = new Identifier(first);
1103 } else
1104 {
1105 id1 = new Identifier(first);
1106 id2 = new Identifier(second);
1107 }
1108 return new Pair<Identifier,Identifier>(id1, id2);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001109 }
1110}
1111
Till Westmann31c21f92013-05-08 09:21:53 -07001112Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001113{
Till Westmann14a20a72013-05-09 00:06:24 -07001114 String first = null;
1115 String second = null;
1116 String third = null;
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001117}
1118{
Till Westmann96c1f172013-08-01 02:05:48 -07001119 first = Identifier() <DOT> second = Identifier() (<DOT> third = Identifier())?
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001120 {
Till Westmann14a20a72013-05-09 00:06:24 -07001121 Identifier id1 = null;
1122 Identifier id2 = null;
1123 Identifier id3 = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001124 if (third == null) {
Till Westmann14a20a72013-05-09 00:06:24 -07001125 id2 = new Identifier(first);
1126 id3 = new Identifier(second);
1127 } else {
1128 id1 = new Identifier(first);
1129 id2 = new Identifier(second);
1130 id3 = new Identifier(third);
1131 }
1132 return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001133 }
1134}
1135
vinayakb38b7ca42012-03-05 05:44:15 +00001136FunctionDecl FunctionDeclaration() throws ParseException:
1137{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001138 FunctionDecl funcDecl;
1139 FunctionSignature signature;
ramangrover29a13f2422012-03-15 23:01:27 +00001140 String functionName;
vinayakb38b7ca42012-03-05 05:44:15 +00001141 List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
1142 Expression funcBody;
vinayakb38b7ca42012-03-05 05:44:15 +00001143 createNewScope();
1144}
1145{
Till Westmannd7dcb122013-05-16 13:19:09 -07001146 "declare" "function" functionName = Identifier()
1147 paramList = ParameterList()
Till Westmann96c1f172013-08-01 02:05:48 -07001148 <LEFTBRACE> funcBody = Expression() <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001149 {
Till Westmannd7dcb122013-05-16 13:19:09 -07001150 signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001151 getCurrentScope().addFunctionDescriptor(signature, false);
1152 funcDecl = new FunctionDecl(signature, paramList, funcBody);
Till Westmannc6c4a742013-05-20 17:59:21 -07001153 removeCurrentScope();
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001154 return funcDecl;
vinayakb38b7ca42012-03-05 05:44:15 +00001155 }
1156}
1157
vinayakb38b7ca42012-03-05 05:44:15 +00001158
Till Westmann31c21f92013-05-08 09:21:53 -07001159Query Query() throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001160{
1161 Query query = new Query();
1162 Expression expr;
1163}
1164{
Till Westmann31c21f92013-05-08 09:21:53 -07001165 expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001166 {
1167 query.setBody(expr);
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001168 query.setVarCounter(getVarCounter());
vinayakb38b7ca42012-03-05 05:44:15 +00001169 return query;
1170 }
RamanGrover29@gmail.comc022a0d2012-07-28 05:13:44 +00001171
vinayakb38b7ca42012-03-05 05:44:15 +00001172}
1173
1174
1175
1176Expression Expression():
1177{
1178 Expression expr = null;
1179 Expression exprP = null;
1180}
1181{
1182(
1183
1184//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
1185 expr = OperatorExpr()
1186 | expr = IfThenElse()
1187 | expr = FLWOGR()
1188 | expr = QuantifiedExpression()
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001189
vinayakb38b7ca42012-03-05 05:44:15 +00001190
1191)
1192 {
1193 return (exprP==null) ? expr : exprP;
1194 }
1195}
1196
1197
1198
1199Expression OperatorExpr()throws ParseException:
1200{
1201 OperatorExpr op = null;
1202 Expression operand = null;
1203}
1204{
1205 operand = AndExpr()
1206 (
1207
Till Westmann96c1f172013-08-01 02:05:48 -07001208 <OR>
vinayakb38b7ca42012-03-05 05:44:15 +00001209 {
1210 if (op == null) {
1211 op = new OperatorExpr();
1212 op.addOperand(operand);
1213 op.setCurrentop(true);
1214 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001215 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001216 }
1217
1218 operand = AndExpr()
1219 {
1220 op.addOperand(operand);
1221 }
1222
1223 )*
1224
1225 {
1226 return op==null? operand: op;
1227 }
1228}
1229
1230Expression AndExpr()throws ParseException:
1231{
1232 OperatorExpr op = null;
1233 Expression operand = null;
1234}
1235{
1236 operand = RelExpr()
1237 (
1238
Till Westmann96c1f172013-08-01 02:05:48 -07001239 <AND>
vinayakb38b7ca42012-03-05 05:44:15 +00001240 {
1241 if (op == null) {
1242 op = new OperatorExpr();
1243 op.addOperand(operand);
1244 op.setCurrentop(true);
1245 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001246 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001247 }
1248
1249 operand = RelExpr()
1250 {
1251 op.addOperand(operand);
1252 }
1253
1254 )*
1255
1256 {
1257 return op==null? operand: op;
1258 }
1259}
1260
1261
1262
1263Expression RelExpr()throws ParseException:
1264{
1265 OperatorExpr op = null;
1266 Expression operand = null;
1267 boolean broadcast = false;
alexander.behm07617fd2012-07-25 10:13:50 +00001268 IExpressionAnnotation annotation = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001269}
1270{
1271 operand = AddExpr()
alexander.behm07617fd2012-07-25 10:13:50 +00001272 {
1273 if (operand instanceof VariableExpr) {
1274 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001275 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
alexander.behm07617fd2012-07-25 10:13:50 +00001276 broadcast = true;
vinayakb38b7ca42012-03-05 05:44:15 +00001277 }
1278 }
1279 }
1280
1281 (
Till Westmann96c1f172013-08-01 02:05:48 -07001282 LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
vinayakb38b7ca42012-03-05 05:44:15 +00001283 {
alexander.behm07617fd2012-07-25 10:13:50 +00001284 String mhint = getHint(token);
1285 if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1286 annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
1287 }
vinayakb38b7ca42012-03-05 05:44:15 +00001288 if (op == null) {
1289 op = new OperatorExpr();
1290 op.addOperand(operand, broadcast);
1291 op.setCurrentop(true);
1292 broadcast = false;
Till Westmanna4242bc2013-05-08 17:49:55 -07001293 }
1294 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001295 }
1296
1297 operand = AddExpr()
1298 {
alexander.behm07617fd2012-07-25 10:13:50 +00001299 broadcast = false;
1300 if (operand instanceof VariableExpr) {
1301 String hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001302 if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
1303 broadcast = true;
1304 }
alexander.behm07617fd2012-07-25 10:13:50 +00001305 }
vinayakb38b7ca42012-03-05 05:44:15 +00001306 op.addOperand(operand, broadcast);
1307 }
1308 )?
1309
1310 {
alexander.behm07617fd2012-07-25 10:13:50 +00001311 if (annotation != null) {
1312 op.addHint(annotation);
1313 }
vinayakb38b7ca42012-03-05 05:44:15 +00001314 return op==null? operand: op;
1315 }
1316}
1317
1318Expression AddExpr()throws ParseException:
1319{
1320 OperatorExpr op = null;
1321 Expression operand = null;
1322}
1323{
1324 operand = MultExpr()
1325
Till Westmann96c1f172013-08-01 02:05:48 -07001326 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001327 {
1328 if (op == null) {
1329 op = new OperatorExpr();
1330 op.addOperand(operand);
1331 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001332 }
1333 ((OperatorExpr)op).addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001334 }
1335
1336 operand = MultExpr()
1337 {
1338 op.addOperand(operand);
1339 }
1340 )*
1341
1342 {
1343 return op==null? operand: op;
1344 }
1345}
1346
1347Expression MultExpr()throws ParseException:
1348{
1349 OperatorExpr op = null;
1350 Expression operand = null;
1351}
1352{
1353 operand = UnionExpr()
1354
Till Westmann96c1f172013-08-01 02:05:48 -07001355 (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
vinayakb38b7ca42012-03-05 05:44:15 +00001356 {
1357 if (op == null) {
1358 op = new OperatorExpr();
1359 op.addOperand(operand);
1360 op.setCurrentop(true);
Till Westmanna4242bc2013-05-08 17:49:55 -07001361 }
1362 op.addOperator(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001363 }
1364 operand = UnionExpr()
1365 {
1366 op.addOperand(operand);
1367 }
1368 )*
1369
1370 {
1371 return op==null?operand:op;
1372 }
1373}
1374
1375Expression UnionExpr() throws ParseException:
1376{
1377 UnionExpr union = null;
1378 Expression operand1 = null;
1379 Expression operand2 = null;
1380}
1381{
1382 operand1 = UnaryExpr()
Till Westmann96c1f172013-08-01 02:05:48 -07001383 (<UNION>
vinayakb38b7ca42012-03-05 05:44:15 +00001384 (operand2 = UnaryExpr()) {
1385 if (union == null) {
1386 union = new UnionExpr();
1387 union.addExpr(operand1);
1388 }
1389 union.addExpr(operand2);
1390 } )*
1391 {
1392 return (union == null)? operand1: union;
1393 }
1394}
1395
1396Expression UnaryExpr() throws ParseException:
1397{
1398 Expression uexpr = null;
1399 Expression expr = null;
1400}
1401{
Till Westmann96c1f172013-08-01 02:05:48 -07001402 ( (<PLUS> | <MINUS>)
vinayakb38b7ca42012-03-05 05:44:15 +00001403 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001404 uexpr = new UnaryExpr();
1405 if("+".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001406 ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
Till Westmanna4242bc2013-05-08 17:49:55 -07001407 else if("-".equals(token.image))
vinayakb38b7ca42012-03-05 05:44:15 +00001408 ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
1409 else
1410 throw new ParseException();
1411 }
1412 )?
1413
1414 expr = ValueExpr()
1415 {
1416 if(uexpr!=null){
1417 ((UnaryExpr)uexpr).setExpr(expr);
1418 return uexpr;
1419 }
1420 else{
1421 return expr;
1422 }
1423 }
1424}
1425
Till Westmann04478e72013-05-13 23:01:34 -07001426Expression ValueExpr()throws ParseException:
vinayakb38b7ca42012-03-05 05:44:15 +00001427{
1428 Expression expr = null;
1429 Identifier ident = null;
1430 AbstractAccessor fa = null;
1431 int index;
vinayakb38b7ca42012-03-05 05:44:15 +00001432}
1433{
Till Westmann04478e72013-05-13 23:01:34 -07001434 expr = PrimaryExpr() ( ident = Field()
vinayakb38b7ca42012-03-05 05:44:15 +00001435 {
Till Westmann04478e72013-05-13 23:01:34 -07001436 fa = (fa == null ? new FieldAccessor(expr, ident)
1437 : new FieldAccessor(fa, ident));
1438 }
1439 | index = Index()
1440 {
1441 fa = (fa == null ? new IndexAccessor(expr, index)
1442 : new IndexAccessor(fa, index));
1443 }
1444 )*
1445 {
1446 return fa == null ? expr : fa;
1447 }
vinayakb38b7ca42012-03-05 05:44:15 +00001448}
1449
1450Identifier Field() throws ParseException:
1451{
Till Westmann14a20a72013-05-09 00:06:24 -07001452 String ident = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001453}
1454{
Till Westmann96c1f172013-08-01 02:05:48 -07001455 <DOT> ident = Identifier()
Till Westmanna4242bc2013-05-08 17:49:55 -07001456 {
Till Westmann14a20a72013-05-09 00:06:24 -07001457 return new Identifier(ident);
Till Westmanna4242bc2013-05-08 17:49:55 -07001458 }
vinayakb38b7ca42012-03-05 05:44:15 +00001459}
1460
1461int Index() throws ParseException:
1462{
1463 Expression expr = null;
1464 int idx = -2;
1465}
1466{
Till Westmann96c1f172013-08-01 02:05:48 -07001467 <LEFTBRACKET> ( expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001468 {
1469 if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
1470 {
ilovesoupc9fef1d2012-07-08 19:30:42 +00001471 Literal lit = ((LiteralExpr)expr).getValue();
1472 if(lit.getLiteralType() == Literal.Type.INTEGER ||
1473 lit.getLiteralType() == Literal.Type.LONG) {
vinayakb38b7ca42012-03-05 05:44:15 +00001474 idx = Integer.valueOf(lit.getStringValue());
ilovesoupc9fef1d2012-07-08 19:30:42 +00001475 }
vinayakb38b7ca42012-03-05 05:44:15 +00001476 else {
1477 throw new ParseException("Index should be an INTEGER");
1478 }
1479 }
1480
1481 }
1482
Till Westmann96c1f172013-08-01 02:05:48 -07001483 | <QUES>
vinayakb38b7ca42012-03-05 05:44:15 +00001484 {
1485 idx = IndexAccessor.ANY;
1486 // ANY
1487 }
1488
1489 )
1490
Till Westmann96c1f172013-08-01 02:05:48 -07001491 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001492 {
1493 return idx;
1494 }
1495}
1496
1497
1498Expression PrimaryExpr()throws ParseException:
1499{
1500 Expression expr = null;
1501}
1502{
Till Westmann68d99652013-05-09 11:15:21 -07001503 ( LOOKAHEAD(2)
1504 expr = FunctionCallExpr()
1505 | expr = Literal()
1506 | expr = DatasetAccessExpression()
1507 | expr = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00001508 {
1509 if(((VariableExpr)expr).getIsNewVar() == true)
Till Westmann68d99652013-05-09 11:15:21 -07001510 throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001511 }
Till Westmann68d99652013-05-09 11:15:21 -07001512 | expr = ListConstructor()
1513 | expr = RecordConstructor()
1514 | expr = ParenthesizedExpression()
1515 )
1516 {
1517 return expr;
1518 }
vinayakb38b7ca42012-03-05 05:44:15 +00001519}
1520
1521Expression Literal() throws ParseException:
1522{
vinayakb38b7ca42012-03-05 05:44:15 +00001523 LiteralExpr lit = new LiteralExpr();
Till Westmann7d535322013-05-09 00:40:02 -07001524 String str = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001525}
1526{
Till Westmann7d535322013-05-09 00:40:02 -07001527 ( str = StringLiteral()
vinayakb38b7ca42012-03-05 05:44:15 +00001528 {
Till Westmann7d535322013-05-09 00:40:02 -07001529 lit.setValue(new StringLiteral(str));
Till Westmanna4242bc2013-05-08 17:49:55 -07001530 }
1531 | <INTEGER_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001532 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001533 try {
1534 lit.setValue(new IntegerLiteral(new Integer(token.image)));
1535 } catch(NumberFormatException ex) {
1536 lit.setValue(new LongIntegerLiteral(new Long(token.image)));
1537 }
1538 }
1539 | <FLOAT_LITERAL>
vinayakb38b7ca42012-03-05 05:44:15 +00001540 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001541 lit.setValue(new FloatLiteral(new Float(token.image)));
1542 }
1543 | <DOUBLE_LITERAL>
1544 {
1545 lit.setValue(new DoubleLiteral(new Double(token.image)));
1546 }
1547 | <NULL>
1548 {
1549 lit.setValue(NullLiteral.INSTANCE);
1550 }
1551 | <TRUE>
1552 {
1553 lit.setValue(TrueLiteral.INSTANCE);
1554 }
1555 | <FALSE>
1556 {
1557 lit.setValue(FalseLiteral.INSTANCE);
1558 }
1559 )
vinayakb38b7ca42012-03-05 05:44:15 +00001560 {
1561 return lit;
1562 }
1563}
1564
1565
1566VariableExpr VariableRef() throws ParseException:
1567{
1568 VariableExpr varExp = new VariableExpr();
1569 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001570}
1571{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001572 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001573 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001574 String varName = token.image;
vinayakb38b7ca42012-03-05 05:44:15 +00001575 Identifier ident = lookupSymbol(varName);
1576 if (isInForbiddenScopes(varName)) {
1577 throw new ParseException("Inside limit clauses, it is disallowed to reference a variable having the same name as any variable bound in the same scope as the limit clause.");
1578 }
1579 if(ident != null) { // exist such ident
1580 varExp.setIsNewVar(false);
1581 varExp.setVar((VarIdentifier)ident);
1582 } else {
1583 varExp.setVar(var);
1584 }
Till Westmanna4242bc2013-05-08 17:49:55 -07001585 var.setValue(varName);
vinayakb38b7ca42012-03-05 05:44:15 +00001586 return varExp;
1587 }
1588}
1589
1590
1591VariableExpr Variable() throws ParseException:
1592{
1593 VariableExpr varExp = new VariableExpr();
1594 VarIdentifier var = new VarIdentifier();
vinayakb38b7ca42012-03-05 05:44:15 +00001595}
1596{
Till Westmann4f58e1a2013-05-20 18:29:54 -07001597 <VARIABLE>
vinayakb38b7ca42012-03-05 05:44:15 +00001598 {
Till Westmanna4242bc2013-05-08 17:49:55 -07001599 Identifier ident = lookupSymbol(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001600 if(ident != null) { // exist such ident
1601 varExp.setIsNewVar(false);
1602 }
1603 varExp.setVar(var);
Till Westmanna4242bc2013-05-08 17:49:55 -07001604 var.setValue(token.image);
vinayakb38b7ca42012-03-05 05:44:15 +00001605 return varExp;
1606 }
1607}
1608
1609Expression ListConstructor() throws ParseException:
1610{
1611 Expression expr = null;
1612}
1613{
1614 (
1615 expr = OrderedListConstructor() | expr = UnorderedListConstructor()
1616 )
1617
1618 {
1619 return expr;
1620 }
1621}
1622
1623
1624ListConstructor OrderedListConstructor() throws ParseException:
1625{
1626 ListConstructor expr = new ListConstructor();
1627 Expression tmp = null;
1628 List<Expression> exprList = new ArrayList<Expression>();
1629 expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
1630}
1631{
1632
Till Westmann96c1f172013-08-01 02:05:48 -07001633 <LEFTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001634 ( tmp = Expression()
1635 {
1636 exprList.add(tmp);
1637 }
1638
Till Westmann96c1f172013-08-01 02:05:48 -07001639 (<COMMA> tmp = Expression() { exprList.add(tmp); })*
vinayakb38b7ca42012-03-05 05:44:15 +00001640 )?
1641
Till Westmann96c1f172013-08-01 02:05:48 -07001642 <RIGHTBRACKET>
vinayakb38b7ca42012-03-05 05:44:15 +00001643
1644 {
1645 expr.setExprList(exprList);
1646 return expr;
1647 }
1648}
1649
1650ListConstructor UnorderedListConstructor() throws ParseException:
1651{
1652 ListConstructor expr = new ListConstructor();
1653 Expression tmp = null;
1654 List<Expression> exprList = new ArrayList<Expression>();
1655 expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
1656}
1657{
1658
Till Westmann96c1f172013-08-01 02:05:48 -07001659 <LEFTDBLBRACE> ( tmp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001660 {
1661 exprList.add(tmp);
1662 }
Till Westmann96c1f172013-08-01 02:05:48 -07001663 (<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001664 {
1665 expr.setExprList(exprList);
1666 return expr;
1667 }
1668}
1669
1670RecordConstructor RecordConstructor() throws ParseException:
1671{
1672 RecordConstructor expr = new RecordConstructor();
1673 FieldBinding tmp = null;
1674 List<FieldBinding> fbList = new ArrayList<FieldBinding>();
1675}
1676{
Till Westmann96c1f172013-08-01 02:05:48 -07001677 <LEFTBRACE> (tmp = FieldBinding()
vinayakb38b7ca42012-03-05 05:44:15 +00001678 {
1679 fbList.add(tmp);
1680 }
Till Westmann96c1f172013-08-01 02:05:48 -07001681 (<COMMA> tmp = FieldBinding() { fbList.add(tmp); })*)? <RIGHTBRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00001682 {
1683 expr.setFbList(fbList);
1684 return expr;
1685 }
1686}
1687
1688FieldBinding FieldBinding() throws ParseException:
1689{
1690 FieldBinding fb = new FieldBinding();
1691 Expression left, right;
1692}
1693{
Till Westmann96c1f172013-08-01 02:05:48 -07001694 left = Expression() <COLON> right = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001695 {
1696 fb.setLeftExpr(left);
1697 fb.setRightExpr(right);
1698 return fb;
1699 }
1700}
1701
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001702
vinayakb38b7ca42012-03-05 05:44:15 +00001703Expression FunctionCallExpr() throws ParseException:
1704{
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001705 CallExpr callExpr;
alexander.behm07617fd2012-07-25 10:13:50 +00001706 List<Expression> argList = new ArrayList<Expression>();
vinayakb38b7ca42012-03-05 05:44:15 +00001707 Expression tmp;
1708 int arity = 0;
ramangrover299f76a5e2013-06-18 10:25:17 -07001709 FunctionName funcName = null;
Till Westmann31c21f92013-05-08 09:21:53 -07001710 String hint = null;
vinayakb38b7ca42012-03-05 05:44:15 +00001711}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001712{
ramangrover299f76a5e2013-06-18 10:25:17 -07001713 funcName = FunctionName()
vinayakb38b7ca42012-03-05 05:44:15 +00001714 {
Till Westmann31c21f92013-05-08 09:21:53 -07001715 hint = getHint(token);
vinayakb38b7ca42012-03-05 05:44:15 +00001716 }
Till Westmann31c21f92013-05-08 09:21:53 -07001717 <LEFTPAREN> (tmp = Expression()
1718 {
1719 argList.add(tmp);
1720 arity ++;
1721 }
Till Westmann96c1f172013-08-01 02:05:48 -07001722 (<COMMA> tmp = Expression()
Till Westmann31c21f92013-05-08 09:21:53 -07001723 {
1724 argList.add(tmp);
1725 arity++;
1726 }
1727 )*)? <RIGHTPAREN>
1728 {
ramangrover299f76a5e2013-06-18 10:25:17 -07001729 // TODO use funcName.library
ramangrover29bdba1a82013-06-21 17:17:52 -07001730 String fqFunctionName = funcName.library == null ? funcName.function : funcName.library + "#" + funcName.function;
ramangrover299f76a5e2013-06-18 10:25:17 -07001731 FunctionSignature signature
ramangrover29bdba1a82013-06-21 17:17:52 -07001732 = lookupFunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001733 if (signature == null) {
ramangrover29bdba1a82013-06-21 17:17:52 -07001734 signature = new FunctionSignature(funcName.dataverse, fqFunctionName, arity);
Till Westmann31c21f92013-05-08 09:21:53 -07001735 }
1736 callExpr = new CallExpr(signature,argList);
1737 if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) {
1738 callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE);
1739 }
1740 return callExpr;
1741 }
vinayakb38b7ca42012-03-05 05:44:15 +00001742}
1743
ramangrover29@gmail.com5f248e12013-04-11 01:03:09 +00001744
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001745Expression DatasetAccessExpression() throws ParseException:
1746{
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001747 String funcName;
Till Westmann14a20a72013-05-09 00:06:24 -07001748 String arg1 = null;
1749 String arg2 = null;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001750 Expression nameArg;
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001751}
1752{
Till Westmann14a20a72013-05-09 00:06:24 -07001753 <DATASET>
1754 {
Till Westmann14a20a72013-05-09 00:06:24 -07001755 funcName = token.image;
1756 }
Till Westmann96c1f172013-08-01 02:05:48 -07001757 ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
Till Westmann14a20a72013-05-09 00:06:24 -07001758 {
1759 String name = arg2 == null ? arg1 : arg1 + "." + arg2;
Till Westmann1f7a2362013-05-24 08:43:40 -07001760 LiteralExpr ds = new LiteralExpr();
Till Westmann14a20a72013-05-09 00:06:24 -07001761 ds.setValue( new StringLiteral(name) );
Till Westmann1f7a2362013-05-24 08:43:40 -07001762 nameArg = ds;
Till Westmann14a20a72013-05-09 00:06:24 -07001763 }
Till Westmann1f7a2362013-05-24 08:43:40 -07001764 | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
Till Westmann14a20a72013-05-09 00:06:24 -07001765 {
Till Westmann1f7a2362013-05-24 08:43:40 -07001766 String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
1767 FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
1768 if (signature == null) {
1769 signature = new FunctionSignature(dataverse, funcName, 1);
1770 }
1771 List<Expression> argList = new ArrayList<Expression>();
Till Westmann14a20a72013-05-09 00:06:24 -07001772 argList.add(nameArg);
Till Westmann1f7a2362013-05-24 08:43:40 -07001773 return new CallExpr(signature, argList);
Till Westmann14a20a72013-05-09 00:06:24 -07001774 }
pouria.pirzadeh@gmail.comfa890742013-03-07 23:59:21 +00001775}
RamanGrover29@gmail.com58cf3302012-11-09 00:27:45 +00001776
vinayakb38b7ca42012-03-05 05:44:15 +00001777Expression ParenthesizedExpression() throws ParseException:
1778{
1779 Expression expr;
1780}
1781{
1782 <LEFTPAREN> expr = Expression() <RIGHTPAREN>
1783 {
1784 return expr;
1785 }
1786}
1787
1788Expression IfThenElse() throws ParseException:
1789{
1790 Expression condExpr;
1791 Expression thenExpr;
1792 Expression elseExpr;
1793 IfExpr ifExpr = new IfExpr();
1794}
1795{
Till Westmann96c1f172013-08-01 02:05:48 -07001796 <IF> <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> <THEN> thenExpr = Expression() <ELSE> elseExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001797
1798 {
1799 ifExpr.setCondExpr(condExpr);
1800 ifExpr.setThenExpr(thenExpr);
1801 ifExpr.setElseExpr(elseExpr);
1802 return ifExpr;
1803 }
1804}
1805
1806Expression FLWOGR() throws ParseException:
1807{
1808 FLWOGRExpression flworg = new FLWOGRExpression();
1809 List<Clause> clauseList = new ArrayList<Clause>();
1810 Expression returnExpr;
1811 Clause tmp;
1812 createNewScope();
1813}
1814{
1815 (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
Till Westmann96c1f172013-08-01 02:05:48 -07001816 (tmp = Clause() {clauseList.add(tmp);})* <RETURN> returnExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001817
1818 {
1819 flworg.setClauseList(clauseList);
1820 flworg.setReturnExpr(returnExpr);
1821 removeCurrentScope();
1822 return flworg;
1823 }
1824}
1825
1826Clause Clause()throws ParseException :
1827{
1828 Clause clause;
1829}
1830{
1831 (
1832 clause = ForClause()
1833 | clause = LetClause()
1834 | clause = WhereClause()
1835 | clause = OrderbyClause()
1836 | clause = GroupClause()
1837 | clause = LimitClause()
1838 | clause = DistinctClause()
vinayakb38b7ca42012-03-05 05:44:15 +00001839 )
1840 {
1841 return clause;
1842 }
1843}
1844
1845Clause ForClause()throws ParseException :
1846{
1847 ForClause fc = new ForClause();
1848 VariableExpr varExp;
1849 VariableExpr varPos = null;
1850 Expression inExp;
1851 extendCurrentScope();
1852}
1853{
Till Westmann96c1f172013-08-01 02:05:48 -07001854 <FOR> varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
vinayakb38b7ca42012-03-05 05:44:15 +00001855 {
1856 fc.setVarExpr(varExp);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001857 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001858 fc.setInExpr(inExp);
1859 if (varPos != null) {
1860 fc.setPosExpr(varPos);
Vinayak Borkar62e66c02013-05-28 13:56:11 -07001861 getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001862 }
1863 return fc;
1864 }
1865}
1866
1867Clause LetClause() throws ParseException:
1868{
1869 LetClause lc = new LetClause();
1870 VariableExpr varExp;
1871 Expression beExp;
1872 extendCurrentScope();
1873}
1874{
Till Westmann96c1f172013-08-01 02:05:48 -07001875 <LET> varExp = Variable() <ASSIGN> beExp = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001876 {
1877 getCurrentScope().addNewVarSymbolToScope(varExp.getVar());
vinayakb38b7ca42012-03-05 05:44:15 +00001878 lc.setVarExpr(varExp);
1879 lc.setBeExpr(beExp);
1880 return lc;
1881 }
1882}
1883
1884Clause WhereClause()throws ParseException :
1885{
1886 WhereClause wc = new WhereClause();
1887 Expression whereExpr;
1888}
1889{
Till Westmann96c1f172013-08-01 02:05:48 -07001890 <WHERE> whereExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001891 {
1892 wc.setWhereExpr(whereExpr);
1893 return wc;
1894 }
1895}
1896
1897Clause OrderbyClause()throws ParseException :
1898{
1899 OrderbyClause oc = new OrderbyClause();
1900 Expression orderbyExpr;
1901 List<Expression> orderbyList = new ArrayList<Expression>();
1902 List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
1903 int numOfOrderby = 0;
1904}
1905{
1906 (
Till Westmann96c1f172013-08-01 02:05:48 -07001907 <ORDER>
vinayakb38b7ca42012-03-05 05:44:15 +00001908 {
1909 String hint = getHint(token);
1910 if (hint != null && hint.startsWith(INMEMORY_HINT)) {
1911 String splits[] = hint.split(" +");
1912 int numFrames = Integer.parseInt(splits[1]);
1913 int numTuples = Integer.parseInt(splits[2]);
1914 oc.setNumFrames(numFrames);
1915 oc.setNumTuples(numTuples);
1916 }
1917 }
Till Westmann96c1f172013-08-01 02:05:48 -07001918 <BY> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001919 {
1920 orderbyList.add(orderbyExpr);
1921 OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
1922 }
Till Westmann96c1f172013-08-01 02:05:48 -07001923 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1924 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001925 {
1926 modifierList.add(modif);
1927 }
1928
Till Westmann96c1f172013-08-01 02:05:48 -07001929 (<COMMA> orderbyExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001930 {
1931 orderbyList.add(orderbyExpr);
1932 modif = OrderbyClause.OrderModifier.ASC;
1933 }
Till Westmann96c1f172013-08-01 02:05:48 -07001934 ( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
1935 | (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
vinayakb38b7ca42012-03-05 05:44:15 +00001936 {
1937 modifierList.add(modif);
1938 }
1939 )*
1940)
1941 {
1942 oc.setModifierList(modifierList);
1943 oc.setOrderbyList(orderbyList);
1944 return oc;
1945 }
1946}
1947Clause GroupClause()throws ParseException :
1948{
1949 GroupbyClause gbc = new GroupbyClause();
1950 // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
1951 List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
1952 List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
1953 List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
1954 VariableExpr var = null;
1955 VariableExpr withVar = null;
1956 Expression expr = null;
1957 VariableExpr decorVar = null;
1958 Expression decorExpr = null;
1959}
1960{
1961 {
1962 Scope newScope = extendCurrentScopeNoPush(true);
1963 // extendCurrentScope(true);
1964 }
Till Westmann96c1f172013-08-01 02:05:48 -07001965 <GROUP>
vinayakb38b7ca42012-03-05 05:44:15 +00001966 {
1967 String hint = getHint(token);
1968 if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
1969 gbc.setHashGroupByHint(true);
1970 }
1971 }
Till Westmann96c1f172013-08-01 02:05:48 -07001972 <BY> (LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00001973 {
1974 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07001975 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00001976 expr = Expression()
1977 {
1978 GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
1979 vePairList.add(pair1);
1980 }
Till Westmann96c1f172013-08-01 02:05:48 -07001981 (<COMMA> ( LOOKAHEAD(2) var = Variable()
vinayakb38b7ca42012-03-05 05:44:15 +00001982 {
1983 newScope.addNewVarSymbolToScope(var.getVar());
Till Westmann96c1f172013-08-01 02:05:48 -07001984 } <ASSIGN>)?
vinayakb38b7ca42012-03-05 05:44:15 +00001985 expr = Expression()
1986 {
1987 GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
1988 vePairList.add(pair2);
1989 }
1990 )*
Till Westmann96c1f172013-08-01 02:05:48 -07001991 (<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001992 {
1993 newScope.addNewVarSymbolToScope(decorVar.getVar());
1994 GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
1995 decorPairList.add(pair3);
1996 }
Till Westmann96c1f172013-08-01 02:05:48 -07001997 (<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00001998 {
1999 newScope.addNewVarSymbolToScope(decorVar.getVar());
2000 GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
2001 decorPairList.add(pair4);
2002 }
2003 )*
2004 )?
Till Westmann96c1f172013-08-01 02:05:48 -07002005 <WITH> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002006 {
2007 if(withVar.getIsNewVar()==true)
2008 throw new ParseException("can't find variable " + withVar.getVar());
2009 withVarList.add(withVar);
2010 newScope.addNewVarSymbolToScope(withVar.getVar());
2011 }
Till Westmann96c1f172013-08-01 02:05:48 -07002012 (<COMMA> withVar = VariableRef()
vinayakb38b7ca42012-03-05 05:44:15 +00002013 {
2014 if(withVar.getIsNewVar()==true)
2015 throw new ParseException("can't find variable " + withVar.getVar());
2016 withVarList.add(withVar);
2017 newScope.addNewVarSymbolToScope(withVar.getVar());
2018 })*
2019 {
2020 gbc.setGbyPairList(vePairList);
2021 gbc.setDecorPairList(decorPairList);
2022 gbc.setWithVarList(withVarList);
2023 replaceCurrentScope(newScope);
2024 return gbc;
2025 }
2026}
2027
2028
2029LimitClause LimitClause() throws ParseException:
2030{
2031 LimitClause lc = new LimitClause();
2032 Expression expr;
2033 pushForbiddenScope(getCurrentScope());
2034}
2035{
Till Westmann96c1f172013-08-01 02:05:48 -07002036 <LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
2037 (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
vinayakb38b7ca42012-03-05 05:44:15 +00002038
2039 {
2040 popForbiddenScope();
2041 return lc;
2042 }
2043}
2044
2045DistinctClause DistinctClause() throws ParseException:
2046{
2047 List<Expression> exprs = new ArrayList<Expression>();
2048 Expression expr;
2049}
2050{
Till Westmann96c1f172013-08-01 02:05:48 -07002051 <DISTINCT> <BY> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002052 {
2053 exprs.add(expr);
2054 }
Till Westmann96c1f172013-08-01 02:05:48 -07002055 (<COMMA> expr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002056 {
2057 exprs.add(expr);
2058 }
2059 )*
2060 {
2061 return new DistinctClause(exprs);
2062 }
2063}
2064
vinayakb38b7ca42012-03-05 05:44:15 +00002065QuantifiedExpression QuantifiedExpression()throws ParseException:
2066{
2067 QuantifiedExpression qc = new QuantifiedExpression();
2068 List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
2069 Expression satisfiesExpr;
2070 VariableExpr var;
2071 Expression inExpr;
2072 QuantifiedPair pair;
2073}
2074{
2075 {
2076 createNewScope();
2077 }
2078
Till Westmann96c1f172013-08-01 02:05:48 -07002079 ( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
2080 | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
2081 var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002082 {
2083 pair = new QuantifiedPair(var, inExpr);
2084 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2085 quantifiedList.add(pair);
2086 }
2087 (
Till Westmann96c1f172013-08-01 02:05:48 -07002088 <COMMA> var = Variable() <IN> inExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002089 {
2090 pair = new QuantifiedPair(var, inExpr);
2091 getCurrentScope().addNewVarSymbolToScope(var.getVar());
2092 quantifiedList.add(pair);
2093 }
2094 )*
Till Westmann96c1f172013-08-01 02:05:48 -07002095 <SATISFIES> satisfiesExpr = Expression()
vinayakb38b7ca42012-03-05 05:44:15 +00002096 {
2097 qc.setSatisfiesExpr(satisfiesExpr);
2098 qc.setQuantifiedList(quantifiedList);
2099 removeCurrentScope();
2100 return qc;
2101 }
2102}
2103
2104TOKEN_MGR_DECLS:
2105{
Till Westmann96c1f172013-08-01 02:05:48 -07002106 public int commentDepth = 0;
2107 public IntStack lexerStateStack = new IntStack();
2108
2109 public void pushState() {
2110 lexerStateStack.push( curLexState );
2111 }
2112
2113 public void popState() {
2114 if (lexerStateStack.size() > 0) {
2115 SwitchTo( lexerStateStack.pop() );
2116 } else {
2117 throw new RuntimeException();
2118 }
2119 }
vinayakb38b7ca42012-03-05 05:44:15 +00002120}
2121
Till Westmann96c1f172013-08-01 02:05:48 -07002122<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002123TOKEN :
2124{
Till Westmann5df7b452013-08-02 13:07:16 -07002125 <ASC : "asc">
2126 | <AT : "at">
2127 | <BY : "by">
2128 | <DATASET : "dataset">
2129 | <DECOR : "decor">
2130 | <DESC : "desc">
2131 | <DISTINCT : "distinct">
2132 | <ELSE : "else">
2133 | <EVERY : "every">
2134 | <FOR : "for">
2135 | <GROUP : "group">
2136 | <IF : "if">
2137 | <IN : "in">
2138 | <LET : "let">
2139 | <LIMIT : "limit">
2140 | <OFFSET : "offset">
2141 | <ORDER : "order">
2142 | <RETURN : "return">
2143 | <SATISFIES : "satisfies">
2144 | <SOME : "some">
2145 | <THEN : "then">
2146 | <UNION : "union">
2147 | <WHERE : "where">
2148 | <WITH : "with">
vinayakb38b7ca42012-03-05 05:44:15 +00002149}
2150
Till Westmann96c1f172013-08-01 02:05:48 -07002151<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002152TOKEN :
2153{
Till Westmann5df7b452013-08-02 13:07:16 -07002154 <CARET : "^">
2155 | <DIV : "/">
2156 | <IDIV : "idiv">
2157 | <MINUS : "-">
2158 | <MOD : "%">
2159 | <MUL : "*">
2160 | <PLUS : "+">
2161
2162 | <LEFTPAREN : "(">
2163 | <RIGHTPAREN : ")">
2164 | <LEFTBRACKET : "[">
2165 | <RIGHTBRACKET : "]">
2166
2167 | <COLON : ":">
2168 | <COMMA : ",">
2169 | <DOT : ".">
2170 | <QUES : "?">
2171
2172 | <LT : "<">
2173 | <GT : ">">
2174 | <LE : "<=">
2175 | <GE : ">=">
2176 | <EQ : "=">
2177 | <NE : "!=">
2178 | <SIMILAR : "~=">
2179 | <ASSIGN : ":=">
2180
2181 | <AND : "and">
2182 | <OR : "or">
vinayakb38b7ca42012-03-05 05:44:15 +00002183}
2184
Till Westmann96c1f172013-08-01 02:05:48 -07002185<DEFAULT,IN_DBL_BRACE>
2186TOKEN :
2187{
Till Westmann5df7b452013-08-02 13:07:16 -07002188 <LEFTBRACE : "{"> { pushState(); } : DEFAULT
vinayakb38b7ca42012-03-05 05:44:15 +00002189}
2190
2191<DEFAULT>
2192TOKEN :
2193{
Till Westmann5df7b452013-08-02 13:07:16 -07002194 <RIGHTBRACE : "}"> { popState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002195}
2196
Till Westmann96c1f172013-08-01 02:05:48 -07002197<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002198TOKEN :
2199{
Till Westmann5df7b452013-08-02 13:07:16 -07002200 <LEFTDBLBRACE : "{{"> { pushState(); } : IN_DBL_BRACE
vinayakb38b7ca42012-03-05 05:44:15 +00002201}
2202
Till Westmann96c1f172013-08-01 02:05:48 -07002203<IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002204TOKEN :
2205{
Till Westmann5df7b452013-08-02 13:07:16 -07002206 <RIGHTDBLBRACE : "}}"> { popState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002207}
2208
Till Westmann96c1f172013-08-01 02:05:48 -07002209<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002210TOKEN :
2211{
Till Westmann5df7b452013-08-02 13:07:16 -07002212 <INTEGER_LITERAL : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002213}
2214
Till Westmann96c1f172013-08-01 02:05:48 -07002215<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002216TOKEN :
2217{
Till Westmann5df7b452013-08-02 13:07:16 -07002218 <NULL : "null">
2219 | <TRUE : "true">
2220 | <FALSE : "false">
vinayakb38b7ca42012-03-05 05:44:15 +00002221}
2222
Till Westmann96c1f172013-08-01 02:05:48 -07002223<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002224TOKEN :
2225{
Till Westmann5df7b452013-08-02 13:07:16 -07002226 <#DIGIT : ["0" - "9"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002227}
2228
Till Westmann96c1f172013-08-01 02:05:48 -07002229<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002230TOKEN:
2231{
Till Westmann5df7b452013-08-02 13:07:16 -07002232 < DOUBLE_LITERAL: <DIGITS>
Till Westmannaf0551c2013-07-23 14:53:31 -07002233 | <DIGITS> ( "." <DIGITS> )?
2234 | "." <DIGITS>
Till Westmann5df7b452013-08-02 13:07:16 -07002235 >
2236 | < FLOAT_LITERAL: <DIGITS> ( "f" | "F" )
Till Westmannaf0551c2013-07-23 14:53:31 -07002237 | <DIGITS> ( "." <DIGITS> ( "f" | "F" ) )?
2238 | "." <DIGITS> ( "f" | "F" )
Till Westmann5df7b452013-08-02 13:07:16 -07002239 >
2240 | <DIGITS : (<DIGIT>)+ >
vinayakb38b7ca42012-03-05 05:44:15 +00002241}
2242
Till Westmann96c1f172013-08-01 02:05:48 -07002243<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002244TOKEN :
2245{
Till Westmann5df7b452013-08-02 13:07:16 -07002246 <#LETTER : ["A" - "Z", "a" - "z"]>
2247 | <SPECIALCHARS : ["$", "_", "-"]>
vinayakb38b7ca42012-03-05 05:44:15 +00002248}
2249
Till Westmann96c1f172013-08-01 02:05:48 -07002250<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002251TOKEN :
2252{
Till Westmann5df7b452013-08-02 13:07:16 -07002253 <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")>
2254 | < #EscapeQuot: "\\\"" >
2255 | < #EscapeApos: "\\\'" >
vinayakb38b7ca42012-03-05 05:44:15 +00002256}
2257
Till Westmann96c1f172013-08-01 02:05:48 -07002258<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002259TOKEN :
2260{
Till Westmann5df7b452013-08-02 13:07:16 -07002261 <IDENTIFIER : <LETTER> (<LETTER> | <DIGIT> | <SPECIALCHARS>)*>
vinayakb38b7ca42012-03-05 05:44:15 +00002262}
2263
Till Westmann96c1f172013-08-01 02:05:48 -07002264<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002265TOKEN :
2266{
Till Westmann5df7b452013-08-02 13:07:16 -07002267 <VARIABLE : "$" <LETTER> (<LETTER> | <DIGIT> | "_")*>
vinayakb38b7ca42012-03-05 05:44:15 +00002268}
2269
Till Westmann96c1f172013-08-01 02:05:48 -07002270<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002271SKIP:
2272{
2273 " "
Till Westmann5df7b452013-08-02 13:07:16 -07002274 | "\t"
2275 | "\r"
2276 | "\n"
vinayakb38b7ca42012-03-05 05:44:15 +00002277}
2278
Till Westmann96c1f172013-08-01 02:05:48 -07002279<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002280SKIP:
2281{
Till Westmann5df7b452013-08-02 13:07:16 -07002282 <"//" (~["\n"])* "\n">
vinayakb38b7ca42012-03-05 05:44:15 +00002283}
2284
Till Westmann96c1f172013-08-01 02:05:48 -07002285<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002286SKIP:
2287{
Till Westmann5df7b452013-08-02 13:07:16 -07002288 <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
vinayakb38b7ca42012-03-05 05:44:15 +00002289}
2290
Till Westmann96c1f172013-08-01 02:05:48 -07002291<DEFAULT,IN_DBL_BRACE>
vinayakb38b7ca42012-03-05 05:44:15 +00002292SKIP:
2293{
Till Westmann96c1f172013-08-01 02:05:48 -07002294 <"/*"> { pushState(); } : INSIDE_COMMENT
vinayakb38b7ca42012-03-05 05:44:15 +00002295}
2296
2297<INSIDE_COMMENT>
2298SPECIAL_TOKEN:
2299{
Till Westmann5df7b452013-08-02 13:07:16 -07002300 <"+"(" ")*(~["*"])*>
vinayakb38b7ca42012-03-05 05:44:15 +00002301}
2302
2303<INSIDE_COMMENT>
2304SKIP:
2305{
Till Westmann96c1f172013-08-01 02:05:48 -07002306 <"/*"> { pushState(); }
vinayakb38b7ca42012-03-05 05:44:15 +00002307}
2308
2309<INSIDE_COMMENT>
2310SKIP:
2311{
Till Westmann96c1f172013-08-01 02:05:48 -07002312 <"*/"> { popState(); }
Till Westmann5df7b452013-08-02 13:07:16 -07002313 | <~[]>
vinayakb38b7ca42012-03-05 05:44:15 +00002314}