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); |
| 1124 | return funcDecl; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1125 | } |
| 1126 | } |
| 1127 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1128 | |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1129 | Query Query() throws ParseException: |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1130 | { |
| 1131 | Query query = new Query(); |
| 1132 | Expression expr; |
| 1133 | } |
| 1134 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1135 | expr = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1136 | { |
| 1137 | query.setBody(expr); |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1138 | query.setVarCounter(getVarCounter()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1139 | return query; |
| 1140 | } |
RamanGrover29@gmail.com | c022a0d | 2012-07-28 05:13:44 +0000 | [diff] [blame] | 1141 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | |
| 1145 | |
| 1146 | Expression Expression(): |
| 1147 | { |
| 1148 | Expression expr = null; |
| 1149 | Expression exprP = null; |
| 1150 | } |
| 1151 | { |
| 1152 | ( |
| 1153 | |
| 1154 | //OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression |
| 1155 | expr = OperatorExpr() |
| 1156 | | expr = IfThenElse() |
| 1157 | | expr = FLWOGR() |
| 1158 | | expr = QuantifiedExpression() |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1159 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1160 | |
| 1161 | ) |
| 1162 | { |
| 1163 | return (exprP==null) ? expr : exprP; |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | |
| 1168 | |
| 1169 | Expression OperatorExpr()throws ParseException: |
| 1170 | { |
| 1171 | OperatorExpr op = null; |
| 1172 | Expression operand = null; |
| 1173 | } |
| 1174 | { |
| 1175 | operand = AndExpr() |
| 1176 | ( |
| 1177 | |
| 1178 | "or" |
| 1179 | { |
| 1180 | if (op == null) { |
| 1181 | op = new OperatorExpr(); |
| 1182 | op.addOperand(operand); |
| 1183 | op.setCurrentop(true); |
| 1184 | } |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1185 | op.addOperator(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | operand = AndExpr() |
| 1189 | { |
| 1190 | op.addOperand(operand); |
| 1191 | } |
| 1192 | |
| 1193 | )* |
| 1194 | |
| 1195 | { |
| 1196 | return op==null? operand: op; |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | Expression AndExpr()throws ParseException: |
| 1201 | { |
| 1202 | OperatorExpr op = null; |
| 1203 | Expression operand = null; |
| 1204 | } |
| 1205 | { |
| 1206 | operand = RelExpr() |
| 1207 | ( |
| 1208 | |
| 1209 | "and" |
| 1210 | { |
| 1211 | if (op == null) { |
| 1212 | op = new OperatorExpr(); |
| 1213 | op.addOperand(operand); |
| 1214 | op.setCurrentop(true); |
| 1215 | } |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1216 | op.addOperator(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | operand = RelExpr() |
| 1220 | { |
| 1221 | op.addOperand(operand); |
| 1222 | } |
| 1223 | |
| 1224 | )* |
| 1225 | |
| 1226 | { |
| 1227 | return op==null? operand: op; |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | |
| 1232 | |
| 1233 | Expression RelExpr()throws ParseException: |
| 1234 | { |
| 1235 | OperatorExpr op = null; |
| 1236 | Expression operand = null; |
| 1237 | boolean broadcast = false; |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1238 | IExpressionAnnotation annotation = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1239 | } |
| 1240 | { |
| 1241 | operand = AddExpr() |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1242 | { |
| 1243 | if (operand instanceof VariableExpr) { |
| 1244 | String hint = getHint(token); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1245 | if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) { |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1246 | broadcast = true; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1247 | } |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | ( |
| 1252 | LOOKAHEAD(2)( "<" | ">" | "<=" | ">=" | "=" | "!=" |"~=") |
| 1253 | { |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1254 | String mhint = getHint(token); |
| 1255 | if (mhint != null && mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) { |
| 1256 | annotation = IndexedNLJoinExpressionAnnotation.INSTANCE; |
| 1257 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1258 | if (op == null) { |
| 1259 | op = new OperatorExpr(); |
| 1260 | op.addOperand(operand, broadcast); |
| 1261 | op.setCurrentop(true); |
| 1262 | broadcast = false; |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1263 | } |
| 1264 | op.addOperator(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | operand = AddExpr() |
| 1268 | { |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1269 | broadcast = false; |
| 1270 | if (operand instanceof VariableExpr) { |
| 1271 | String hint = getHint(token); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1272 | if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) { |
| 1273 | broadcast = true; |
| 1274 | } |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1275 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1276 | op.addOperand(operand, broadcast); |
| 1277 | } |
| 1278 | )? |
| 1279 | |
| 1280 | { |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1281 | if (annotation != null) { |
| 1282 | op.addHint(annotation); |
| 1283 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1284 | return op==null? operand: op; |
| 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | Expression AddExpr()throws ParseException: |
| 1289 | { |
| 1290 | OperatorExpr op = null; |
| 1291 | Expression operand = null; |
| 1292 | } |
| 1293 | { |
| 1294 | operand = MultExpr() |
| 1295 | |
| 1296 | ( ("+" | "-") |
| 1297 | { |
| 1298 | if (op == null) { |
| 1299 | op = new OperatorExpr(); |
| 1300 | op.addOperand(operand); |
| 1301 | op.setCurrentop(true); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1302 | } |
| 1303 | ((OperatorExpr)op).addOperator(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | operand = MultExpr() |
| 1307 | { |
| 1308 | op.addOperand(operand); |
| 1309 | } |
| 1310 | )* |
| 1311 | |
| 1312 | { |
| 1313 | return op==null? operand: op; |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | Expression MultExpr()throws ParseException: |
| 1318 | { |
| 1319 | OperatorExpr op = null; |
| 1320 | Expression operand = null; |
| 1321 | } |
| 1322 | { |
| 1323 | operand = UnionExpr() |
| 1324 | |
| 1325 | (( "*" | "/" | "%" | <CARET> | "idiv") |
| 1326 | { |
| 1327 | if (op == null) { |
| 1328 | op = new OperatorExpr(); |
| 1329 | op.addOperand(operand); |
| 1330 | op.setCurrentop(true); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1331 | } |
| 1332 | op.addOperator(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1333 | } |
| 1334 | operand = UnionExpr() |
| 1335 | { |
| 1336 | op.addOperand(operand); |
| 1337 | } |
| 1338 | )* |
| 1339 | |
| 1340 | { |
| 1341 | return op==null?operand:op; |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | Expression UnionExpr() throws ParseException: |
| 1346 | { |
| 1347 | UnionExpr union = null; |
| 1348 | Expression operand1 = null; |
| 1349 | Expression operand2 = null; |
| 1350 | } |
| 1351 | { |
| 1352 | operand1 = UnaryExpr() |
| 1353 | ("union" |
| 1354 | (operand2 = UnaryExpr()) { |
| 1355 | if (union == null) { |
| 1356 | union = new UnionExpr(); |
| 1357 | union.addExpr(operand1); |
| 1358 | } |
| 1359 | union.addExpr(operand2); |
| 1360 | } )* |
| 1361 | { |
| 1362 | return (union == null)? operand1: union; |
| 1363 | } |
| 1364 | } |
| 1365 | |
| 1366 | Expression UnaryExpr() throws ParseException: |
| 1367 | { |
| 1368 | Expression uexpr = null; |
| 1369 | Expression expr = null; |
| 1370 | } |
| 1371 | { |
| 1372 | (( "+"|"-") |
| 1373 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1374 | uexpr = new UnaryExpr(); |
| 1375 | if("+".equals(token.image)) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1376 | ((UnaryExpr)uexpr).setSign(Sign.POSITIVE); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1377 | else if("-".equals(token.image)) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1378 | ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE); |
| 1379 | else |
| 1380 | throw new ParseException(); |
| 1381 | } |
| 1382 | )? |
| 1383 | |
| 1384 | expr = ValueExpr() |
| 1385 | { |
| 1386 | if(uexpr!=null){ |
| 1387 | ((UnaryExpr)uexpr).setExpr(expr); |
| 1388 | return uexpr; |
| 1389 | } |
| 1390 | else{ |
| 1391 | return expr; |
| 1392 | } |
| 1393 | } |
| 1394 | } |
| 1395 | |
Till Westmann | 04478e7 | 2013-05-13 23:01:34 -0700 | [diff] [blame] | 1396 | Expression ValueExpr()throws ParseException: |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1397 | { |
| 1398 | Expression expr = null; |
| 1399 | Identifier ident = null; |
| 1400 | AbstractAccessor fa = null; |
| 1401 | int index; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1402 | } |
| 1403 | { |
Till Westmann | 04478e7 | 2013-05-13 23:01:34 -0700 | [diff] [blame] | 1404 | expr = PrimaryExpr() ( ident = Field() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1405 | { |
Till Westmann | 04478e7 | 2013-05-13 23:01:34 -0700 | [diff] [blame] | 1406 | fa = (fa == null ? new FieldAccessor(expr, ident) |
| 1407 | : new FieldAccessor(fa, ident)); |
| 1408 | } |
| 1409 | | index = Index() |
| 1410 | { |
| 1411 | fa = (fa == null ? new IndexAccessor(expr, index) |
| 1412 | : new IndexAccessor(fa, index)); |
| 1413 | } |
| 1414 | )* |
| 1415 | { |
| 1416 | return fa == null ? expr : fa; |
| 1417 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | Identifier Field() throws ParseException: |
| 1421 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1422 | String ident = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1423 | } |
| 1424 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1425 | "." ident = Identifier() |
| 1426 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1427 | return new Identifier(ident); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1428 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | int Index() throws ParseException: |
| 1432 | { |
| 1433 | Expression expr = null; |
| 1434 | int idx = -2; |
| 1435 | } |
| 1436 | { |
| 1437 | "[" ( expr = Expression() |
| 1438 | { |
| 1439 | if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION) |
| 1440 | { |
ilovesoup | c9fef1d | 2012-07-08 19:30:42 +0000 | [diff] [blame] | 1441 | Literal lit = ((LiteralExpr)expr).getValue(); |
| 1442 | if(lit.getLiteralType() == Literal.Type.INTEGER || |
| 1443 | lit.getLiteralType() == Literal.Type.LONG) { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1444 | idx = Integer.valueOf(lit.getStringValue()); |
ilovesoup | c9fef1d | 2012-07-08 19:30:42 +0000 | [diff] [blame] | 1445 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1446 | else { |
| 1447 | throw new ParseException("Index should be an INTEGER"); |
| 1448 | } |
| 1449 | } |
| 1450 | |
| 1451 | } |
| 1452 | |
| 1453 | | "?" |
| 1454 | { |
| 1455 | idx = IndexAccessor.ANY; |
| 1456 | // ANY |
| 1457 | } |
| 1458 | |
| 1459 | ) |
| 1460 | |
| 1461 | "]" |
| 1462 | { |
| 1463 | return idx; |
| 1464 | } |
| 1465 | } |
| 1466 | |
| 1467 | |
| 1468 | Expression PrimaryExpr()throws ParseException: |
| 1469 | { |
| 1470 | Expression expr = null; |
| 1471 | } |
| 1472 | { |
Till Westmann | 68d9965 | 2013-05-09 11:15:21 -0700 | [diff] [blame] | 1473 | ( LOOKAHEAD(2) |
| 1474 | expr = FunctionCallExpr() |
| 1475 | | expr = Literal() |
| 1476 | | expr = DatasetAccessExpression() |
| 1477 | | expr = VariableRef() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1478 | { |
| 1479 | if(((VariableExpr)expr).getIsNewVar() == true) |
Till Westmann | 68d9965 | 2013-05-09 11:15:21 -0700 | [diff] [blame] | 1480 | throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1481 | } |
Till Westmann | 68d9965 | 2013-05-09 11:15:21 -0700 | [diff] [blame] | 1482 | | expr = ListConstructor() |
| 1483 | | expr = RecordConstructor() |
| 1484 | | expr = ParenthesizedExpression() |
| 1485 | ) |
| 1486 | { |
| 1487 | return expr; |
| 1488 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | Expression Literal() throws ParseException: |
| 1492 | { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1493 | LiteralExpr lit = new LiteralExpr(); |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 1494 | String str = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1495 | } |
| 1496 | { |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 1497 | ( str = StringLiteral() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1498 | { |
Till Westmann | 7d53532 | 2013-05-09 00:40:02 -0700 | [diff] [blame] | 1499 | lit.setValue(new StringLiteral(str)); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1500 | } |
| 1501 | | <INTEGER_LITERAL> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1502 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1503 | try { |
| 1504 | lit.setValue(new IntegerLiteral(new Integer(token.image))); |
| 1505 | } catch(NumberFormatException ex) { |
| 1506 | lit.setValue(new LongIntegerLiteral(new Long(token.image))); |
| 1507 | } |
| 1508 | } |
| 1509 | | <FLOAT_LITERAL> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1510 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1511 | lit.setValue(new FloatLiteral(new Float(token.image))); |
| 1512 | } |
| 1513 | | <DOUBLE_LITERAL> |
| 1514 | { |
| 1515 | lit.setValue(new DoubleLiteral(new Double(token.image))); |
| 1516 | } |
| 1517 | | <NULL> |
| 1518 | { |
| 1519 | lit.setValue(NullLiteral.INSTANCE); |
| 1520 | } |
| 1521 | | <TRUE> |
| 1522 | { |
| 1523 | lit.setValue(TrueLiteral.INSTANCE); |
| 1524 | } |
| 1525 | | <FALSE> |
| 1526 | { |
| 1527 | lit.setValue(FalseLiteral.INSTANCE); |
| 1528 | } |
| 1529 | ) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1530 | { |
| 1531 | return lit; |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | |
| 1536 | VariableExpr VariableRef() throws ParseException: |
| 1537 | { |
| 1538 | VariableExpr varExp = new VariableExpr(); |
| 1539 | VarIdentifier var = new VarIdentifier(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1540 | } |
| 1541 | { |
| 1542 | <VARIABLE> |
| 1543 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1544 | String varName = token.image; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1545 | Identifier ident = lookupSymbol(varName); |
| 1546 | if (isInForbiddenScopes(varName)) { |
| 1547 | 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."); |
| 1548 | } |
| 1549 | if(ident != null) { // exist such ident |
| 1550 | varExp.setIsNewVar(false); |
| 1551 | varExp.setVar((VarIdentifier)ident); |
| 1552 | } else { |
| 1553 | varExp.setVar(var); |
| 1554 | } |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1555 | var.setValue(varName); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1556 | return varExp; |
| 1557 | } |
| 1558 | } |
| 1559 | |
| 1560 | |
| 1561 | VariableExpr Variable() throws ParseException: |
| 1562 | { |
| 1563 | VariableExpr varExp = new VariableExpr(); |
| 1564 | VarIdentifier var = new VarIdentifier(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1565 | } |
| 1566 | { |
| 1567 | <VARIABLE> |
| 1568 | { |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1569 | Identifier ident = lookupSymbol(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1570 | if(ident != null) { // exist such ident |
| 1571 | varExp.setIsNewVar(false); |
| 1572 | } |
| 1573 | varExp.setVar(var); |
Till Westmann | a4242bc | 2013-05-08 17:49:55 -0700 | [diff] [blame] | 1574 | var.setValue(token.image); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1575 | return varExp; |
| 1576 | } |
| 1577 | } |
| 1578 | |
| 1579 | Expression ListConstructor() throws ParseException: |
| 1580 | { |
| 1581 | Expression expr = null; |
| 1582 | } |
| 1583 | { |
| 1584 | ( |
| 1585 | expr = OrderedListConstructor() | expr = UnorderedListConstructor() |
| 1586 | ) |
| 1587 | |
| 1588 | { |
| 1589 | return expr; |
| 1590 | } |
| 1591 | } |
| 1592 | |
| 1593 | |
| 1594 | ListConstructor OrderedListConstructor() throws ParseException: |
| 1595 | { |
| 1596 | ListConstructor expr = new ListConstructor(); |
| 1597 | Expression tmp = null; |
| 1598 | List<Expression> exprList = new ArrayList<Expression>(); |
| 1599 | expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR); |
| 1600 | } |
| 1601 | { |
| 1602 | |
| 1603 | "[" |
| 1604 | ( tmp = Expression() |
| 1605 | { |
| 1606 | exprList.add(tmp); |
| 1607 | } |
| 1608 | |
| 1609 | ("," tmp = Expression() { exprList.add(tmp); })* |
| 1610 | )? |
| 1611 | |
| 1612 | "]" |
| 1613 | |
| 1614 | { |
| 1615 | expr.setExprList(exprList); |
| 1616 | return expr; |
| 1617 | } |
| 1618 | } |
| 1619 | |
| 1620 | ListConstructor UnorderedListConstructor() throws ParseException: |
| 1621 | { |
| 1622 | ListConstructor expr = new ListConstructor(); |
| 1623 | Expression tmp = null; |
| 1624 | List<Expression> exprList = new ArrayList<Expression>(); |
| 1625 | expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR); |
| 1626 | } |
| 1627 | { |
| 1628 | |
| 1629 | "{{" ( tmp = Expression() |
| 1630 | { |
| 1631 | exprList.add(tmp); |
| 1632 | } |
| 1633 | ("," tmp = Expression() { exprList.add(tmp); })*)? "}}" |
| 1634 | { |
| 1635 | expr.setExprList(exprList); |
| 1636 | return expr; |
| 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | RecordConstructor RecordConstructor() throws ParseException: |
| 1641 | { |
| 1642 | RecordConstructor expr = new RecordConstructor(); |
| 1643 | FieldBinding tmp = null; |
| 1644 | List<FieldBinding> fbList = new ArrayList<FieldBinding>(); |
| 1645 | } |
| 1646 | { |
| 1647 | "{" (tmp = FieldBinding() |
| 1648 | { |
| 1649 | fbList.add(tmp); |
| 1650 | } |
| 1651 | ("," tmp = FieldBinding() { fbList.add(tmp); })*)? "}" |
| 1652 | { |
| 1653 | expr.setFbList(fbList); |
| 1654 | return expr; |
| 1655 | } |
| 1656 | } |
| 1657 | |
| 1658 | FieldBinding FieldBinding() throws ParseException: |
| 1659 | { |
| 1660 | FieldBinding fb = new FieldBinding(); |
| 1661 | Expression left, right; |
| 1662 | } |
| 1663 | { |
| 1664 | left = Expression() ":" right = Expression() |
| 1665 | { |
| 1666 | fb.setLeftExpr(left); |
| 1667 | fb.setRightExpr(right); |
| 1668 | return fb; |
| 1669 | } |
| 1670 | } |
| 1671 | |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1672 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1673 | Expression FunctionCallExpr() throws ParseException: |
| 1674 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1675 | CallExpr callExpr; |
alexander.behm | 07617fd | 2012-07-25 10:13:50 +0000 | [diff] [blame] | 1676 | List<Expression> argList = new ArrayList<Expression>(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1677 | Expression tmp; |
| 1678 | int arity = 0; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1679 | Pair<Identifier,Identifier> funcId = null; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1680 | String funcName; |
| 1681 | String dataverse; |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1682 | String hint = null; |
| 1683 | String id1 = null; |
| 1684 | String id2 = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1685 | } |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1686 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1687 | funcId = FunctionOrTypeName() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1688 | { |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1689 | dataverse = funcId.first.getValue(); |
| 1690 | funcName = funcId.second.getValue(); |
| 1691 | hint = getHint(token); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1692 | } |
Till Westmann | 31c21f9 | 2013-05-08 09:21:53 -0700 | [diff] [blame] | 1693 | <LEFTPAREN> (tmp = Expression() |
| 1694 | { |
| 1695 | argList.add(tmp); |
| 1696 | arity ++; |
| 1697 | } |
| 1698 | ("," tmp = Expression() |
| 1699 | { |
| 1700 | argList.add(tmp); |
| 1701 | arity++; |
| 1702 | } |
| 1703 | )*)? <RIGHTPAREN> |
| 1704 | { |
| 1705 | FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, arity); |
| 1706 | if (signature == null) { |
| 1707 | signature = new FunctionSignature(dataverse, funcName, arity); |
| 1708 | } |
| 1709 | callExpr = new CallExpr(signature,argList); |
| 1710 | if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) { |
| 1711 | callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE); |
| 1712 | } |
| 1713 | return callExpr; |
| 1714 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1715 | } |
| 1716 | |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 1717 | Expression DatasetAccessExpression() throws ParseException: |
| 1718 | { |
| 1719 | CallExpr callExpr; |
| 1720 | List<Expression> argList = new ArrayList<Expression>(); |
| 1721 | String funcName; |
| 1722 | String dataverse; |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1723 | String arg1 = null; |
| 1724 | String arg2 = null; |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 1725 | LiteralExpr ds; |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 1726 | Expression nameArg; |
| 1727 | int arity = 0; |
| 1728 | } |
| 1729 | { |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1730 | <DATASET> |
| 1731 | { |
| 1732 | dataverse = MetadataConstants.METADATA_DATAVERSE_NAME; |
| 1733 | funcName = token.image; |
| 1734 | } |
| 1735 | ( ( arg1 = Identifier() ( "." arg2 = Identifier() )? ) |
| 1736 | { |
| 1737 | String name = arg2 == null ? arg1 : arg1 + "." + arg2; |
| 1738 | ds = new LiteralExpr(); |
| 1739 | ds.setValue( new StringLiteral(name) ); |
| 1740 | argList.add(ds); |
| 1741 | arity ++; |
| 1742 | } |
| 1743 | | ( <LEFTPAREN> nameArg = Expression() |
| 1744 | { |
| 1745 | argList.add(nameArg); |
| 1746 | arity ++; |
| 1747 | } |
| 1748 | ( "," nameArg = Expression() |
| 1749 | { |
| 1750 | argList.add(nameArg); |
| 1751 | arity++; |
| 1752 | } |
| 1753 | )* <RIGHTPAREN> ) ) |
| 1754 | { |
| 1755 | FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, arity); |
| 1756 | if (signature == null) { |
| 1757 | signature = new FunctionSignature(dataverse, funcName, arity); |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 1758 | } |
Till Westmann | 14a20a7 | 2013-05-09 00:06:24 -0700 | [diff] [blame] | 1759 | callExpr = new CallExpr(signature,argList); |
| 1760 | return callExpr; |
| 1761 | } |
pouria.pirzadeh@gmail.com | fa89074 | 2013-03-07 23:59:21 +0000 | [diff] [blame] | 1762 | } |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1763 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1764 | Expression ParenthesizedExpression() throws ParseException: |
| 1765 | { |
| 1766 | Expression expr; |
| 1767 | } |
| 1768 | { |
| 1769 | <LEFTPAREN> expr = Expression() <RIGHTPAREN> |
| 1770 | { |
| 1771 | return expr; |
| 1772 | } |
| 1773 | } |
| 1774 | |
| 1775 | Expression IfThenElse() throws ParseException: |
| 1776 | { |
| 1777 | Expression condExpr; |
| 1778 | Expression thenExpr; |
| 1779 | Expression elseExpr; |
| 1780 | IfExpr ifExpr = new IfExpr(); |
| 1781 | } |
| 1782 | { |
| 1783 | "if" <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> "then" thenExpr = Expression() "else" elseExpr = Expression() |
| 1784 | |
| 1785 | { |
| 1786 | ifExpr.setCondExpr(condExpr); |
| 1787 | ifExpr.setThenExpr(thenExpr); |
| 1788 | ifExpr.setElseExpr(elseExpr); |
| 1789 | return ifExpr; |
| 1790 | } |
| 1791 | } |
| 1792 | |
| 1793 | Expression FLWOGR() throws ParseException: |
| 1794 | { |
| 1795 | FLWOGRExpression flworg = new FLWOGRExpression(); |
| 1796 | List<Clause> clauseList = new ArrayList<Clause>(); |
| 1797 | Expression returnExpr; |
| 1798 | Clause tmp; |
| 1799 | createNewScope(); |
| 1800 | } |
| 1801 | { |
| 1802 | (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);}) |
| 1803 | (tmp = Clause() {clauseList.add(tmp);})* "return" returnExpr = Expression() |
| 1804 | |
| 1805 | { |
| 1806 | flworg.setClauseList(clauseList); |
| 1807 | flworg.setReturnExpr(returnExpr); |
| 1808 | removeCurrentScope(); |
| 1809 | return flworg; |
| 1810 | } |
| 1811 | } |
| 1812 | |
| 1813 | Clause Clause()throws ParseException : |
| 1814 | { |
| 1815 | Clause clause; |
| 1816 | } |
| 1817 | { |
| 1818 | ( |
| 1819 | clause = ForClause() |
| 1820 | | clause = LetClause() |
| 1821 | | clause = WhereClause() |
| 1822 | | clause = OrderbyClause() |
| 1823 | | clause = GroupClause() |
| 1824 | | clause = LimitClause() |
| 1825 | | clause = DistinctClause() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1826 | ) |
| 1827 | { |
| 1828 | return clause; |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | Clause ForClause()throws ParseException : |
| 1833 | { |
| 1834 | ForClause fc = new ForClause(); |
| 1835 | VariableExpr varExp; |
| 1836 | VariableExpr varPos = null; |
| 1837 | Expression inExp; |
| 1838 | extendCurrentScope(); |
| 1839 | } |
| 1840 | { |
| 1841 | "for" varExp = Variable() |
| 1842 | { |
| 1843 | getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); |
| 1844 | } |
| 1845 | ("at" varPos = Variable() |
| 1846 | { |
| 1847 | getCurrentScope().addNewVarSymbolToScope(varPos.getVar()); |
| 1848 | } |
| 1849 | )? |
| 1850 | "in" ( inExp = Expression() ) |
| 1851 | { |
| 1852 | fc.setVarExpr(varExp); |
| 1853 | fc.setInExpr(inExp); |
| 1854 | if (varPos != null) { |
| 1855 | fc.setPosExpr(varPos); |
| 1856 | } |
| 1857 | return fc; |
| 1858 | } |
| 1859 | } |
| 1860 | |
| 1861 | Clause LetClause() throws ParseException: |
| 1862 | { |
| 1863 | LetClause lc = new LetClause(); |
| 1864 | VariableExpr varExp; |
| 1865 | Expression beExp; |
| 1866 | extendCurrentScope(); |
| 1867 | } |
| 1868 | { |
ilovesoup | b2527c1 | 2012-07-12 03:21:13 +0000 | [diff] [blame] | 1869 | "let" varExp = Variable() ":=" beExp = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1870 | { |
| 1871 | getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1872 | lc.setVarExpr(varExp); |
| 1873 | lc.setBeExpr(beExp); |
| 1874 | return lc; |
| 1875 | } |
| 1876 | } |
| 1877 | |
| 1878 | Clause WhereClause()throws ParseException : |
| 1879 | { |
| 1880 | WhereClause wc = new WhereClause(); |
| 1881 | Expression whereExpr; |
| 1882 | } |
| 1883 | { |
| 1884 | "where" whereExpr = Expression() |
| 1885 | { |
| 1886 | wc.setWhereExpr(whereExpr); |
| 1887 | return wc; |
| 1888 | } |
| 1889 | } |
| 1890 | |
| 1891 | Clause OrderbyClause()throws ParseException : |
| 1892 | { |
| 1893 | OrderbyClause oc = new OrderbyClause(); |
| 1894 | Expression orderbyExpr; |
| 1895 | List<Expression> orderbyList = new ArrayList<Expression>(); |
| 1896 | List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >(); |
| 1897 | int numOfOrderby = 0; |
| 1898 | } |
| 1899 | { |
| 1900 | ( |
| 1901 | "order" |
| 1902 | { |
| 1903 | String hint = getHint(token); |
| 1904 | if (hint != null && hint.startsWith(INMEMORY_HINT)) { |
| 1905 | String splits[] = hint.split(" +"); |
| 1906 | int numFrames = Integer.parseInt(splits[1]); |
| 1907 | int numTuples = Integer.parseInt(splits[2]); |
| 1908 | oc.setNumFrames(numFrames); |
| 1909 | oc.setNumTuples(numTuples); |
| 1910 | } |
| 1911 | } |
| 1912 | "by" orderbyExpr = Expression() |
| 1913 | { |
| 1914 | orderbyList.add(orderbyExpr); |
| 1915 | OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC; |
| 1916 | } |
| 1917 | ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; }) |
| 1918 | | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))? |
| 1919 | { |
| 1920 | modifierList.add(modif); |
| 1921 | } |
| 1922 | |
| 1923 | ("," orderbyExpr = Expression() |
| 1924 | { |
| 1925 | orderbyList.add(orderbyExpr); |
| 1926 | modif = OrderbyClause.OrderModifier.ASC; |
| 1927 | } |
| 1928 | ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; }) |
| 1929 | | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))? |
| 1930 | { |
| 1931 | modifierList.add(modif); |
| 1932 | } |
| 1933 | )* |
| 1934 | ) |
| 1935 | { |
| 1936 | oc.setModifierList(modifierList); |
| 1937 | oc.setOrderbyList(orderbyList); |
| 1938 | return oc; |
| 1939 | } |
| 1940 | } |
| 1941 | Clause GroupClause()throws ParseException : |
| 1942 | { |
| 1943 | GroupbyClause gbc = new GroupbyClause(); |
| 1944 | // GbyVariableExpressionPair pair = new GbyVariableExpressionPair(); |
| 1945 | List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>(); |
| 1946 | List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>(); |
| 1947 | List<VariableExpr> withVarList= new ArrayList<VariableExpr>(); |
| 1948 | VariableExpr var = null; |
| 1949 | VariableExpr withVar = null; |
| 1950 | Expression expr = null; |
| 1951 | VariableExpr decorVar = null; |
| 1952 | Expression decorExpr = null; |
| 1953 | } |
| 1954 | { |
| 1955 | { |
| 1956 | Scope newScope = extendCurrentScopeNoPush(true); |
| 1957 | // extendCurrentScope(true); |
| 1958 | } |
| 1959 | "group" |
| 1960 | { |
| 1961 | String hint = getHint(token); |
| 1962 | if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) { |
| 1963 | gbc.setHashGroupByHint(true); |
| 1964 | } |
| 1965 | } |
| 1966 | "by" (LOOKAHEAD(2) var = Variable() |
| 1967 | { |
| 1968 | newScope.addNewVarSymbolToScope(var.getVar()); |
| 1969 | } ":=")? |
| 1970 | expr = Expression() |
| 1971 | { |
| 1972 | GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr); |
| 1973 | vePairList.add(pair1); |
| 1974 | } |
| 1975 | ("," ( LOOKAHEAD(2) var = Variable() |
| 1976 | { |
| 1977 | newScope.addNewVarSymbolToScope(var.getVar()); |
| 1978 | } ":=")? |
| 1979 | expr = Expression() |
| 1980 | { |
| 1981 | GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr); |
| 1982 | vePairList.add(pair2); |
| 1983 | } |
| 1984 | )* |
| 1985 | ("decor" decorVar = Variable() ":=" decorExpr = Expression() |
| 1986 | { |
| 1987 | newScope.addNewVarSymbolToScope(decorVar.getVar()); |
| 1988 | GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr); |
| 1989 | decorPairList.add(pair3); |
| 1990 | } |
| 1991 | ("," "decor" decorVar = Variable() ":=" decorExpr = Expression() |
| 1992 | { |
| 1993 | newScope.addNewVarSymbolToScope(decorVar.getVar()); |
| 1994 | GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr); |
| 1995 | decorPairList.add(pair4); |
| 1996 | } |
| 1997 | )* |
| 1998 | )? |
| 1999 | "with" withVar = VariableRef() |
| 2000 | { |
| 2001 | if(withVar.getIsNewVar()==true) |
| 2002 | throw new ParseException("can't find variable " + withVar.getVar()); |
| 2003 | withVarList.add(withVar); |
| 2004 | newScope.addNewVarSymbolToScope(withVar.getVar()); |
| 2005 | } |
| 2006 | ("," withVar = VariableRef() |
| 2007 | { |
| 2008 | if(withVar.getIsNewVar()==true) |
| 2009 | throw new ParseException("can't find variable " + withVar.getVar()); |
| 2010 | withVarList.add(withVar); |
| 2011 | newScope.addNewVarSymbolToScope(withVar.getVar()); |
| 2012 | })* |
| 2013 | { |
| 2014 | gbc.setGbyPairList(vePairList); |
| 2015 | gbc.setDecorPairList(decorPairList); |
| 2016 | gbc.setWithVarList(withVarList); |
| 2017 | replaceCurrentScope(newScope); |
| 2018 | return gbc; |
| 2019 | } |
| 2020 | } |
| 2021 | |
| 2022 | |
| 2023 | LimitClause LimitClause() throws ParseException: |
| 2024 | { |
| 2025 | LimitClause lc = new LimitClause(); |
| 2026 | Expression expr; |
| 2027 | pushForbiddenScope(getCurrentScope()); |
| 2028 | } |
| 2029 | { |
| 2030 | "limit" expr = Expression() { lc.setLimitExpr(expr); } |
| 2031 | ("offset" expr = Expression() { lc.setOffset(expr); })? |
| 2032 | |
| 2033 | { |
| 2034 | popForbiddenScope(); |
| 2035 | return lc; |
| 2036 | } |
| 2037 | } |
| 2038 | |
| 2039 | DistinctClause DistinctClause() throws ParseException: |
| 2040 | { |
| 2041 | List<Expression> exprs = new ArrayList<Expression>(); |
| 2042 | Expression expr; |
| 2043 | } |
| 2044 | { |
| 2045 | "distinct" "by" expr = Expression() |
| 2046 | { |
| 2047 | exprs.add(expr); |
| 2048 | } |
| 2049 | ("," expr = Expression() |
| 2050 | { |
| 2051 | exprs.add(expr); |
| 2052 | } |
| 2053 | )* |
| 2054 | { |
| 2055 | return new DistinctClause(exprs); |
| 2056 | } |
| 2057 | } |
| 2058 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2059 | QuantifiedExpression QuantifiedExpression()throws ParseException: |
| 2060 | { |
| 2061 | QuantifiedExpression qc = new QuantifiedExpression(); |
| 2062 | List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>(); |
| 2063 | Expression satisfiesExpr; |
| 2064 | VariableExpr var; |
| 2065 | Expression inExpr; |
| 2066 | QuantifiedPair pair; |
| 2067 | } |
| 2068 | { |
| 2069 | { |
| 2070 | createNewScope(); |
| 2071 | } |
| 2072 | |
| 2073 | ( ("some" { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); }) |
| 2074 | | ("every" { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); })) |
| 2075 | var = Variable() "in" inExpr = Expression() |
| 2076 | { |
| 2077 | pair = new QuantifiedPair(var, inExpr); |
| 2078 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 2079 | quantifiedList.add(pair); |
| 2080 | } |
| 2081 | ( |
| 2082 | "," var = Variable() "in" inExpr = Expression() |
| 2083 | { |
| 2084 | pair = new QuantifiedPair(var, inExpr); |
| 2085 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 2086 | quantifiedList.add(pair); |
| 2087 | } |
| 2088 | )* |
| 2089 | "satisfies" satisfiesExpr = Expression() |
| 2090 | { |
| 2091 | qc.setSatisfiesExpr(satisfiesExpr); |
| 2092 | qc.setQuantifiedList(quantifiedList); |
| 2093 | removeCurrentScope(); |
| 2094 | return qc; |
| 2095 | } |
| 2096 | } |
| 2097 | |
| 2098 | TOKEN_MGR_DECLS: |
| 2099 | { |
| 2100 | public int commentDepth = 0; |
| 2101 | } |
| 2102 | |
| 2103 | <DEFAULT> |
| 2104 | TOKEN : |
| 2105 | { |
| 2106 | <CARET : "^" > |
| 2107 | } |
| 2108 | |
| 2109 | <DEFAULT> |
| 2110 | TOKEN : |
| 2111 | { |
| 2112 | <DATASET : "dataset" > |
| 2113 | } |
| 2114 | |
| 2115 | <DEFAULT> |
| 2116 | TOKEN : |
| 2117 | { |
| 2118 | <LEFTPAREN : "(" > |
| 2119 | } |
| 2120 | |
| 2121 | <DEFAULT> |
| 2122 | TOKEN : |
| 2123 | { |
| 2124 | <RIGHTPAREN : ")" > |
| 2125 | } |
| 2126 | |
| 2127 | |
| 2128 | <DEFAULT> |
| 2129 | TOKEN : |
| 2130 | { |
| 2131 | <INTEGER_LITERAL : (<DIGIT>)+ > |
| 2132 | } |
| 2133 | |
| 2134 | |
| 2135 | <DEFAULT> |
| 2136 | TOKEN : |
| 2137 | { |
| 2138 | <NULL : "null"> |
| 2139 | } |
| 2140 | |
| 2141 | <DEFAULT> |
| 2142 | TOKEN : |
| 2143 | { |
| 2144 | <TRUE : "true"> |
| 2145 | } |
| 2146 | |
| 2147 | <DEFAULT> |
| 2148 | TOKEN : |
| 2149 | { |
| 2150 | <FALSE : "false"> |
| 2151 | } |
| 2152 | |
| 2153 | <DEFAULT> |
| 2154 | TOKEN : |
| 2155 | { |
| 2156 | <#DIGIT : ["0" - "9"]> |
| 2157 | } |
| 2158 | |
| 2159 | |
| 2160 | TOKEN: |
| 2161 | { |
| 2162 | < DOUBLE_LITERAL: <INTEGER> |
| 2163 | | <INTEGER> ( "." <INTEGER> )? |
| 2164 | | "." <INTEGER> |
| 2165 | > |
| 2166 | | |
| 2167 | < FLOAT_LITERAL: <INTEGER> ( "f" | "F" ) |
| 2168 | | <INTEGER> ( "." <INTEGER> ( "f" | "F" ) )? |
| 2169 | | "." <INTEGER> ( "f" | "F" ) |
| 2170 | > |
| 2171 | | |
| 2172 | <INTEGER : (<DIGIT>)+ > |
| 2173 | } |
| 2174 | |
| 2175 | <DEFAULT> |
| 2176 | TOKEN : |
| 2177 | { |
| 2178 | <#LETTER : ["A" - "Z", "a" - "z"]> |
| 2179 | } |
| 2180 | |
| 2181 | <DEFAULT> |
| 2182 | TOKEN : |
| 2183 | { |
| 2184 | <SPECIALCHARS : ["$", "_", "-"] > |
| 2185 | } |
| 2186 | |
| 2187 | <DEFAULT> |
| 2188 | TOKEN : |
| 2189 | { |
| 2190 | <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")> |
| 2191 | | |
| 2192 | < #EscapeQuot: "\\\"" > |
| 2193 | | |
| 2194 | < #EscapeApos: "\\\'" > |
| 2195 | } |
| 2196 | |
| 2197 | <DEFAULT> |
| 2198 | TOKEN : |
| 2199 | { |
| 2200 | <IDENTIFIER : (<LETTER>)+ (<LETTER> | <DIGIT> | <SPECIALCHARS>)*> |
| 2201 | } |
| 2202 | |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 2203 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 2204 | <DEFAULT> |
| 2205 | TOKEN : |
| 2206 | { |
| 2207 | <VARIABLE : "$" <IDENTIFIER> > |
| 2208 | } |
| 2209 | |
| 2210 | SKIP: |
| 2211 | { |
| 2212 | " " |
| 2213 | | "\t" |
| 2214 | | "\r" |
| 2215 | | "\n" |
| 2216 | } |
| 2217 | |
| 2218 | SKIP: |
| 2219 | { |
| 2220 | <"//" (~["\n"])* "\n"> |
| 2221 | } |
| 2222 | |
| 2223 | SKIP: |
| 2224 | { |
| 2225 | <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?> |
| 2226 | } |
| 2227 | |
| 2228 | |
| 2229 | SKIP: |
| 2230 | { |
| 2231 | <"/*"> {commentDepth=1;}: INSIDE_COMMENT |
| 2232 | } |
| 2233 | |
| 2234 | <INSIDE_COMMENT> |
| 2235 | SPECIAL_TOKEN: |
| 2236 | { |
| 2237 | <"+"(" ")*(~["*"])*> |
| 2238 | } |
| 2239 | |
| 2240 | <INSIDE_COMMENT> |
| 2241 | SKIP: |
| 2242 | { |
| 2243 | <"/*"> {commentDepth++;} |
| 2244 | } |
| 2245 | |
| 2246 | <INSIDE_COMMENT> |
| 2247 | SKIP: |
| 2248 | { |
| 2249 | <"*/"> {commentDepth--; if (commentDepth == 0) SwitchTo(DEFAULT);} |
| 2250 | | <~[]> |
| 2251 | } |