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