vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1 | options { |
| 2 | |
| 3 | |
| 4 | STATIC = false; |
| 5 | |
| 6 | } |
| 7 | |
| 8 | |
| 9 | PARSER_BEGIN(AQLParser) |
| 10 | |
| 11 | package edu.uci.ics.asterix.aql.parser; |
| 12 | |
| 13 | import java.io.*; |
| 14 | import java.util.List; |
| 15 | import java.util.ArrayList; |
| 16 | import java.util.Stack; |
| 17 | |
| 18 | import java.util.Map; |
| 19 | import java.util.HashMap; |
diegogiorgini@gmail.com | eb1910e | 2013-02-14 07:43:00 +0000 | [diff] [blame] | 20 | import java.util.LinkedHashMap; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 21 | import edu.uci.ics.asterix.aql.literal.FloatLiteral; |
| 22 | import edu.uci.ics.asterix.aql.literal.DoubleLiteral; |
| 23 | import edu.uci.ics.asterix.aql.literal.FalseLiteral; |
ilovesoup | c9fef1d | 2012-07-08 19:30:42 +0000 | [diff] [blame] | 24 | import edu.uci.ics.asterix.aql.base.Literal; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 25 | import edu.uci.ics.asterix.aql.literal.IntegerLiteral; |
ilovesoup | c9fef1d | 2012-07-08 19:30:42 +0000 | [diff] [blame] | 26 | import edu.uci.ics.asterix.aql.literal.LongIntegerLiteral; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 27 | import edu.uci.ics.asterix.aql.literal.NullLiteral; |
| 28 | import edu.uci.ics.asterix.aql.literal.StringLiteral; |
| 29 | import edu.uci.ics.asterix.aql.literal.TrueLiteral; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 30 | import edu.uci.ics.asterix.metadata.bootstrap.MetadataConstants; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 31 | |
| 32 | import edu.uci.ics.asterix.aql.base.*; |
| 33 | import edu.uci.ics.asterix.aql.expression.*; |
| 34 | import edu.uci.ics.asterix.common.config.DatasetConfig.DatasetType; |
| 35 | import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType; |
| 36 | import edu.uci.ics.asterix.aql.expression.visitor.AQLPrintVisitor; |
| 37 | import edu.uci.ics.asterix.aql.expression.UnaryExpr.Sign; |
| 38 | import edu.uci.ics.asterix.aql.base.Statement.Kind; |
| 39 | import edu.uci.ics.asterix.aql.context.Scope; |
| 40 | import edu.uci.ics.asterix.aql.context.RootScopeFactory; |
| 41 | import edu.uci.ics.asterix.common.annotations.*; |
| 42 | import edu.uci.ics.asterix.common.exceptions.AsterixException; |
ramangrover29 | a13f242 | 2012-03-15 23:01:27 +0000 | [diff] [blame] | 43 | import edu.uci.ics.asterix.om.functions.AsterixFunction; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 44 | import edu.uci.ics.asterix.common.functions.FunctionSignature; |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 45 | import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation; |
| 46 | import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 47 | import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; |
| 48 | import edu.uci.ics.hyracks.algebricks.common.utils.Pair; |
| 49 | import edu.uci.ics.hyracks.algebricks.common.utils.Triple; |
| 50 | |
| 51 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 52 | |
| 53 | |
| 54 | public class AQLParser extends ScopeChecker { |
| 55 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 56 | // optimizer hints |
| 57 | private static final String HASH_GROUP_BY_HINT = "hash"; |
| 58 | private static final String BROADCAST_JOIN_HINT = "bcast"; |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 59 | private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl"; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 60 | private static final String INMEMORY_HINT = "inmem"; |
| 61 | private static final String VAL_FILE_HINT = "val-files"; |
| 62 | private static final String VAL_FILE_SAME_INDEX_HINT = "val-file-same-idx"; |
| 63 | private static final String INTERVAL_HINT = "interval"; |
| 64 | private static final String COMPOSE_VAL_FILES_HINT = "compose-val-files"; |
| 65 | private static final String INSERT_RAND_INT_HINT = "insert-rand-int"; |
| 66 | private static final String LIST_VAL_FILE_HINT = "list-val-file"; |
| 67 | private static final String LIST_HINT = "list"; |
| 68 | private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years"; |
| 69 | private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years"; |
| 70 | private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours"; |
| 71 | private static final String AUTO_HINT = "auto"; |
| 72 | |
| 73 | private static final String GEN_FIELDS_HINT = "gen-fields"; |
| 74 | |
| 75 | // data generator hints |
| 76 | private static final String DGEN_HINT = "dgen"; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 77 | |
| 78 | private static class IndexParams { |
| 79 | public IndexType type; |
| 80 | public int gramLength; |
| 81 | |
| 82 | public IndexParams(IndexType type, int gramLength) { |
| 83 | this.type = type; |
| 84 | this.gramLength = gramLength; |
| 85 | } |
| 86 | }; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 87 | |
| 88 | private static String getHint(Token t) { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 89 | if (t.specialToken == null) { |
| 90 | return null; |
| 91 | } |
| 92 | String s = t.specialToken.image; |
| 93 | int n = s.length(); |
| 94 | if (n < 2) { |
| 95 | return null; |
| 96 | } |
| 97 | return s.substring(1).trim(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 98 | } |
Till Westmann | 77cb2f4 | 2013-07-15 16:44:19 -0700 | [diff] [blame] | 99 | |
| 100 | private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException { |
| 101 | IRecordFieldDataGen rfdg = null; |
| 102 | String splits[] = hint.split(" +"); |
| 103 | if (splits[0].equals(VAL_FILE_HINT)) { |
| 104 | File[] valFiles = new File[splits.length - 1]; |
| 105 | for (int k=1; k<splits.length; k++) { |
| 106 | valFiles[k-1] = new File(splits[k]); |
| 107 | } |
| 108 | rfdg = new FieldValFileDataGen(valFiles); |
| 109 | } else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) { |
| 110 | rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]); |
| 111 | } else if (splits[0].equals(LIST_VAL_FILE_HINT)) { |
| 112 | rfdg = new ListValFileDataGen(new File(splits[1]), Integer.parseInt(splits[2]), Integer.parseInt(splits[3])); |
| 113 | } else if (splits[0].equals(LIST_HINT)) { |
| 114 | rfdg = new ListDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 115 | } else if (splits[0].equals(INTERVAL_HINT)) { |
| 116 | FieldIntervalDataGen.ValueType vt; |
| 117 | if (splits[1].equals("int")) { |
| 118 | vt = FieldIntervalDataGen.ValueType.INT; |
| 119 | } else if (splits[1].equals("long")) { |
| 120 | vt = FieldIntervalDataGen.ValueType.LONG; |
| 121 | } else if (splits[1].equals("float")) { |
| 122 | vt = FieldIntervalDataGen.ValueType.FLOAT; |
| 123 | } else if (splits[1].equals("double")) { |
| 124 | vt = FieldIntervalDataGen.ValueType.DOUBLE; |
| 125 | } else { |
| 126 | throw new ParseException("Unknown type for interval data gen: " + splits[1]); |
| 127 | } |
| 128 | rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]); |
| 129 | } else if (splits[0].equals(INSERT_RAND_INT_HINT)) { |
| 130 | rfdg = new InsertRandIntDataGen(splits[1], splits[2]); |
| 131 | } else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) { |
| 132 | rfdg = new DateBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 133 | } else if (splits[0].equals(DATETIME_BETWEEN_YEARS_HINT)) { |
| 134 | rfdg = new DatetimeBetweenYearsDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2])); |
| 135 | } else if (splits[0].equals(DATETIME_ADD_RAND_HOURS_HINT)) { |
| 136 | rfdg = new DatetimeAddRandHoursDataGen(Integer.parseInt(splits[1]), Integer.parseInt(splits[2]), splits[3]); |
| 137 | } else if (splits[0].equals(AUTO_HINT)) { |
| 138 | rfdg = new AutoDataGen(splits[1]); |
| 139 | } |
| 140 | return rfdg; |
| 141 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 142 | |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 143 | public AQLParser(String s){ |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 144 | this(new StringReader(s)); |
| 145 | super.setInput(s); |
| 146 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 147 | |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 148 | public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException { |
| 149 | File file = new File(args[0]); |
| 150 | Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); |
| 151 | AQLParser parser = new AQLParser(fis); |
| 152 | List<Statement> st = parser.Statement(); |
| 153 | //st.accept(new AQLPrintVisitor(), 0); |
| 154 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | PARSER_END(AQLParser) |
| 158 | |
| 159 | |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 160 | List<Statement> Statement() throws ParseException: |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 161 | { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 162 | scopeStack.push(RootScopeFactory.createRootScope(this)); |
| 163 | List<Statement> decls = new ArrayList<Statement>(); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 164 | Statement stmt = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 165 | } |
| 166 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 167 | ( stmt = SingleStatement() (";") ? |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 168 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 169 | decls.add(stmt); |
| 170 | } |
| 171 | )* |
| 172 | <EOF> |
| 173 | { |
| 174 | return decls; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | Statement SingleStatement() throws ParseException: |
| 179 | { |
| 180 | Statement stmt = null; |
| 181 | } |
| 182 | { |
| 183 | ( |
| 184 | stmt = DataverseDeclaration() |
| 185 | | stmt = FunctionDeclaration() |
| 186 | | stmt = CreateStatement() |
| 187 | | stmt = LoadStatement() |
| 188 | | stmt = DropStatement() |
| 189 | | stmt = WriteStatement() |
| 190 | | stmt = SetStatement() |
| 191 | | stmt = InsertStatement() |
| 192 | | stmt = DeleteStatement() |
| 193 | | stmt = UpdateStatement() |
| 194 | | stmt = FeedStatement() |
| 195 | | stmt = Query() |
| 196 | ) |
| 197 | { |
| 198 | return stmt; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | DataverseDecl DataverseDeclaration() throws ParseException: |
| 203 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 204 | String dvName = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 205 | } |
| 206 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 207 | "use" "dataverse" dvName = Identifier() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 208 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 209 | defaultDataverse = dvName; |
| 210 | return new DataverseDecl(new Identifier(dvName)); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | |
| 214 | Statement CreateStatement() throws ParseException: |
| 215 | { |
| 216 | String hint = null; |
| 217 | boolean dgen = false; |
| 218 | Statement stmt = null; |
| 219 | } |
| 220 | { |
| 221 | "create" |
| 222 | ( |
| 223 | { |
| 224 | hint = getHint(token); |
| 225 | if (hint != null && hint.startsWith(DGEN_HINT)) { |
| 226 | dgen = true; |
| 227 | } |
| 228 | } |
| 229 | stmt = TypeSpecification(hint, dgen) |
| 230 | | stmt = NodegroupSpecification() |
| 231 | | stmt = DatasetSpecification() |
| 232 | | stmt = IndexSpecification() |
| 233 | | stmt = DataverseSpecification() |
| 234 | | stmt = FunctionSpecification() |
| 235 | ) |
| 236 | { |
| 237 | return stmt; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException: |
| 242 | { |
| 243 | Pair<Identifier,Identifier> nameComponents = null; |
| 244 | boolean ifNotExists = false; |
| 245 | TypeExpression typeExpr = null; |
| 246 | } |
| 247 | { |
| 248 | "type" nameComponents = FunctionOrTypeName() ifNotExists = IfNotExists() |
| 249 | "as" typeExpr = TypeExpr() |
| 250 | { |
| 251 | long numValues = -1; |
| 252 | String filename = null; |
| 253 | if (dgen) { |
| 254 | String splits[] = hint.split(" +"); |
| 255 | if (splits.length != 3) { |
| 256 | throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */"); |
| 257 | } |
| 258 | filename = splits[1]; |
| 259 | numValues = Long.parseLong(splits[2]); |
| 260 | } |
| 261 | TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues); |
| 262 | return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | |
| 267 | NodegroupDecl NodegroupSpecification() throws ParseException: |
| 268 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 269 | String name = null; |
| 270 | String tmp = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 271 | boolean ifNotExists = false; |
| 272 | List<Identifier>ncNames = null; |
| 273 | } |
| 274 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 275 | "nodegroup" name = Identifier() |
| 276 | ifNotExists = IfNotExists() "on" tmp = Identifier() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 277 | { |
| 278 | ncNames = new ArrayList<Identifier>(); |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 279 | ncNames.add(new Identifier(tmp)); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 280 | } |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 281 | ( "," tmp = Identifier() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 282 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 283 | ncNames.add(new Identifier(tmp)); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 284 | } |
| 285 | )* |
| 286 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 287 | return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | |
| 291 | DatasetDecl DatasetSpecification() throws ParseException: |
| 292 | { |
| 293 | Pair<Identifier,Identifier> nameComponents = null; |
| 294 | boolean ifNotExists = false; |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 295 | String typeName = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 296 | String adapterName = null; |
| 297 | Map<String,String> properties = null; |
| 298 | FunctionSignature appliedFunction = null; |
| 299 | List<String> primaryKeyFields = null; |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 300 | String nodeGroupName = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 301 | Map<String,String> hints = new HashMap<String,String>(); |
| 302 | DatasetDecl dsetDecl = null; |
| 303 | } |
| 304 | { |
| 305 | ( |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 306 | "external" <DATASET> nameComponents = QualifiedName() |
| 307 | <LEFTPAREN> typeName = Identifier() <RIGHTPAREN> |
| 308 | ifNotExists = IfNotExists() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 309 | "using" adapterName = AdapterName() properties = Configuration() |
| 310 | ( "hints" hints = Properties() )? |
| 311 | { |
| 312 | ExternalDetailsDecl edd = new ExternalDetailsDecl(); |
| 313 | edd.setAdapter(adapterName); |
| 314 | edd.setProperties(properties); |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 315 | dsetDecl = new DatasetDecl(nameComponents.first, |
| 316 | nameComponents.second, |
| 317 | new Identifier(typeName), |
| 318 | hints, |
| 319 | DatasetType.EXTERNAL, |
| 320 | edd, |
| 321 | ifNotExists); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 324 | | "feed" <DATASET> nameComponents = QualifiedName() |
| 325 | <LEFTPAREN> typeName = Identifier() <RIGHTPAREN> |
| 326 | ifNotExists = IfNotExists() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 327 | "using" adapterName = AdapterName() properties = Configuration() |
| 328 | (appliedFunction = ApplyFunction())? primaryKeyFields = PrimaryKey() |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 329 | ( "on" nodeGroupName = Identifier() )? |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 330 | ( "hints" hints = Properties() )? |
| 331 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 332 | FeedDetailsDecl fdd = new FeedDetailsDecl(adapterName, |
| 333 | properties, |
| 334 | appliedFunction, |
| 335 | nodeGroupName != null |
| 336 | ? new Identifier(nodeGroupName) |
| 337 | : null, |
| 338 | primaryKeyFields); |
| 339 | dsetDecl = new DatasetDecl(nameComponents.first, |
| 340 | nameComponents.second, |
| 341 | new Identifier(typeName), |
| 342 | hints, |
| 343 | DatasetType.FEED, |
| 344 | fdd, |
| 345 | ifNotExists); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 346 | } |
Till Westmann | d7dcb12 | 2013-05-16 13:19:09 -0700 | [diff] [blame] | 347 | | ("internal")? <DATASET> nameComponents = QualifiedName() |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 348 | <LEFTPAREN> typeName = Identifier() <RIGHTPAREN> |
| 349 | ifNotExists = IfNotExists() |
| 350 | primaryKeyFields = PrimaryKey() ("on" nodeGroupName = Identifier() )? |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 351 | ( "hints" hints = Properties() )? |
| 352 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 353 | InternalDetailsDecl idd = new InternalDetailsDecl(nodeGroupName != null |
| 354 | ? new Identifier(nodeGroupName) |
| 355 | : null, |
| 356 | primaryKeyFields); |
| 357 | dsetDecl = new DatasetDecl(nameComponents.first, |
| 358 | nameComponents.second, |
| 359 | new Identifier(typeName), |
| 360 | hints, |
| 361 | DatasetType.INTERNAL, |
| 362 | idd, |
| 363 | ifNotExists); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 364 | } |
| 365 | ) |
| 366 | { |
| 367 | return dsetDecl; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | CreateIndexStatement IndexSpecification() throws ParseException: |
| 372 | { |
| 373 | CreateIndexStatement cis = new CreateIndexStatement(); |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 374 | String indexName = null; |
| 375 | String fieldExpr = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 376 | boolean ifNotExists = false; |
| 377 | Pair<Identifier,Identifier> nameComponents = null; |
| 378 | IndexParams indexType = null; |
| 379 | } |
| 380 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 381 | "index" indexName = Identifier() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 382 | ifNotExists = IfNotExists() |
| 383 | "on" nameComponents = QualifiedName() |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 384 | <LEFTPAREN> ( fieldExpr = Identifier() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 385 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 386 | cis.addFieldExpr(fieldExpr); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 387 | } |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 388 | ) ("," fieldExpr = Identifier() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 389 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 390 | cis.addFieldExpr(fieldExpr); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 391 | } |
| 392 | )* <RIGHTPAREN> ( "type" indexType = IndexType() )? |
| 393 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 394 | cis.setIndexName(new Identifier(indexName)); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 395 | cis.setIfNotExists(ifNotExists); |
| 396 | cis.setDataverseName(nameComponents.first); |
| 397 | cis.setDatasetName(nameComponents.second); |
| 398 | if (indexType != null) { |
| 399 | cis.setIndexType(indexType.type); |
| 400 | cis.setGramLength(indexType.gramLength); |
| 401 | } |
| 402 | return cis; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | IndexParams IndexType() throws ParseException: |
| 407 | { |
| 408 | IndexType type = null; |
| 409 | int gramLength = 0; |
| 410 | } |
| 411 | { |
| 412 | ("btree" |
| 413 | { |
| 414 | type = IndexType.BTREE; |
| 415 | } |
| 416 | | "rtree" |
| 417 | { |
| 418 | type = IndexType.RTREE; |
| 419 | } |
| 420 | | "keyword" |
| 421 | { |
JIMAHN | b75446d | 2013-06-03 08:35:27 -0700 | [diff] [blame] | 422 | type = IndexType.LENGTH_PARTITIONED_WORD_INVIX; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 423 | } |
| 424 | | "ngram" <LEFTPAREN> <INTEGER_LITERAL> |
| 425 | { |
JIMAHN | b75446d | 2013-06-03 08:35:27 -0700 | [diff] [blame] | 426 | type = IndexType.LENGTH_PARTITIONED_NGRAM_INVIX; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 427 | gramLength = Integer.valueOf(token.image); |
| 428 | } |
| 429 | <RIGHTPAREN>) |
| 430 | { |
| 431 | return new IndexParams(type, gramLength); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | CreateDataverseStatement DataverseSpecification() throws ParseException : |
| 436 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 437 | String dvName = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 438 | boolean ifNotExists = false; |
| 439 | String format = null; |
| 440 | } |
| 441 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 442 | "dataverse" dvName = Identifier() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 443 | ifNotExists = IfNotExists() |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 444 | ( "with format" format = StringLiteral() )? |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 445 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 446 | return new CreateDataverseStatement(new Identifier(dvName), format, ifNotExists); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 447 | } |
| 448 | } |
| 449 | |
| 450 | CreateFunctionStatement FunctionSpecification() throws ParseException: |
| 451 | { |
| 452 | FunctionSignature signature; |
| 453 | boolean ifNotExists = false; |
| 454 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 455 | String functionBody; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 456 | Expression functionBodyExpr; |
| 457 | Token beginPos; |
| 458 | Token endPos; |
| 459 | Pair<Identifier,Identifier> nameComponents=null; |
| 460 | |
| 461 | createNewScope(); |
| 462 | } |
| 463 | { |
| 464 | "function" nameComponents = FunctionOrTypeName() |
| 465 | ifNotExists = IfNotExists() |
Till Westmann | d7dcb12 | 2013-05-16 13:19:09 -0700 | [diff] [blame] | 466 | paramList = ParameterList() |
| 467 | "{" |
| 468 | { |
| 469 | beginPos = token; |
| 470 | } |
| 471 | functionBodyExpr = Expression() "}" |
| 472 | { |
| 473 | endPos = token; |
| 474 | functionBody = extractFragment(beginPos.beginLine, beginPos.beginColumn, endPos.beginLine, endPos.beginColumn); |
| 475 | String dataverse = nameComponents.first.getValue(); |
| 476 | String functionName = nameComponents.second.getValue(); |
| 477 | signature = new FunctionSignature(dataverse, functionName, paramList.size()); |
| 478 | getCurrentScope().addFunctionDescriptor(signature, false); |
| 479 | return new CreateFunctionStatement(signature, paramList, functionBody, ifNotExists); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | List<VarIdentifier> ParameterList() throws ParseException: |
| 484 | { |
| 485 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 486 | VarIdentifier var = null; |
| 487 | } |
| 488 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 489 | <LEFTPAREN> (<VARIABLE> |
| 490 | { |
| 491 | var = new VarIdentifier(); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 492 | var.setValue(token.image); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 493 | paramList.add(var); |
| 494 | getCurrentScope().addNewVarSymbolToScope(var); |
| 495 | } |
| 496 | ("," <VARIABLE> |
| 497 | { |
| 498 | var = new VarIdentifier(); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 499 | var.setValue(token.image); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 500 | paramList.add(var); |
| 501 | getCurrentScope().addNewVarSymbolToScope(var); |
| 502 | } |
Till Westmann | d7dcb12 | 2013-05-16 13:19:09 -0700 | [diff] [blame] | 503 | )*)? <RIGHTPAREN> |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 504 | { |
Till Westmann | d7dcb12 | 2013-05-16 13:19:09 -0700 | [diff] [blame] | 505 | return paramList; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
| 509 | boolean IfNotExists() throws ParseException: |
| 510 | { |
| 511 | } |
| 512 | { |
| 513 | ( "if not exists" |
| 514 | { |
| 515 | return true; |
| 516 | } |
| 517 | )? |
| 518 | { |
| 519 | return false; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | FunctionSignature ApplyFunction() throws ParseException: |
| 524 | { |
| 525 | FunctionSignature funcSig = null; |
| 526 | } |
| 527 | { |
| 528 | "apply" "function" funcSig = FunctionSignature() |
| 529 | { |
| 530 | return funcSig; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | FunctionSignature FunctionSignature() throws ParseException: |
| 535 | { |
| 536 | Pair<Identifier,Identifier> pairId = null; |
| 537 | int arity = 0; |
| 538 | } |
| 539 | { |
| 540 | pairId = FunctionOrTypeName() "@" <INTEGER_LITERAL> |
| 541 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 542 | arity = new Integer(token.image); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 543 | if (arity < 0 && arity != FunctionIdentifier.VARARGS) { |
| 544 | throw new ParseException(" invalid arity:" + arity); |
| 545 | } |
| 546 | |
| 547 | String dataverse = pairId.first.getValue(); |
| 548 | String functionName = pairId.second.getValue(); |
| 549 | return new FunctionSignature(dataverse, functionName, arity); |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | List<String> PrimaryKey() throws ParseException: |
| 554 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 555 | String tmp = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 556 | List<String> primaryKeyFields = new ArrayList<String>(); |
| 557 | } |
| 558 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 559 | "primary" "key" tmp = Identifier() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 560 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 561 | primaryKeyFields.add(tmp); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 562 | } |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 563 | ( "," tmp = Identifier() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 564 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 565 | primaryKeyFields.add(tmp); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 566 | } |
| 567 | )* |
| 568 | { |
| 569 | return primaryKeyFields; |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | Statement DropStatement() throws ParseException: |
| 574 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 575 | String id = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 576 | Pair<Identifier,Identifier> pairId = null; |
| 577 | Triple<Identifier,Identifier,Identifier> tripleId = null; |
| 578 | FunctionSignature funcSig = null; |
| 579 | boolean ifExists = false; |
| 580 | Statement stmt = null; |
| 581 | } |
| 582 | { |
| 583 | "drop" |
| 584 | ( |
| 585 | <DATASET> pairId = QualifiedName() ifExists = IfExists() |
| 586 | { |
| 587 | stmt = new DropStatement(pairId.first, pairId.second, ifExists); |
| 588 | } |
| 589 | | "index" tripleId = DoubleQualifiedName() ifExists = IfExists() |
| 590 | { |
| 591 | stmt = new IndexDropStatement(tripleId.first, tripleId.second, tripleId.third, ifExists); |
| 592 | } |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 593 | | "nodegroup" id = Identifier() ifExists = IfExists() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 594 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 595 | stmt = new NodeGroupDropStatement(new Identifier(id), ifExists); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 596 | } |
| 597 | | "type" pairId = FunctionOrTypeName() ifExists = IfExists() |
| 598 | { |
| 599 | stmt = new TypeDropStatement(pairId.first, pairId.second, ifExists); |
| 600 | } |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 601 | | "dataverse" id = Identifier() ifExists = IfExists() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 602 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 603 | stmt = new DataverseDropStatement(new Identifier(id), ifExists); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 604 | } |
| 605 | | "function" funcSig = FunctionSignature() ifExists = IfExists() |
| 606 | { |
| 607 | stmt = new FunctionDropStatement(funcSig, ifExists); |
| 608 | } |
| 609 | ) |
| 610 | { |
| 611 | return stmt; |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | boolean IfExists() throws ParseException : |
| 616 | { |
| 617 | } |
| 618 | { |
| 619 | ( "if" "exists" |
| 620 | { |
| 621 | return true; |
| 622 | } |
| 623 | )? |
| 624 | { |
| 625 | return false; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | |
| 629 | InsertStatement InsertStatement() throws ParseException: |
| 630 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 631 | Pair<Identifier,Identifier> nameComponents = null; |
| 632 | Query query; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 633 | } |
| 634 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 635 | "insert" "into" <DATASET> nameComponents = QualifiedName() query = Query() |
| 636 | { |
| 637 | return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter()); |
| 638 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | DeleteStatement DeleteStatement() throws ParseException: |
| 642 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 643 | VariableExpr var = null; |
| 644 | Expression condition = null; |
| 645 | Pair<Identifier, Identifier> nameComponents; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 646 | } |
| 647 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 648 | "delete" var = Variable() |
| 649 | { |
| 650 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 651 | } |
| 652 | "from" <DATASET> nameComponents = QualifiedName() |
| 653 | ("where" condition = Expression())? |
| 654 | { |
| 655 | return new DeleteStatement(var, nameComponents.first, nameComponents.second, condition, getVarCounter()); |
| 656 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | UpdateStatement UpdateStatement() throws ParseException: |
| 660 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 661 | VariableExpr vars; |
| 662 | Expression target; |
| 663 | Expression condition; |
| 664 | UpdateClause uc; |
| 665 | List<UpdateClause> ucs = new ArrayList<UpdateClause>(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 666 | } |
| 667 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 668 | "update" vars = Variable() "in" target = Expression() |
| 669 | "where" condition = Expression() |
| 670 | <LEFTPAREN> (uc = UpdateClause() |
| 671 | { |
| 672 | ucs.add(uc); |
| 673 | } |
| 674 | ("," uc = UpdateClause() |
| 675 | { |
| 676 | ucs.add(uc); |
| 677 | } |
| 678 | )*) <RIGHTPAREN> |
| 679 | { |
| 680 | return new UpdateStatement(vars, target, condition, ucs); |
| 681 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 682 | } |
| 683 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 684 | UpdateClause UpdateClause() throws ParseException: |
| 685 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 686 | Expression target = null; |
| 687 | Expression value = null ; |
| 688 | InsertStatement is = null; |
| 689 | DeleteStatement ds = null; |
| 690 | UpdateStatement us = null; |
| 691 | Expression condition = null; |
| 692 | UpdateClause ifbranch = null; |
| 693 | UpdateClause elsebranch = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 694 | } |
| 695 | { |
| 696 | "set" target = Expression() ":=" value = Expression() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 697 | | is = InsertStatement() |
| 698 | | ds = DeleteStatement() |
| 699 | | us = UpdateStatement() |
| 700 | | "if" <LEFTPAREN> condition = Expression() <RIGHTPAREN> |
| 701 | "then" ifbranch = UpdateClause() |
| 702 | [LOOKAHEAD(1) "else" elsebranch = UpdateClause()] |
| 703 | { |
| 704 | return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch); |
| 705 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 706 | } |
| 707 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 708 | Statement SetStatement() throws ParseException: |
| 709 | { |
| 710 | String pn = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 711 | String pv = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 712 | } |
| 713 | { |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 714 | "set" pn = Identifier() pv = StringLiteral() |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 715 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 716 | return new SetStatement(pn, pv); |
| 717 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | Statement WriteStatement() throws ParseException: |
| 721 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 722 | String nodeName = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 723 | String fileName = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 724 | Query query; |
| 725 | String writerClass = null; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 726 | Pair<Identifier,Identifier> nameComponents = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 727 | } |
| 728 | { |
Till Westmann | 35a0f70 | 2013-07-01 14:06:34 -0700 | [diff] [blame] | 729 | "write" "output" "to" nodeName = Identifier() ":" fileName = StringLiteral() |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 730 | ( "using" writerClass = StringLiteral() )? |
Till Westmann | 35a0f70 | 2013-07-01 14:06:34 -0700 | [diff] [blame] | 731 | { |
| 732 | return new WriteStatement(new Identifier(nodeName), fileName, writerClass); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 736 | LoadFromFileStatement LoadStatement() throws ParseException: |
| 737 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 738 | Identifier dataverseName = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 739 | Identifier datasetName = null; |
| 740 | boolean alreadySorted = false; |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 741 | String adapterName; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 742 | Map<String,String> properties; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 743 | Pair<Identifier,Identifier> nameComponents = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 744 | } |
| 745 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 746 | "load" <DATASET> nameComponents = QualifiedName() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 747 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 748 | dataverseName = nameComponents.first; |
| 749 | datasetName = nameComponents.second; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 750 | } |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 751 | "using" adapterName = AdapterName() properties = Configuration() |
| 752 | ("pre-sorted" |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 753 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 754 | alreadySorted = true; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 755 | } |
| 756 | )? |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 757 | { |
| 758 | return new LoadFromFileStatement(dataverseName, datasetName, adapterName, properties, alreadySorted); |
| 759 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 760 | } |
| 761 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 762 | |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 763 | String AdapterName() throws ParseException : |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 764 | { |
ramangrover29 | 669d8f6 | 2013-02-11 06:03:32 +0000 | [diff] [blame] | 765 | String adapterName = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 766 | } |
| 767 | { |
Till Westmann | 68d9965 | 2013-05-09 11:15:21 -0700 | [diff] [blame] | 768 | adapterName = Identifier() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 769 | { |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 770 | return adapterName; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 771 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 772 | } |
| 773 | |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 774 | Statement FeedStatement() throws ParseException: |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 775 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 776 | Pair<Identifier,Identifier> nameComponents = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 777 | Map<String,String> configuration = null; |
| 778 | Statement stmt = null; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 779 | } |
| 780 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 781 | ( |
| 782 | "begin" "feed" nameComponents = QualifiedName() |
| 783 | { |
| 784 | stmt = new BeginFeedStatement(nameComponents.first, nameComponents.second, getVarCounter()); |
| 785 | } |
| 786 | | "suspend" "feed" nameComponents = QualifiedName() |
| 787 | { |
| 788 | stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.SUSPEND, nameComponents.first, nameComponents.second); |
| 789 | } |
| 790 | | "resume" "feed" nameComponents = QualifiedName() |
| 791 | { |
| 792 | stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.RESUME, nameComponents.first, nameComponents.second); |
| 793 | } |
| 794 | | "end" "feed" nameComponents = QualifiedName() |
| 795 | { |
| 796 | stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.END, nameComponents.first, nameComponents.second); |
| 797 | } |
| 798 | | "alter" "feed" nameComponents = QualifiedName() "set" configuration = Configuration() |
| 799 | { |
| 800 | stmt = new ControlFeedStatement(ControlFeedStatement.OperationType.ALTER, nameComponents.first, nameComponents.second, configuration); |
| 801 | } |
| 802 | ) |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 803 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 804 | return stmt; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 805 | } |
| 806 | } |
| 807 | |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 808 | Map<String,String> Configuration() throws ParseException : |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 809 | { |
diegogiorgini@gmail.com | eb1910e | 2013-02-14 07:43:00 +0000 | [diff] [blame] | 810 | Map<String,String> configuration = new LinkedHashMap<String,String>(); |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 811 | Pair<String, String> keyValuePair = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 812 | } |
| 813 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 814 | <LEFTPAREN> ( keyValuePair = KeyValuePair() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 815 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 816 | configuration.put(keyValuePair.first, keyValuePair.second); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 817 | } |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 818 | ( "," keyValuePair = KeyValuePair() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 819 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 820 | configuration.put(keyValuePair.first, keyValuePair.second); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 821 | } |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 822 | )* )? <RIGHTPAREN> |
| 823 | { |
| 824 | return configuration; |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | Pair<String, String> KeyValuePair() throws ParseException: |
| 829 | { |
| 830 | String key; |
| 831 | String value; |
| 832 | } |
| 833 | { |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 834 | <LEFTPAREN> key = StringLiteral() "=" value = StringLiteral() <RIGHTPAREN> |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 835 | { |
| 836 | return new Pair<String, String>(key, value); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 837 | } |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | Map<String,String> Properties() throws ParseException: |
| 841 | { |
| 842 | Map<String,String> properties = new HashMap<String,String>(); |
| 843 | Pair<String, String> property; |
| 844 | } |
| 845 | { |
| 846 | ( <LEFTPAREN> property = Property() |
| 847 | { |
| 848 | properties.put(property.first, property.second); |
| 849 | } |
| 850 | ( "," property = Property() |
| 851 | { |
| 852 | properties.put(property.first, property.second); |
| 853 | } |
| 854 | )* <RIGHTPAREN> )? |
| 855 | { |
| 856 | return properties; |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | Pair<String, String> Property() throws ParseException: |
| 861 | { |
| 862 | String key; |
| 863 | String value; |
| 864 | } |
| 865 | { |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 866 | key = Identifier() "=" ( value = StringLiteral() | <INTEGER_LITERAL> |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 867 | { |
| 868 | try { |
| 869 | value = "" + Long.valueOf(token.image); |
| 870 | } catch (NumberFormatException nfe) { |
| 871 | throw new ParseException("inapproriate value: " + token.image); |
| 872 | } |
| 873 | } |
| 874 | ) |
| 875 | { |
| 876 | return new Pair<String, String>(key.toUpperCase(), value); |
| 877 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | TypeExpression TypeExpr() throws ParseException: |
| 881 | { |
| 882 | TypeExpression typeExpr = null; |
| 883 | } |
| 884 | { |
| 885 | ( |
| 886 | typeExpr = RecordTypeDef() |
| 887 | | typeExpr = TypeReference() |
| 888 | | typeExpr = OrderedListTypeDef() |
| 889 | | typeExpr = UnorderedListTypeDef() |
| 890 | ) |
| 891 | { |
| 892 | return typeExpr; |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | RecordTypeDefinition RecordTypeDef() throws ParseException: |
| 897 | { |
| 898 | RecordTypeDefinition recType = new RecordTypeDefinition(); |
| 899 | RecordTypeDefinition.RecordKind recordKind = null; |
| 900 | } |
| 901 | { |
| 902 | ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; } |
| 903 | | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )? |
| 904 | "{" |
| 905 | { |
| 906 | String hint = getHint(token); |
| 907 | if (hint != null) { |
| 908 | String splits[] = hint.split(" +"); |
| 909 | if (splits[0].equals(GEN_FIELDS_HINT)) { |
| 910 | if (splits.length != 5) { |
| 911 | throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/"); |
| 912 | } |
| 913 | if (!splits[1].equals("int")) { |
| 914 | throw new ParseException("The only supported type for gen-fields is int."); |
| 915 | } |
| 916 | UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT, |
| 917 | Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]); |
| 918 | recType.setUndeclaredFieldsDataGen(ufdg); |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | } |
| 923 | ( |
| 924 | RecordField(recType) |
| 925 | ( "," RecordField(recType) )* |
| 926 | )? |
| 927 | "}" |
| 928 | { |
| 929 | if (recordKind == null) { |
| 930 | recordKind = RecordTypeDefinition.RecordKind.OPEN; |
| 931 | } |
| 932 | recType.setRecordKind(recordKind); |
| 933 | return recType; |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | void RecordField(RecordTypeDefinition recType) throws ParseException: |
| 938 | { |
Till Westmann | 77cb2f4 | 2013-07-15 16:44:19 -0700 | [diff] [blame] | 939 | String fieldName; |
| 940 | TypeExpression type = null; |
| 941 | boolean nullable = false; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 942 | } |
| 943 | { |
Till Westmann | 77cb2f4 | 2013-07-15 16:44:19 -0700 | [diff] [blame] | 944 | fieldName = Identifier() |
| 945 | { |
| 946 | String hint = getHint(token); |
| 947 | IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null; |
| 948 | } |
| 949 | ":" type = TypeExpr() ("?" { nullable = true; } )? |
| 950 | { |
| 951 | recType.addField(fieldName, type, nullable, rfdg); |
| 952 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | TypeReferenceExpression TypeReference() throws ParseException: |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 956 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 957 | String id = null; |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 958 | } |
| 959 | { |
| 960 | id = Identifier() |
| 961 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 962 | return new TypeReferenceExpression(new Identifier(id)); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 963 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | OrderedListTypeDefinition OrderedListTypeDef() throws ParseException: |
| 967 | { |
| 968 | TypeExpression type = null; |
| 969 | } |
| 970 | { |
| 971 | "[" |
| 972 | ( type = TypeExpr() ) |
| 973 | "]" |
| 974 | { |
| 975 | return new OrderedListTypeDefinition(type); |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | |
| 980 | UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException: |
| 981 | { |
| 982 | TypeExpression type = null; |
| 983 | } |
| 984 | { |
| 985 | "{{" |
| 986 | ( type = TypeExpr() ) |
| 987 | "}}" |
| 988 | { |
| 989 | return new UnorderedListTypeDefinition(type); |
| 990 | } |
| 991 | } |
| 992 | |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 993 | |
| 994 | Pair<Identifier,Identifier> FunctionOrTypeName() throws ParseException: |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 995 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 996 | Pair<Identifier,Identifier> name = null; |
| 997 | } |
| 998 | { |
| 999 | name = QualifiedName() |
| 1000 | { |
| 1001 | if (name.first == null) { |
| 1002 | name.first = new Identifier(defaultDataverse); |
| 1003 | } |
| 1004 | return name; |
| 1005 | } |
| 1006 | } |
| 1007 | |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1008 | String Identifier() throws ParseException: |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1009 | { |
Till Westmann | 68d9965 | 2013-05-09 11:15:21 -0700 | [diff] [blame] | 1010 | String lit = null; |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1011 | } |
| 1012 | { |
| 1013 | <IDENTIFIER> |
| 1014 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1015 | return token.image; |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1016 | } |
Till Westmann | 68d9965 | 2013-05-09 11:15:21 -0700 | [diff] [blame] | 1017 | | lit = StringLiteral() |
| 1018 | { |
| 1019 | return lit; |
| 1020 | } |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 1023 | String StringLiteral() throws ParseException: |
| 1024 | { |
| 1025 | } |
| 1026 | { |
| 1027 | <STRING_LITERAL> |
| 1028 | { |
| 1029 | return removeQuotesAndEscapes(token.image); |
| 1030 | } |
| 1031 | } |
| 1032 | |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1033 | Pair<Identifier,Identifier> QualifiedName() throws ParseException: |
| 1034 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1035 | String first = null; |
| 1036 | String second = null; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1037 | } |
| 1038 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1039 | first = Identifier() ("." second = Identifier())? |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1040 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1041 | Identifier id1 = null; |
| 1042 | Identifier id2 = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1043 | if (second == null) { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1044 | id2 = new Identifier(first); |
| 1045 | } else |
| 1046 | { |
| 1047 | id1 = new Identifier(first); |
| 1048 | id2 = new Identifier(second); |
| 1049 | } |
| 1050 | return new Pair<Identifier,Identifier>(id1, id2); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1051 | } |
| 1052 | } |
| 1053 | |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1054 | Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException: |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1055 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1056 | String first = null; |
| 1057 | String second = null; |
| 1058 | String third = null; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1059 | } |
| 1060 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1061 | first = Identifier() "." second = Identifier() ("." third = Identifier())? |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1062 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1063 | Identifier id1 = null; |
| 1064 | Identifier id2 = null; |
| 1065 | Identifier id3 = null; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1066 | if (third == null) { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1067 | id2 = new Identifier(first); |
| 1068 | id3 = new Identifier(second); |
| 1069 | } else { |
| 1070 | id1 = new Identifier(first); |
| 1071 | id2 = new Identifier(second); |
| 1072 | id3 = new Identifier(third); |
| 1073 | } |
| 1074 | return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1075 | } |
| 1076 | } |
| 1077 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1078 | FunctionDecl FunctionDeclaration() throws ParseException: |
| 1079 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1080 | FunctionDecl funcDecl; |
| 1081 | FunctionSignature signature; |
ramangrover29 | a13f242 | 2012-03-15 23:01:27 +0000 | [diff] [blame] | 1082 | String functionName; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1083 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 1084 | Expression funcBody; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1085 | createNewScope(); |
| 1086 | } |
| 1087 | { |
Till Westmann | d7dcb12 | 2013-05-16 13:19:09 -0700 | [diff] [blame] | 1088 | "declare" "function" functionName = Identifier() |
| 1089 | paramList = ParameterList() |
| 1090 | "{" funcBody = Expression() "}" |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1091 | { |
Till Westmann | d7dcb12 | 2013-05-16 13:19:09 -0700 | [diff] [blame] | 1092 | signature = new FunctionSignature(defaultDataverse, functionName, paramList.size()); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1093 | getCurrentScope().addFunctionDescriptor(signature, false); |
| 1094 | funcDecl = new FunctionDecl(signature, paramList, funcBody); |
Till Westmann | c6c4a74 | 2013-05-20 17:59:21 -0700 | [diff] [blame] | 1095 | removeCurrentScope(); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1096 | return funcDecl; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1097 | } |
| 1098 | } |
| 1099 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1100 | |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1101 | Query Query() throws ParseException: |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1102 | { |
| 1103 | Query query = new Query(); |
| 1104 | Expression expr; |
| 1105 | } |
| 1106 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1107 | expr = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1108 | { |
| 1109 | query.setBody(expr); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1110 | query.setVarCounter(getVarCounter()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1111 | return query; |
| 1112 | } |
RamanGrover29@gmail.com | c022a0d | 2012-07-28 05:13:44 +0000 | [diff] [blame] | 1113 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | |
| 1117 | |
| 1118 | Expression Expression(): |
| 1119 | { |
| 1120 | Expression expr = null; |
| 1121 | Expression exprP = null; |
| 1122 | } |
| 1123 | { |
| 1124 | ( |
| 1125 | |
| 1126 | //OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression |
| 1127 | expr = OperatorExpr() |
| 1128 | | expr = IfThenElse() |
| 1129 | | expr = FLWOGR() |
| 1130 | | expr = QuantifiedExpression() |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1131 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1132 | |
| 1133 | ) |
| 1134 | { |
| 1135 | return (exprP==null) ? expr : exprP; |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | |
| 1140 | |
| 1141 | Expression OperatorExpr()throws ParseException: |
| 1142 | { |
| 1143 | OperatorExpr op = null; |
| 1144 | Expression operand = null; |
| 1145 | } |
| 1146 | { |
| 1147 | operand = AndExpr() |
| 1148 | ( |
| 1149 | |
| 1150 | "or" |
| 1151 | { |
| 1152 | if (op == null) { |
| 1153 | op = new OperatorExpr(); |
| 1154 | op.addOperand(operand); |
| 1155 | op.setCurrentop(true); |
| 1156 | } |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1157 | op.addOperator(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | operand = AndExpr() |
| 1161 | { |
| 1162 | op.addOperand(operand); |
| 1163 | } |
| 1164 | |
| 1165 | )* |
| 1166 | |
| 1167 | { |
| 1168 | return op==null? operand: op; |
| 1169 | } |
| 1170 | } |
| 1171 | |
| 1172 | Expression AndExpr()throws ParseException: |
| 1173 | { |
| 1174 | OperatorExpr op = null; |
| 1175 | Expression operand = null; |
| 1176 | } |
| 1177 | { |
| 1178 | operand = RelExpr() |
| 1179 | ( |
| 1180 | |
| 1181 | "and" |
| 1182 | { |
| 1183 | if (op == null) { |
| 1184 | op = new OperatorExpr(); |
| 1185 | op.addOperand(operand); |
| 1186 | op.setCurrentop(true); |
| 1187 | } |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1188 | op.addOperator(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | operand = RelExpr() |
| 1192 | { |
| 1193 | op.addOperand(operand); |
| 1194 | } |
| 1195 | |
| 1196 | )* |
| 1197 | |
| 1198 | { |
| 1199 | return op==null? operand: op; |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | |
| 1204 | |
| 1205 | Expression RelExpr()throws ParseException: |
| 1206 | { |
| 1207 | OperatorExpr op = null; |
| 1208 | Expression operand = null; |
| 1209 | boolean broadcast = false; |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1210 | IExpressionAnnotation annotation = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1211 | } |
| 1212 | { |
| 1213 | operand = AddExpr() |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1214 | { |
| 1215 | if (operand instanceof VariableExpr) { |
| 1216 | String hint = getHint(token); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1217 | if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) { |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1218 | broadcast = true; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1219 | } |
| 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | ( |
| 1224 | LOOKAHEAD(2)( "<" | ">" | "<=" | ">=" | "=" | "!=" |"~=") |
| 1225 | { |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1226 | String mhint = getHint(token); |
| 1227 | if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) { |
| 1228 | annotation = IndexedNLJoinExpressionAnnotation.INSTANCE; |
| 1229 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1230 | if (op == null) { |
| 1231 | op = new OperatorExpr(); |
| 1232 | op.addOperand(operand, broadcast); |
| 1233 | op.setCurrentop(true); |
| 1234 | broadcast = false; |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1235 | } |
| 1236 | op.addOperator(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | operand = AddExpr() |
| 1240 | { |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1241 | broadcast = false; |
| 1242 | if (operand instanceof VariableExpr) { |
| 1243 | String hint = getHint(token); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1244 | if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) { |
| 1245 | broadcast = true; |
| 1246 | } |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1247 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1248 | op.addOperand(operand, broadcast); |
| 1249 | } |
| 1250 | )? |
| 1251 | |
| 1252 | { |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1253 | if (annotation != null) { |
| 1254 | op.addHint(annotation); |
| 1255 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1256 | return op==null? operand: op; |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | Expression AddExpr()throws ParseException: |
| 1261 | { |
| 1262 | OperatorExpr op = null; |
| 1263 | Expression operand = null; |
| 1264 | } |
| 1265 | { |
| 1266 | operand = MultExpr() |
| 1267 | |
| 1268 | ( ("+" | "-") |
| 1269 | { |
| 1270 | if (op == null) { |
| 1271 | op = new OperatorExpr(); |
| 1272 | op.addOperand(operand); |
| 1273 | op.setCurrentop(true); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1274 | } |
| 1275 | ((OperatorExpr)op).addOperator(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | operand = MultExpr() |
| 1279 | { |
| 1280 | op.addOperand(operand); |
| 1281 | } |
| 1282 | )* |
| 1283 | |
| 1284 | { |
| 1285 | return op==null? operand: op; |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | Expression MultExpr()throws ParseException: |
| 1290 | { |
| 1291 | OperatorExpr op = null; |
| 1292 | Expression operand = null; |
| 1293 | } |
| 1294 | { |
| 1295 | operand = UnionExpr() |
| 1296 | |
| 1297 | (( "*" | "/" | "%" | <CARET> | "idiv") |
| 1298 | { |
| 1299 | if (op == null) { |
| 1300 | op = new OperatorExpr(); |
| 1301 | op.addOperand(operand); |
| 1302 | op.setCurrentop(true); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1303 | } |
| 1304 | op.addOperator(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1305 | } |
| 1306 | operand = UnionExpr() |
| 1307 | { |
| 1308 | op.addOperand(operand); |
| 1309 | } |
| 1310 | )* |
| 1311 | |
| 1312 | { |
| 1313 | return op==null?operand:op; |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | Expression UnionExpr() throws ParseException: |
| 1318 | { |
| 1319 | UnionExpr union = null; |
| 1320 | Expression operand1 = null; |
| 1321 | Expression operand2 = null; |
| 1322 | } |
| 1323 | { |
| 1324 | operand1 = UnaryExpr() |
| 1325 | ("union" |
| 1326 | (operand2 = UnaryExpr()) { |
| 1327 | if (union == null) { |
| 1328 | union = new UnionExpr(); |
| 1329 | union.addExpr(operand1); |
| 1330 | } |
| 1331 | union.addExpr(operand2); |
| 1332 | } )* |
| 1333 | { |
| 1334 | return (union == null)? operand1: union; |
| 1335 | } |
| 1336 | } |
| 1337 | |
| 1338 | Expression UnaryExpr() throws ParseException: |
| 1339 | { |
| 1340 | Expression uexpr = null; |
| 1341 | Expression expr = null; |
| 1342 | } |
| 1343 | { |
| 1344 | (( "+"|"-") |
| 1345 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1346 | uexpr = new UnaryExpr(); |
| 1347 | if("+".equals(token.image)) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1348 | ((UnaryExpr)uexpr).setSign(Sign.POSITIVE); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1349 | else if("-".equals(token.image)) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1350 | ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE); |
| 1351 | else |
| 1352 | throw new ParseException(); |
| 1353 | } |
| 1354 | )? |
| 1355 | |
| 1356 | expr = ValueExpr() |
| 1357 | { |
| 1358 | if(uexpr!=null){ |
| 1359 | ((UnaryExpr)uexpr).setExpr(expr); |
| 1360 | return uexpr; |
| 1361 | } |
| 1362 | else{ |
| 1363 | return expr; |
| 1364 | } |
| 1365 | } |
| 1366 | } |
| 1367 | |
Till Westmann | 04478e7 | 2013-05-13 23:01:34 -0700 | [diff] [blame] | 1368 | Expression ValueExpr()throws ParseException: |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1369 | { |
| 1370 | Expression expr = null; |
| 1371 | Identifier ident = null; |
| 1372 | AbstractAccessor fa = null; |
| 1373 | int index; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1374 | } |
| 1375 | { |
Till Westmann | 04478e7 | 2013-05-13 23:01:34 -0700 | [diff] [blame] | 1376 | expr = PrimaryExpr() ( ident = Field() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1377 | { |
Till Westmann | 04478e7 | 2013-05-13 23:01:34 -0700 | [diff] [blame] | 1378 | fa = (fa == null ? new FieldAccessor(expr, ident) |
| 1379 | : new FieldAccessor(fa, ident)); |
| 1380 | } |
| 1381 | | index = Index() |
| 1382 | { |
| 1383 | fa = (fa == null ? new IndexAccessor(expr, index) |
| 1384 | : new IndexAccessor(fa, index)); |
| 1385 | } |
| 1386 | )* |
| 1387 | { |
| 1388 | return fa == null ? expr : fa; |
| 1389 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | Identifier Field() throws ParseException: |
| 1393 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1394 | String ident = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1395 | } |
| 1396 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1397 | "." ident = Identifier() |
| 1398 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1399 | return new Identifier(ident); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1400 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | int Index() throws ParseException: |
| 1404 | { |
| 1405 | Expression expr = null; |
| 1406 | int idx = -2; |
| 1407 | } |
| 1408 | { |
| 1409 | "[" ( expr = Expression() |
| 1410 | { |
| 1411 | if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION) |
| 1412 | { |
ilovesoup | c9fef1d | 2012-07-08 19:30:42 +0000 | [diff] [blame] | 1413 | Literal lit = ((LiteralExpr)expr).getValue(); |
| 1414 | if(lit.getLiteralType() == Literal.Type.INTEGER || |
| 1415 | lit.getLiteralType() == Literal.Type.LONG) { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1416 | idx = Integer.valueOf(lit.getStringValue()); |
ilovesoup | c9fef1d | 2012-07-08 19:30:42 +0000 | [diff] [blame] | 1417 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1418 | else { |
| 1419 | throw new ParseException("Index should be an INTEGER"); |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | } |
| 1424 | |
| 1425 | | "?" |
| 1426 | { |
| 1427 | idx = IndexAccessor.ANY; |
| 1428 | // ANY |
| 1429 | } |
| 1430 | |
| 1431 | ) |
| 1432 | |
| 1433 | "]" |
| 1434 | { |
| 1435 | return idx; |
| 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | |
| 1440 | Expression PrimaryExpr()throws ParseException: |
| 1441 | { |
| 1442 | Expression expr = null; |
| 1443 | } |
| 1444 | { |
Till Westmann | 68d9965 | 2013-05-09 11:15:21 -0700 | [diff] [blame] | 1445 | ( LOOKAHEAD(2) |
| 1446 | expr = FunctionCallExpr() |
| 1447 | | expr = Literal() |
| 1448 | | expr = DatasetAccessExpression() |
| 1449 | | expr = VariableRef() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1450 | { |
| 1451 | if(((VariableExpr)expr).getIsNewVar() == true) |
Till Westmann | 68d9965 | 2013-05-09 11:15:21 -0700 | [diff] [blame] | 1452 | throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1453 | } |
Till Westmann | 68d9965 | 2013-05-09 11:15:21 -0700 | [diff] [blame] | 1454 | | expr = ListConstructor() |
| 1455 | | expr = RecordConstructor() |
| 1456 | | expr = ParenthesizedExpression() |
| 1457 | ) |
| 1458 | { |
| 1459 | return expr; |
| 1460 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | Expression Literal() throws ParseException: |
| 1464 | { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1465 | LiteralExpr lit = new LiteralExpr(); |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 1466 | String str = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1467 | } |
| 1468 | { |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 1469 | ( str = StringLiteral() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1470 | { |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 1471 | lit.setValue(new StringLiteral(str)); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1472 | } |
| 1473 | | <INTEGER_LITERAL> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1474 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1475 | try { |
| 1476 | lit.setValue(new IntegerLiteral(new Integer(token.image))); |
| 1477 | } catch(NumberFormatException ex) { |
| 1478 | lit.setValue(new LongIntegerLiteral(new Long(token.image))); |
| 1479 | } |
| 1480 | } |
| 1481 | | <FLOAT_LITERAL> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1482 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1483 | lit.setValue(new FloatLiteral(new Float(token.image))); |
| 1484 | } |
| 1485 | | <DOUBLE_LITERAL> |
| 1486 | { |
| 1487 | lit.setValue(new DoubleLiteral(new Double(token.image))); |
| 1488 | } |
| 1489 | | <NULL> |
| 1490 | { |
| 1491 | lit.setValue(NullLiteral.INSTANCE); |
| 1492 | } |
| 1493 | | <TRUE> |
| 1494 | { |
| 1495 | lit.setValue(TrueLiteral.INSTANCE); |
| 1496 | } |
| 1497 | | <FALSE> |
| 1498 | { |
| 1499 | lit.setValue(FalseLiteral.INSTANCE); |
| 1500 | } |
| 1501 | ) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1502 | { |
| 1503 | return lit; |
| 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | |
| 1508 | VariableExpr VariableRef() throws ParseException: |
| 1509 | { |
| 1510 | VariableExpr varExp = new VariableExpr(); |
| 1511 | VarIdentifier var = new VarIdentifier(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1512 | } |
| 1513 | { |
Till Westmann | 4f58e1a | 2013-05-20 18:29:54 -0700 | [diff] [blame] | 1514 | <VARIABLE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1515 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1516 | String varName = token.image; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1517 | Identifier ident = lookupSymbol(varName); |
| 1518 | if (isInForbiddenScopes(varName)) { |
| 1519 | 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."); |
| 1520 | } |
| 1521 | if(ident != null) { // exist such ident |
| 1522 | varExp.setIsNewVar(false); |
| 1523 | varExp.setVar((VarIdentifier)ident); |
| 1524 | } else { |
| 1525 | varExp.setVar(var); |
| 1526 | } |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1527 | var.setValue(varName); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1528 | return varExp; |
| 1529 | } |
| 1530 | } |
| 1531 | |
| 1532 | |
| 1533 | VariableExpr Variable() throws ParseException: |
| 1534 | { |
| 1535 | VariableExpr varExp = new VariableExpr(); |
| 1536 | VarIdentifier var = new VarIdentifier(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1537 | } |
| 1538 | { |
Till Westmann | 4f58e1a | 2013-05-20 18:29:54 -0700 | [diff] [blame] | 1539 | <VARIABLE> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1540 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1541 | Identifier ident = lookupSymbol(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1542 | if(ident != null) { // exist such ident |
| 1543 | varExp.setIsNewVar(false); |
| 1544 | } |
| 1545 | varExp.setVar(var); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1546 | var.setValue(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1547 | return varExp; |
| 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | Expression ListConstructor() throws ParseException: |
| 1552 | { |
| 1553 | Expression expr = null; |
| 1554 | } |
| 1555 | { |
| 1556 | ( |
| 1557 | expr = OrderedListConstructor() | expr = UnorderedListConstructor() |
| 1558 | ) |
| 1559 | |
| 1560 | { |
| 1561 | return expr; |
| 1562 | } |
| 1563 | } |
| 1564 | |
| 1565 | |
| 1566 | ListConstructor OrderedListConstructor() throws ParseException: |
| 1567 | { |
| 1568 | ListConstructor expr = new ListConstructor(); |
| 1569 | Expression tmp = null; |
| 1570 | List<Expression> exprList = new ArrayList<Expression>(); |
| 1571 | expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR); |
| 1572 | } |
| 1573 | { |
| 1574 | |
| 1575 | "[" |
| 1576 | ( tmp = Expression() |
| 1577 | { |
| 1578 | exprList.add(tmp); |
| 1579 | } |
| 1580 | |
| 1581 | ("," tmp = Expression() { exprList.add(tmp); })* |
| 1582 | )? |
| 1583 | |
| 1584 | "]" |
| 1585 | |
| 1586 | { |
| 1587 | expr.setExprList(exprList); |
| 1588 | return expr; |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | ListConstructor UnorderedListConstructor() throws ParseException: |
| 1593 | { |
| 1594 | ListConstructor expr = new ListConstructor(); |
| 1595 | Expression tmp = null; |
| 1596 | List<Expression> exprList = new ArrayList<Expression>(); |
| 1597 | expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR); |
| 1598 | } |
| 1599 | { |
| 1600 | |
| 1601 | "{{" ( tmp = Expression() |
| 1602 | { |
| 1603 | exprList.add(tmp); |
| 1604 | } |
| 1605 | ("," tmp = Expression() { exprList.add(tmp); })*)? "}}" |
| 1606 | { |
| 1607 | expr.setExprList(exprList); |
| 1608 | return expr; |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | RecordConstructor RecordConstructor() throws ParseException: |
| 1613 | { |
| 1614 | RecordConstructor expr = new RecordConstructor(); |
| 1615 | FieldBinding tmp = null; |
| 1616 | List<FieldBinding> fbList = new ArrayList<FieldBinding>(); |
| 1617 | } |
| 1618 | { |
| 1619 | "{" (tmp = FieldBinding() |
| 1620 | { |
| 1621 | fbList.add(tmp); |
| 1622 | } |
| 1623 | ("," tmp = FieldBinding() { fbList.add(tmp); })*)? "}" |
| 1624 | { |
| 1625 | expr.setFbList(fbList); |
| 1626 | return expr; |
| 1627 | } |
| 1628 | } |
| 1629 | |
| 1630 | FieldBinding FieldBinding() throws ParseException: |
| 1631 | { |
| 1632 | FieldBinding fb = new FieldBinding(); |
| 1633 | Expression left, right; |
| 1634 | } |
| 1635 | { |
| 1636 | left = Expression() ":" right = Expression() |
| 1637 | { |
| 1638 | fb.setLeftExpr(left); |
| 1639 | fb.setRightExpr(right); |
| 1640 | return fb; |
| 1641 | } |
| 1642 | } |
| 1643 | |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1644 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1645 | Expression FunctionCallExpr() throws ParseException: |
| 1646 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1647 | CallExpr callExpr; |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1648 | List<Expression> argList = new ArrayList<Expression>(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1649 | Expression tmp; |
| 1650 | int arity = 0; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1651 | Pair<Identifier,Identifier> funcId = null; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1652 | String funcName; |
| 1653 | String dataverse; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1654 | String hint = null; |
| 1655 | String id1 = null; |
| 1656 | String id2 = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1657 | } |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1658 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1659 | funcId = FunctionOrTypeName() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1660 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1661 | dataverse = funcId.first.getValue(); |
| 1662 | funcName = funcId.second.getValue(); |
| 1663 | hint = getHint(token); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1664 | } |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1665 | <LEFTPAREN> (tmp = Expression() |
| 1666 | { |
| 1667 | argList.add(tmp); |
| 1668 | arity ++; |
| 1669 | } |
| 1670 | ("," tmp = Expression() |
| 1671 | { |
| 1672 | argList.add(tmp); |
| 1673 | arity++; |
| 1674 | } |
| 1675 | )*)? <RIGHTPAREN> |
| 1676 | { |
| 1677 | FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, arity); |
| 1678 | if (signature == null) { |
| 1679 | signature = new FunctionSignature(dataverse, funcName, arity); |
| 1680 | } |
| 1681 | callExpr = new CallExpr(signature,argList); |
| 1682 | if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) { |
| 1683 | callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE); |
| 1684 | } |
| 1685 | return callExpr; |
| 1686 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1687 | } |
| 1688 | |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 1689 | Expression DatasetAccessExpression() throws ParseException: |
| 1690 | { |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 1691 | String funcName; |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1692 | String arg1 = null; |
| 1693 | String arg2 = null; |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 1694 | Expression nameArg; |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 1695 | } |
| 1696 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1697 | <DATASET> |
| 1698 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1699 | funcName = token.image; |
| 1700 | } |
| 1701 | ( ( arg1 = Identifier() ( "." arg2 = Identifier() )? ) |
| 1702 | { |
| 1703 | String name = arg2 == null ? arg1 : arg1 + "." + arg2; |
Till Westmann | 1f7a236 | 2013-05-24 08:43:40 -0700 | [diff] [blame] | 1704 | LiteralExpr ds = new LiteralExpr(); |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1705 | ds.setValue( new StringLiteral(name) ); |
Till Westmann | 1f7a236 | 2013-05-24 08:43:40 -0700 | [diff] [blame] | 1706 | nameArg = ds; |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1707 | } |
Till Westmann | 1f7a236 | 2013-05-24 08:43:40 -0700 | [diff] [blame] | 1708 | | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) ) |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1709 | { |
Till Westmann | 1f7a236 | 2013-05-24 08:43:40 -0700 | [diff] [blame] | 1710 | String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME; |
| 1711 | FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1); |
| 1712 | if (signature == null) { |
| 1713 | signature = new FunctionSignature(dataverse, funcName, 1); |
| 1714 | } |
| 1715 | List<Expression> argList = new ArrayList<Expression>(); |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1716 | argList.add(nameArg); |
Till Westmann | 1f7a236 | 2013-05-24 08:43:40 -0700 | [diff] [blame] | 1717 | return new CallExpr(signature, argList); |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1718 | } |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 1719 | } |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1720 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1721 | Expression ParenthesizedExpression() throws ParseException: |
| 1722 | { |
| 1723 | Expression expr; |
| 1724 | } |
| 1725 | { |
| 1726 | <LEFTPAREN> expr = Expression() <RIGHTPAREN> |
| 1727 | { |
| 1728 | return expr; |
| 1729 | } |
| 1730 | } |
| 1731 | |
| 1732 | Expression IfThenElse() throws ParseException: |
| 1733 | { |
| 1734 | Expression condExpr; |
| 1735 | Expression thenExpr; |
| 1736 | Expression elseExpr; |
| 1737 | IfExpr ifExpr = new IfExpr(); |
| 1738 | } |
| 1739 | { |
| 1740 | "if" <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> "then" thenExpr = Expression() "else" elseExpr = Expression() |
| 1741 | |
| 1742 | { |
| 1743 | ifExpr.setCondExpr(condExpr); |
| 1744 | ifExpr.setThenExpr(thenExpr); |
| 1745 | ifExpr.setElseExpr(elseExpr); |
| 1746 | return ifExpr; |
| 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | Expression FLWOGR() throws ParseException: |
| 1751 | { |
| 1752 | FLWOGRExpression flworg = new FLWOGRExpression(); |
| 1753 | List<Clause> clauseList = new ArrayList<Clause>(); |
| 1754 | Expression returnExpr; |
| 1755 | Clause tmp; |
| 1756 | createNewScope(); |
| 1757 | } |
| 1758 | { |
| 1759 | (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);}) |
| 1760 | (tmp = Clause() {clauseList.add(tmp);})* "return" returnExpr = Expression() |
| 1761 | |
| 1762 | { |
| 1763 | flworg.setClauseList(clauseList); |
| 1764 | flworg.setReturnExpr(returnExpr); |
| 1765 | removeCurrentScope(); |
| 1766 | return flworg; |
| 1767 | } |
| 1768 | } |
| 1769 | |
| 1770 | Clause Clause()throws ParseException : |
| 1771 | { |
| 1772 | Clause clause; |
| 1773 | } |
| 1774 | { |
| 1775 | ( |
| 1776 | clause = ForClause() |
| 1777 | | clause = LetClause() |
| 1778 | | clause = WhereClause() |
| 1779 | | clause = OrderbyClause() |
| 1780 | | clause = GroupClause() |
| 1781 | | clause = LimitClause() |
| 1782 | | clause = DistinctClause() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1783 | ) |
| 1784 | { |
| 1785 | return clause; |
| 1786 | } |
| 1787 | } |
| 1788 | |
| 1789 | Clause ForClause()throws ParseException : |
| 1790 | { |
| 1791 | ForClause fc = new ForClause(); |
| 1792 | VariableExpr varExp; |
| 1793 | VariableExpr varPos = null; |
| 1794 | Expression inExp; |
| 1795 | extendCurrentScope(); |
| 1796 | } |
| 1797 | { |
Vinayak Borkar | 62e66c0 | 2013-05-28 13:56:11 -0700 | [diff] [blame] | 1798 | "for" varExp = Variable() ("at" varPos = Variable())? "in" ( inExp = Expression() ) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1799 | { |
| 1800 | fc.setVarExpr(varExp); |
Vinayak Borkar | 62e66c0 | 2013-05-28 13:56:11 -0700 | [diff] [blame] | 1801 | getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1802 | fc.setInExpr(inExp); |
| 1803 | if (varPos != null) { |
| 1804 | fc.setPosExpr(varPos); |
Vinayak Borkar | 62e66c0 | 2013-05-28 13:56:11 -0700 | [diff] [blame] | 1805 | getCurrentScope().addNewVarSymbolToScope(varPos.getVar()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1806 | } |
| 1807 | return fc; |
| 1808 | } |
| 1809 | } |
| 1810 | |
| 1811 | Clause LetClause() throws ParseException: |
| 1812 | { |
| 1813 | LetClause lc = new LetClause(); |
| 1814 | VariableExpr varExp; |
| 1815 | Expression beExp; |
| 1816 | extendCurrentScope(); |
| 1817 | } |
| 1818 | { |
ilovesoup | b2527c1 | 2012-07-12 03:21:13 +0000 | [diff] [blame] | 1819 | "let" varExp = Variable() ":=" beExp = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1820 | { |
| 1821 | getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1822 | lc.setVarExpr(varExp); |
| 1823 | lc.setBeExpr(beExp); |
| 1824 | return lc; |
| 1825 | } |
| 1826 | } |
| 1827 | |
| 1828 | Clause WhereClause()throws ParseException : |
| 1829 | { |
| 1830 | WhereClause wc = new WhereClause(); |
| 1831 | Expression whereExpr; |
| 1832 | } |
| 1833 | { |
| 1834 | "where" whereExpr = Expression() |
| 1835 | { |
| 1836 | wc.setWhereExpr(whereExpr); |
| 1837 | return wc; |
| 1838 | } |
| 1839 | } |
| 1840 | |
| 1841 | Clause OrderbyClause()throws ParseException : |
| 1842 | { |
| 1843 | OrderbyClause oc = new OrderbyClause(); |
| 1844 | Expression orderbyExpr; |
| 1845 | List<Expression> orderbyList = new ArrayList<Expression>(); |
| 1846 | List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >(); |
| 1847 | int numOfOrderby = 0; |
| 1848 | } |
| 1849 | { |
| 1850 | ( |
| 1851 | "order" |
| 1852 | { |
| 1853 | String hint = getHint(token); |
| 1854 | if (hint != null && hint.startsWith(INMEMORY_HINT)) { |
| 1855 | String splits[] = hint.split(" +"); |
| 1856 | int numFrames = Integer.parseInt(splits[1]); |
| 1857 | int numTuples = Integer.parseInt(splits[2]); |
| 1858 | oc.setNumFrames(numFrames); |
| 1859 | oc.setNumTuples(numTuples); |
| 1860 | } |
| 1861 | } |
| 1862 | "by" orderbyExpr = Expression() |
| 1863 | { |
| 1864 | orderbyList.add(orderbyExpr); |
| 1865 | OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC; |
| 1866 | } |
| 1867 | ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; }) |
| 1868 | | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))? |
| 1869 | { |
| 1870 | modifierList.add(modif); |
| 1871 | } |
| 1872 | |
| 1873 | ("," orderbyExpr = Expression() |
| 1874 | { |
| 1875 | orderbyList.add(orderbyExpr); |
| 1876 | modif = OrderbyClause.OrderModifier.ASC; |
| 1877 | } |
| 1878 | ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; }) |
| 1879 | | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))? |
| 1880 | { |
| 1881 | modifierList.add(modif); |
| 1882 | } |
| 1883 | )* |
| 1884 | ) |
| 1885 | { |
| 1886 | oc.setModifierList(modifierList); |
| 1887 | oc.setOrderbyList(orderbyList); |
| 1888 | return oc; |
| 1889 | } |
| 1890 | } |
| 1891 | Clause GroupClause()throws ParseException : |
| 1892 | { |
| 1893 | GroupbyClause gbc = new GroupbyClause(); |
| 1894 | // GbyVariableExpressionPair pair = new GbyVariableExpressionPair(); |
| 1895 | List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>(); |
| 1896 | List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>(); |
| 1897 | List<VariableExpr> withVarList= new ArrayList<VariableExpr>(); |
| 1898 | VariableExpr var = null; |
| 1899 | VariableExpr withVar = null; |
| 1900 | Expression expr = null; |
| 1901 | VariableExpr decorVar = null; |
| 1902 | Expression decorExpr = null; |
| 1903 | } |
| 1904 | { |
| 1905 | { |
| 1906 | Scope newScope = extendCurrentScopeNoPush(true); |
| 1907 | // extendCurrentScope(true); |
| 1908 | } |
| 1909 | "group" |
| 1910 | { |
| 1911 | String hint = getHint(token); |
| 1912 | if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) { |
| 1913 | gbc.setHashGroupByHint(true); |
| 1914 | } |
| 1915 | } |
| 1916 | "by" (LOOKAHEAD(2) var = Variable() |
| 1917 | { |
| 1918 | newScope.addNewVarSymbolToScope(var.getVar()); |
| 1919 | } ":=")? |
| 1920 | expr = Expression() |
| 1921 | { |
| 1922 | GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr); |
| 1923 | vePairList.add(pair1); |
| 1924 | } |
| 1925 | ("," ( LOOKAHEAD(2) var = Variable() |
| 1926 | { |
| 1927 | newScope.addNewVarSymbolToScope(var.getVar()); |
| 1928 | } ":=")? |
| 1929 | expr = Expression() |
| 1930 | { |
| 1931 | GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr); |
| 1932 | vePairList.add(pair2); |
| 1933 | } |
| 1934 | )* |
| 1935 | ("decor" decorVar = Variable() ":=" decorExpr = Expression() |
| 1936 | { |
| 1937 | newScope.addNewVarSymbolToScope(decorVar.getVar()); |
| 1938 | GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr); |
| 1939 | decorPairList.add(pair3); |
| 1940 | } |
| 1941 | ("," "decor" decorVar = Variable() ":=" decorExpr = Expression() |
| 1942 | { |
| 1943 | newScope.addNewVarSymbolToScope(decorVar.getVar()); |
| 1944 | GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr); |
| 1945 | decorPairList.add(pair4); |
| 1946 | } |
| 1947 | )* |
| 1948 | )? |
| 1949 | "with" withVar = VariableRef() |
| 1950 | { |
| 1951 | if(withVar.getIsNewVar()==true) |
| 1952 | throw new ParseException("can't find variable " + withVar.getVar()); |
| 1953 | withVarList.add(withVar); |
| 1954 | newScope.addNewVarSymbolToScope(withVar.getVar()); |
| 1955 | } |
| 1956 | ("," withVar = VariableRef() |
| 1957 | { |
| 1958 | if(withVar.getIsNewVar()==true) |
| 1959 | throw new ParseException("can't find variable " + withVar.getVar()); |
| 1960 | withVarList.add(withVar); |
| 1961 | newScope.addNewVarSymbolToScope(withVar.getVar()); |
| 1962 | })* |
| 1963 | { |
| 1964 | gbc.setGbyPairList(vePairList); |
| 1965 | gbc.setDecorPairList(decorPairList); |
| 1966 | gbc.setWithVarList(withVarList); |
| 1967 | replaceCurrentScope(newScope); |
| 1968 | return gbc; |
| 1969 | } |
| 1970 | } |
| 1971 | |
| 1972 | |
| 1973 | LimitClause LimitClause() throws ParseException: |
| 1974 | { |
| 1975 | LimitClause lc = new LimitClause(); |
| 1976 | Expression expr; |
| 1977 | pushForbiddenScope(getCurrentScope()); |
| 1978 | } |
| 1979 | { |
| 1980 | "limit" expr = Expression() { lc.setLimitExpr(expr); } |
| 1981 | ("offset" expr = Expression() { lc.setOffset(expr); })? |
| 1982 | |
| 1983 | { |
| 1984 | popForbiddenScope(); |
| 1985 | return lc; |
| 1986 | } |
| 1987 | } |
| 1988 | |
| 1989 | DistinctClause DistinctClause() throws ParseException: |
| 1990 | { |
| 1991 | List<Expression> exprs = new ArrayList<Expression>(); |
| 1992 | Expression expr; |
| 1993 | } |
| 1994 | { |
| 1995 | "distinct" "by" expr = Expression() |
| 1996 | { |
| 1997 | exprs.add(expr); |
| 1998 | } |
| 1999 | ("," expr = Expression() |
| 2000 | { |
| 2001 | exprs.add(expr); |
| 2002 | } |
| 2003 | )* |
| 2004 | { |
| 2005 | return new DistinctClause(exprs); |
| 2006 | } |
| 2007 | } |
| 2008 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2009 | QuantifiedExpression QuantifiedExpression()throws ParseException: |
| 2010 | { |
| 2011 | QuantifiedExpression qc = new QuantifiedExpression(); |
| 2012 | List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>(); |
| 2013 | Expression satisfiesExpr; |
| 2014 | VariableExpr var; |
| 2015 | Expression inExpr; |
| 2016 | QuantifiedPair pair; |
| 2017 | } |
| 2018 | { |
| 2019 | { |
| 2020 | createNewScope(); |
| 2021 | } |
| 2022 | |
| 2023 | ( ("some" { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); }) |
| 2024 | | ("every" { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); })) |
| 2025 | var = Variable() "in" inExpr = Expression() |
| 2026 | { |
| 2027 | pair = new QuantifiedPair(var, inExpr); |
| 2028 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 2029 | quantifiedList.add(pair); |
| 2030 | } |
| 2031 | ( |
| 2032 | "," var = Variable() "in" inExpr = Expression() |
| 2033 | { |
| 2034 | pair = new QuantifiedPair(var, inExpr); |
| 2035 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 2036 | quantifiedList.add(pair); |
| 2037 | } |
| 2038 | )* |
| 2039 | "satisfies" satisfiesExpr = Expression() |
| 2040 | { |
| 2041 | qc.setSatisfiesExpr(satisfiesExpr); |
| 2042 | qc.setQuantifiedList(quantifiedList); |
| 2043 | removeCurrentScope(); |
| 2044 | return qc; |
| 2045 | } |
| 2046 | } |
| 2047 | |
| 2048 | TOKEN_MGR_DECLS: |
| 2049 | { |
| 2050 | public int commentDepth = 0; |
| 2051 | } |
| 2052 | |
| 2053 | <DEFAULT> |
| 2054 | TOKEN : |
| 2055 | { |
| 2056 | <CARET : "^" > |
| 2057 | } |
| 2058 | |
| 2059 | <DEFAULT> |
| 2060 | TOKEN : |
| 2061 | { |
| 2062 | <DATASET : "dataset" > |
| 2063 | } |
| 2064 | |
| 2065 | <DEFAULT> |
| 2066 | TOKEN : |
| 2067 | { |
| 2068 | <LEFTPAREN : "(" > |
| 2069 | } |
| 2070 | |
| 2071 | <DEFAULT> |
| 2072 | TOKEN : |
| 2073 | { |
| 2074 | <RIGHTPAREN : ")" > |
| 2075 | } |
| 2076 | |
| 2077 | |
| 2078 | <DEFAULT> |
| 2079 | TOKEN : |
| 2080 | { |
| 2081 | <INTEGER_LITERAL : (<DIGIT>)+ > |
| 2082 | } |
| 2083 | |
| 2084 | |
| 2085 | <DEFAULT> |
| 2086 | TOKEN : |
| 2087 | { |
| 2088 | <NULL : "null"> |
| 2089 | } |
| 2090 | |
| 2091 | <DEFAULT> |
| 2092 | TOKEN : |
| 2093 | { |
| 2094 | <TRUE : "true"> |
| 2095 | } |
| 2096 | |
| 2097 | <DEFAULT> |
| 2098 | TOKEN : |
| 2099 | { |
| 2100 | <FALSE : "false"> |
| 2101 | } |
| 2102 | |
| 2103 | <DEFAULT> |
| 2104 | TOKEN : |
| 2105 | { |
| 2106 | <#DIGIT : ["0" - "9"]> |
| 2107 | } |
| 2108 | |
| 2109 | |
| 2110 | TOKEN: |
| 2111 | { |
| 2112 | < DOUBLE_LITERAL: <INTEGER> |
| 2113 | | <INTEGER> ( "." <INTEGER> )? |
| 2114 | | "." <INTEGER> |
| 2115 | > |
| 2116 | | |
| 2117 | < FLOAT_LITERAL: <INTEGER> ( "f" | "F" ) |
| 2118 | | <INTEGER> ( "." <INTEGER> ( "f" | "F" ) )? |
| 2119 | | "." <INTEGER> ( "f" | "F" ) |
| 2120 | > |
| 2121 | | |
| 2122 | <INTEGER : (<DIGIT>)+ > |
| 2123 | } |
| 2124 | |
| 2125 | <DEFAULT> |
| 2126 | TOKEN : |
| 2127 | { |
| 2128 | <#LETTER : ["A" - "Z", "a" - "z"]> |
| 2129 | } |
| 2130 | |
| 2131 | <DEFAULT> |
| 2132 | TOKEN : |
| 2133 | { |
| 2134 | <SPECIALCHARS : ["$", "_", "-"] > |
| 2135 | } |
| 2136 | |
| 2137 | <DEFAULT> |
| 2138 | TOKEN : |
| 2139 | { |
| 2140 | <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")> |
| 2141 | | |
| 2142 | < #EscapeQuot: "\\\"" > |
| 2143 | | |
| 2144 | < #EscapeApos: "\\\'" > |
| 2145 | } |
| 2146 | |
| 2147 | <DEFAULT> |
| 2148 | TOKEN : |
| 2149 | { |
| 2150 | <IDENTIFIER : (<LETTER>)+ (<LETTER> | <DIGIT> | <SPECIALCHARS>)*> |
| 2151 | } |
| 2152 | |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 2153 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2154 | <DEFAULT> |
| 2155 | TOKEN : |
| 2156 | { |
Till Westmann | 4f58e1a | 2013-05-20 18:29:54 -0700 | [diff] [blame] | 2157 | <VARIABLE : "$" (<LETTER>)+ (<LETTER> | <DIGIT> | "_")* > |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | SKIP: |
| 2161 | { |
| 2162 | " " |
| 2163 | | "\t" |
| 2164 | | "\r" |
| 2165 | | "\n" |
| 2166 | } |
| 2167 | |
| 2168 | SKIP: |
| 2169 | { |
| 2170 | <"//" (~["\n"])* "\n"> |
| 2171 | } |
| 2172 | |
| 2173 | SKIP: |
| 2174 | { |
| 2175 | <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?> |
| 2176 | } |
| 2177 | |
| 2178 | |
| 2179 | SKIP: |
| 2180 | { |
| 2181 | <"/*"> {commentDepth=1;}: INSIDE_COMMENT |
| 2182 | } |
| 2183 | |
| 2184 | <INSIDE_COMMENT> |
| 2185 | SPECIAL_TOKEN: |
| 2186 | { |
| 2187 | <"+"(" ")*(~["*"])*> |
| 2188 | } |
| 2189 | |
| 2190 | <INSIDE_COMMENT> |
| 2191 | SKIP: |
| 2192 | { |
| 2193 | <"/*"> {commentDepth++;} |
| 2194 | } |
| 2195 | |
| 2196 | <INSIDE_COMMENT> |
| 2197 | SKIP: |
| 2198 | { |
| 2199 | <"*/"> {commentDepth--; if (commentDepth == 0) SwitchTo(DEFAULT);} |
| 2200 | | <~[]> |
| 2201 | } |