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