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