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