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