vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1 | options { |
| 2 | |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 3 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 4 | STATIC = false; |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 5 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 6 | } |
| 7 | |
| 8 | |
| 9 | PARSER_BEGIN(AQLPlusParser) |
| 10 | |
Ian Maxon | f18bba2 | 2015-08-21 12:35:14 -0700 | [diff] [blame] | 11 | package org.apache.asterix.aqlplus.parser; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 12 | |
| 13 | import java.io.*; |
| 14 | import java.util.List; |
| 15 | import java.util.ArrayList; |
| 16 | import java.util.Stack; |
| 17 | import java.util.Map; |
| 18 | import java.util.HashMap; |
| 19 | |
Ian Maxon | f18bba2 | 2015-08-21 12:35:14 -0700 | [diff] [blame] | 20 | import org.apache.asterix.aql.literal.FloatLiteral; |
| 21 | import org.apache.asterix.aql.literal.DoubleLiteral; |
| 22 | import org.apache.asterix.aql.literal.FalseLiteral; |
| 23 | import org.apache.asterix.aql.base.Literal; |
| 24 | import org.apache.asterix.aql.literal.IntegerLiteral; |
| 25 | import org.apache.asterix.aql.literal.LongIntegerLiteral; |
| 26 | import org.apache.asterix.aql.literal.NullLiteral; |
| 27 | import org.apache.asterix.aql.literal.StringLiteral; |
| 28 | import org.apache.asterix.aql.literal.TrueLiteral; |
| 29 | import org.apache.asterix.aql.parser.ScopeChecker; |
| 30 | import org.apache.asterix.aql.base.*; |
| 31 | import org.apache.asterix.aql.expression.*; |
| 32 | import org.apache.asterix.aql.expression.visitor.AQLPrintVisitor; |
| 33 | import org.apache.asterix.aql.expression.UnaryExpr.Sign; |
| 34 | import org.apache.asterix.aql.expression.TypeExpression.TypeExprKind; |
| 35 | import org.apache.asterix.aql.base.Statement.Kind; |
| 36 | import org.apache.asterix.aql.context.Scope; |
| 37 | import org.apache.asterix.aql.context.RootScopeFactory; |
| 38 | import org.apache.asterix.common.exceptions.AsterixException; |
| 39 | import org.apache.asterix.om.functions.AsterixFunction; |
| 40 | import org.apache.asterix.common.functions.FunctionSignature; |
| 41 | import org.apache.asterix.metadata.bootstrap.MetadataConstants; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 42 | |
Ian Maxon | f18bba2 | 2015-08-21 12:35:14 -0700 | [diff] [blame] | 43 | import org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation; |
| 44 | import org.apache.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation; |
| 45 | import org.apache.hyracks.algebricks.common.utils.Pair; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 46 | |
| 47 | |
ramangrover29 | a13f242 | 2012-03-15 23:01:27 +0000 | [diff] [blame] | 48 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 49 | public class AQLPlusParser extends ScopeChecker { |
| 50 | |
| 51 | /* |
| 52 | private void printHints(Token t) { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 53 | //System.err.println("token="+t.image+"\t special="+t.specialToken); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 54 | if (t.specialToken == null) return; |
| 55 | Token tmp_t = t.specialToken; |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 56 | while (tmp_t.specialToken != null) tmp_t = tmp_t.specialToken; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 57 | while (tmp_t != null) { |
| 58 | System.out.println(tmp_t.image); |
| 59 | tmp_t = tmp_t.next; |
| 60 | } |
| 61 | } |
| 62 | */ |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 63 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 64 | private static final String HASH_GROUP_BY_HINT = "hash"; |
| 65 | private static final String BROADCAST_JOIN_HINT = "bcast"; |
| 66 | private static final String INMEMORY_HINT = "inmem"; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 67 | private static final String INDEXED_NESTED_LOOP_JOIN_HINT = "indexnl"; |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 68 | |
| 69 | |
| 70 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 71 | private static String getHint(Token t) { |
| 72 | if (t.specialToken == null) { |
| 73 | return null; |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 74 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 75 | String s = t.specialToken.image; |
| 76 | int n = s.length(); |
| 77 | if (n < 2) { |
| 78 | return null; |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 79 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 80 | return s.substring(1).trim(); |
| 81 | } |
| 82 | |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 83 | public static void main(String args[]) throws ParseException, TokenMgrError, IOException, FileNotFoundException, AsterixException { |
| 84 | File file = new File(args[0]); |
| 85 | Reader fis = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); |
| 86 | AQLPlusParser parser = new AQLPlusParser(fis); |
| 87 | List<Statement> st = parser.Statement(); |
| 88 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 89 | |
| 90 | public void initScope() { |
| 91 | scopeStack.push(RootScopeFactory.createRootScope(this)); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | PARSER_END(AQLPlusParser) |
| 96 | |
| 97 | |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 98 | List<Statement> Statement() throws ParseException: |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 99 | { |
| 100 | Query query = null; |
| 101 | // scopeStack.push(RootScopeFactory.createRootScope(this)); |
| 102 | initScope(); |
| 103 | List<Statement> decls = new ArrayList<Statement>(); |
| 104 | } |
| 105 | { |
| 106 | ( |
| 107 | ( |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 108 | ( |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 109 | "use" |
| 110 | { |
| 111 | decls.add(DataverseDeclaration()); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 112 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 113 | | "declare" |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 114 | ( "function" { |
| 115 | decls.add(FunctionDeclaration()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 116 | } |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 117 | | "type" { |
| 118 | decls.add(TypeDeclaration()); |
| 119 | } |
| 120 | ) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 121 | | "load" { |
| 122 | decls.add(LoadStatement()); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 123 | } |
| 124 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 125 | | "write" { |
| 126 | decls.add(WriteStatement()); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 127 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 128 | | "set" { |
| 129 | decls.add(SetStatement()); |
| 130 | } |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 131 | | |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 132 | { |
| 133 | decls.add(Query()) ; |
| 134 | } ";" |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 135 | |
| 136 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 137 | )* |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 138 | ) |
| 139 | |
| 140 | <EOF> |
| 141 | ) |
| 142 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 143 | |
| 144 | return decls; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
| 148 | Statement SetStatement() throws ParseException: |
| 149 | { |
| 150 | String pn = null; |
| 151 | Statement stmt = null; |
| 152 | } |
| 153 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 154 | <IDENTIFIER> { pn = token.image; } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 155 | <STRING_LITERAL> |
| 156 | { String pv = removeQuotesAndEscapes(token.image); } |
| 157 | ";" |
| 158 | { |
| 159 | return new SetStatement(pn, pv); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | Statement WriteStatement() throws ParseException: |
| 164 | { |
| 165 | Identifier nodeName = null; |
| 166 | String fileName = null; |
| 167 | Identifier datasetName = null; |
| 168 | Statement stmt = null; |
| 169 | Query query; |
| 170 | } |
| 171 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 172 | ( "output" "to" |
| 173 | <IDENTIFIER> { nodeName = new Identifier(token.image); } |
| 174 | ":" <STRING_LITERAL> { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 175 | fileName = removeQuotesAndEscapes(token.image); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 176 | stmt = new WriteStatement(nodeName, fileName, null); |
Till Westmann | 35a0f70 | 2013-07-01 14:06:34 -0700 | [diff] [blame] | 177 | } |
| 178 | ) ";" |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 179 | { |
| 180 | return stmt; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | DataverseDecl DataverseDeclaration() throws ParseException: |
| 185 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 186 | Identifier dvName = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 187 | } |
| 188 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 189 | "dataverse" <IDENTIFIER> { defaultDataverse = token.image;} |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 190 | ";" |
| 191 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 192 | return new DataverseDecl(new Identifier(defaultDataverse)); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | |
zheilbron | 28e026f | 2013-11-20 10:15:15 -0800 | [diff] [blame] | 196 | LoadStatement LoadStatement() throws ParseException: |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 197 | { |
| 198 | Identifier datasetName = null; |
| 199 | boolean alreadySorted = false; |
| 200 | String adapter; |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 201 | Map<String,String> properties = new HashMap<String,String>(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 202 | String name; |
| 203 | String value; |
| 204 | } |
| 205 | { |
| 206 | <DATASET> <IDENTIFIER> { datasetName = new Identifier(token.image); } |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 207 | |
| 208 | "using" |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 209 | ( |
| 210 | <STRING_LITERAL> |
| 211 | { |
| 212 | adapter = removeQuotesAndEscapes(token.image); |
| 213 | } |
| 214 | <LEFTPAREN> |
| 215 | ( |
| 216 | ( |
| 217 | <LEFTPAREN> |
| 218 | ( |
| 219 | <STRING_LITERAL> |
| 220 | { |
| 221 | name = removeQuotesAndEscapes(token.image); |
| 222 | } |
| 223 | "=" <STRING_LITERAL> |
| 224 | { |
| 225 | value = removeQuotesAndEscapes(token.image); |
| 226 | } |
| 227 | ) |
| 228 | <RIGHTPAREN> |
| 229 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 230 | properties.put(name, value); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 231 | } |
| 232 | ) |
| 233 | ( |
| 234 | "," <LEFTPAREN> |
| 235 | ( |
| 236 | <STRING_LITERAL> |
| 237 | { |
| 238 | name = removeQuotesAndEscapes(token.image); |
| 239 | } |
| 240 | "=" <STRING_LITERAL> |
| 241 | { |
| 242 | value = removeQuotesAndEscapes(token.image); |
| 243 | } |
| 244 | ) |
| 245 | <RIGHTPAREN> |
| 246 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 247 | properties.put(name, value); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 248 | } |
| 249 | )* |
| 250 | )? |
| 251 | <RIGHTPAREN> |
| 252 | ) |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 253 | |
| 254 | ("pre-sorted" |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 255 | { alreadySorted = true; } |
| 256 | )? |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 257 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 258 | ";" |
| 259 | { |
zheilbron | 28e026f | 2013-11-20 10:15:15 -0800 | [diff] [blame] | 260 | return new LoadStatement(null, datasetName, adapter, properties, alreadySorted); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 261 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | TypeDecl TypeDeclaration() throws ParseException: |
| 265 | { |
| 266 | Identifier ident; |
| 267 | TypeExpression typeExpr; |
| 268 | } |
| 269 | { |
| 270 | <IDENTIFIER> |
| 271 | { |
| 272 | ident = new Identifier(token.image.toString()); |
| 273 | } |
| 274 | "as" |
| 275 | ( typeExpr = TypeExpr() ) |
| 276 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 277 | return new TypeDecl(null, ident, typeExpr); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
| 281 | TypeExpression TypeExpr() throws ParseException: |
| 282 | { |
| 283 | TypeExpression typeExpr = null; |
| 284 | } |
| 285 | { |
| 286 | ( |
| 287 | typeExpr = RecordTypeDef() |
| 288 | | typeExpr = TypeReference() |
| 289 | | typeExpr = OrderedListTypeDef() |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 290 | | typeExpr = UnorderedListTypeDef() |
| 291 | ) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 292 | { |
| 293 | return typeExpr; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | RecordTypeDefinition RecordTypeDef() throws ParseException: |
| 298 | { |
| 299 | RecordTypeDefinition recType = new RecordTypeDefinition(); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 300 | RecordTypeDefinition.RecordKind recordKind = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 301 | } |
| 302 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 303 | ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 304 | | "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )? |
| 305 | "{" |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 306 | ( |
| 307 | RecordField(recType) |
| 308 | ( "," RecordField(recType) )* |
| 309 | )? |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 310 | "}" |
| 311 | { |
| 312 | if (recordKind == null) { |
| 313 | recordKind = RecordTypeDefinition.RecordKind.OPEN; |
| 314 | } |
| 315 | recType.setRecordKind(recordKind); |
| 316 | return recType; |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 317 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | void RecordField(RecordTypeDefinition recType) throws ParseException: |
| 321 | { |
| 322 | String fieldName; |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 323 | TypeExpression type = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 324 | boolean nullable = false; |
| 325 | } |
| 326 | { |
| 327 | <IDENTIFIER> |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 328 | { |
| 329 | Token t = getToken(0); |
| 330 | fieldName = t.toString(); |
| 331 | } |
| 332 | ":" |
| 333 | ( type = TypeExpr() ) |
| 334 | ("?" { nullable = true; } )? |
| 335 | { |
| 336 | |
| 337 | recType.addField(fieldName, type, nullable); |
| 338 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | TypeReferenceExpression TypeReference() throws ParseException: |
| 342 | {} |
| 343 | { |
| 344 | <IDENTIFIER> |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 345 | { |
| 346 | Token t = getToken(0); |
| 347 | Identifier id; |
| 348 | if (t.toString().equalsIgnoreCase("int")) { |
| 349 | id = new Identifier("int64"); |
| 350 | } else { |
| 351 | id = new Identifier(t.toString()); |
| 352 | } |
| 353 | return new TypeReferenceExpression(id); |
| 354 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | OrderedListTypeDefinition OrderedListTypeDef() throws ParseException: |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 358 | { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 359 | TypeExpression type = null; |
| 360 | } |
| 361 | { |
| 362 | "[" |
| 363 | ( type = TypeExpr() ) |
| 364 | "]" |
| 365 | { |
| 366 | return new OrderedListTypeDefinition(type); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | |
| 371 | UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException: |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 372 | { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 373 | TypeExpression type = null; |
| 374 | } |
| 375 | { |
| 376 | "<" |
| 377 | ( type = TypeExpr() ) |
| 378 | ">" |
| 379 | { |
| 380 | return new UnorderedListTypeDefinition(type); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | |
| 385 | FunctionDecl FunctionDeclaration() throws ParseException: |
| 386 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 387 | FunctionDecl funcDecl; |
| 388 | FunctionSignature signature; |
ramangrover29 | a13f242 | 2012-03-15 23:01:27 +0000 | [diff] [blame] | 389 | String functionName; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 390 | int arity = 0; |
| 391 | List<VarIdentifier> paramList = new ArrayList<VarIdentifier>(); |
| 392 | Expression funcBody; |
| 393 | VarIdentifier var = null; |
| 394 | createNewScope(); |
| 395 | } |
| 396 | { |
| 397 | |
| 398 | <IDENTIFIER> |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 399 | { |
| 400 | Token t = getToken(0); |
| 401 | functionName = t.toString(); |
| 402 | if (functionName.equalsIgnoreCase("int")) { |
| 403 | functionName = "int64"; |
| 404 | } |
| 405 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 406 | <LEFTPAREN> (<VARIABLE> |
| 407 | { |
| 408 | var = new VarIdentifier(); |
| 409 | var.setValue(getToken(0).toString()); |
| 410 | paramList.add(var); |
| 411 | getCurrentScope().addNewVarSymbolToScope(var); |
| 412 | arity++; |
| 413 | } |
| 414 | ("," <VARIABLE> |
| 415 | { |
| 416 | var = new VarIdentifier(); |
| 417 | var.setValue(getToken(0).toString()); |
| 418 | paramList.add(var); |
| 419 | getCurrentScope().addNewVarSymbolToScope(var); |
| 420 | arity++; |
| 421 | })*)? <RIGHTPAREN> "{" funcBody = Expression() "}" |
| 422 | |
| 423 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 424 | signature = new FunctionSignature(defaultDataverse, functionName, arity); |
| 425 | getCurrentScope().addFunctionDescriptor(signature, false); |
| 426 | funcDecl = new FunctionDecl(signature, paramList, funcBody); |
| 427 | return funcDecl; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | |
| 431 | Query Query()throws ParseException: |
| 432 | { |
| 433 | Query query = new Query(); |
| 434 | Expression expr; |
| 435 | } |
| 436 | { |
| 437 | expr = Expression() |
| 438 | |
| 439 | { |
| 440 | query.setBody(expr); |
| 441 | return query; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | |
| 446 | |
| 447 | Expression Expression(): |
| 448 | { |
| 449 | Expression expr = null; |
| 450 | Expression exprP = null; |
| 451 | } |
| 452 | { |
| 453 | ( |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 454 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 455 | //OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression |
| 456 | expr = OperatorExpr() |
| 457 | | expr = IfThenElse() |
| 458 | | expr = FLWOGR() |
| 459 | | expr = QuantifiedExpression() |
| 460 | |
| 461 | |
| 462 | ) |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 463 | { |
| 464 | return (exprP==null) ? expr : exprP; |
| 465 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | |
| 469 | |
| 470 | Expression OperatorExpr()throws ParseException: |
| 471 | { |
| 472 | OperatorExpr op = null; |
| 473 | Expression operand = null; |
| 474 | } |
| 475 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 476 | operand = AndExpr() |
| 477 | ( |
| 478 | |
| 479 | "or" |
| 480 | { |
| 481 | if (op == null) { |
| 482 | op = new OperatorExpr(); |
| 483 | op.addOperand(operand); |
| 484 | op.setCurrentop(true); |
| 485 | } |
| 486 | Token t = getToken(0); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 487 | op.addOperator(t.toString()); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 488 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 489 | |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 490 | operand = AndExpr() |
| 491 | { |
| 492 | op.addOperand(operand); |
| 493 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 494 | |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 495 | )* |
| 496 | |
| 497 | { |
| 498 | return op==null? operand: op; |
| 499 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | Expression AndExpr()throws ParseException: |
| 503 | { |
| 504 | OperatorExpr op = null; |
| 505 | Expression operand = null; |
| 506 | } |
| 507 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 508 | operand = RelExpr() |
| 509 | ( |
| 510 | |
| 511 | "and" |
| 512 | { |
| 513 | if (op == null) { |
| 514 | op = new OperatorExpr(); |
| 515 | op.addOperand(operand); |
| 516 | op.setCurrentop(true); |
| 517 | } |
| 518 | Token t = getToken(0); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 519 | op.addOperator(t.toString()); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 520 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 521 | |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 522 | operand = RelExpr() |
| 523 | { |
| 524 | op.addOperand(operand); |
| 525 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 526 | |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 527 | )* |
| 528 | |
| 529 | { |
| 530 | return op==null? operand: op; |
| 531 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | |
| 535 | |
| 536 | Expression RelExpr()throws ParseException: |
| 537 | { |
| 538 | OperatorExpr op = null; |
| 539 | Expression operand = null; |
| 540 | boolean broadcast = false; |
| 541 | } |
| 542 | { |
| 543 | operand = AddExpr() |
| 544 | { |
| 545 | if (operand instanceof VariableExpr) { |
| 546 | String hint = getHint(token); |
| 547 | if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 548 | broadcast = true; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 549 | } |
| 550 | } |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 551 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 552 | |
| 553 | ( |
| 554 | LOOKAHEAD(2)( "<" | ">" | "<=" | ">=" | "=" | "!=" |"~=") |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 555 | { |
| 556 | if (op == null) { |
| 557 | op = new OperatorExpr(); |
| 558 | op.addOperand(operand, broadcast); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 559 | op.setCurrentop(true); |
| 560 | broadcast = false; |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 561 | } |
| 562 | Token t = getToken(0); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 563 | op.addOperator(t.toString()); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | operand = AddExpr() |
| 567 | { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 568 | broadcast = false; |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 569 | if (operand instanceof VariableExpr) { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 570 | String hint = getHint(token); |
| 571 | if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) { |
| 572 | broadcast = true; |
| 573 | } |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 574 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 575 | op.addOperand(operand, broadcast); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 576 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 577 | )? |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 578 | |
| 579 | { |
| 580 | return op==null? operand: op; |
| 581 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | Expression AddExpr()throws ParseException: |
| 585 | { |
| 586 | OperatorExpr op = null; |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 587 | Expression operand = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 588 | } |
| 589 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 590 | operand = MultExpr() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 591 | |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 592 | ( ("+" | "-") |
| 593 | { |
| 594 | if (op == null) { |
| 595 | op = new OperatorExpr(); |
| 596 | op.addOperand(operand); |
| 597 | op.setCurrentop(true); |
| 598 | } |
| 599 | Token t = getToken(0); |
| 600 | ((OperatorExpr)op).addOperator(t.toString()); |
| 601 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 602 | |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 603 | operand = MultExpr() |
| 604 | { |
| 605 | op.addOperand(operand); |
| 606 | } |
| 607 | )* |
| 608 | |
| 609 | { |
| 610 | return op==null? operand: op; |
| 611 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | Expression MultExpr()throws ParseException: |
| 615 | { |
| 616 | OperatorExpr op = null; |
| 617 | Expression operand = null; |
| 618 | } |
| 619 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 620 | operand = UnionExpr() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 621 | |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 622 | (( "*" | "/" | "%" | <CARET> | "idiv") |
| 623 | { |
| 624 | if (op == null) { |
| 625 | op = new OperatorExpr(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 626 | op.addOperand(operand); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 627 | op.setCurrentop(true); |
| 628 | } |
| 629 | Token t = getToken(0); |
| 630 | op.addOperator(t.toString()); |
| 631 | } |
| 632 | operand = UnionExpr() |
| 633 | { |
| 634 | op.addOperand(operand); |
| 635 | } |
| 636 | )* |
| 637 | |
| 638 | { |
| 639 | return op==null?operand:op; |
| 640 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | Expression UnionExpr() throws ParseException: |
| 644 | { |
| 645 | UnionExpr union = null; |
| 646 | Expression operand1 = null; |
| 647 | Expression operand2 = null; |
| 648 | } |
| 649 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 650 | operand1 = UnaryExpr() |
| 651 | ("union" |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 652 | (operand2 = UnaryExpr()) { |
| 653 | if (union == null) { |
| 654 | union = new UnionExpr(); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 655 | union.addExpr(operand1); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 656 | } |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 657 | union.addExpr(operand2); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 658 | } )* |
| 659 | { |
| 660 | return (union == null)? operand1: union; |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | Expression UnaryExpr() throws ParseException: |
| 665 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 666 | Expression uexpr = null; |
| 667 | Expression expr = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 668 | } |
| 669 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 670 | (( "+"|"-") |
| 671 | { |
| 672 | uexpr = new UnaryExpr(); |
| 673 | Token t = getToken(0); |
| 674 | if("+".equals(t.toString())) |
| 675 | ((UnaryExpr)uexpr).setSign(Sign.POSITIVE); |
| 676 | else if("-".equals(t.toString())) |
| 677 | ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE); |
| 678 | else |
| 679 | throw new ParseException(); |
| 680 | } |
| 681 | )? |
| 682 | |
| 683 | expr = ValueExpr() |
| 684 | { |
| 685 | if(uexpr!=null){ |
| 686 | ((UnaryExpr)uexpr).setExpr(expr); |
| 687 | return uexpr; |
| 688 | } |
| 689 | else{ |
| 690 | return expr; |
| 691 | } |
| 692 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | Expression ValueExpr() throws ParseException: |
| 696 | { |
| 697 | Expression expr; |
| 698 | } |
| 699 | { |
| 700 | expr = FieldOrIndexAccessor() |
| 701 | { |
| 702 | return expr; |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | |
| 707 | Expression FieldOrIndexAccessor()throws ParseException: |
| 708 | { |
| 709 | Expression expr = null; |
| 710 | Identifier ident = null; |
| 711 | AbstractAccessor fa = null; |
icetindil | a611ac7 | 2014-05-16 10:10:11 -0700 | [diff] [blame] | 712 | Expression indexExpr = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 713 | |
| 714 | } |
| 715 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 716 | ( expr = PrimaryExpr() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 717 | |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 718 | ) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 719 | |
| 720 | |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 721 | ( |
| 722 | ( |
| 723 | ident = Field() |
| 724 | { |
| 725 | if(fa == null) |
| 726 | fa = new FieldAccessor(expr, ident); |
| 727 | else |
| 728 | fa = new FieldAccessor(fa, ident); |
| 729 | } |
| 730 | ) |
| 731 | | ( |
| 732 | indexExpr = Index() |
| 733 | { |
| 734 | if(fa == null) |
| 735 | fa = new IndexAccessor(expr, indexExpr); |
| 736 | else |
| 737 | fa = new IndexAccessor(fa, indexExpr); |
| 738 | } |
| 739 | ) |
| 740 | )* |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 741 | |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 742 | |
| 743 | { |
| 744 | return fa==null?expr:fa; |
| 745 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | Identifier Field() throws ParseException: |
| 749 | { |
| 750 | Identifier ident = null; |
| 751 | |
| 752 | } |
| 753 | { |
| 754 | "." < IDENTIFIER > |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 755 | { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 756 | |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 757 | ident = new Identifier(); |
| 758 | ident.setValue(getToken(0).toString()); |
| 759 | |
| 760 | return ident; |
| 761 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 762 | } |
| 763 | |
icetindil | a611ac7 | 2014-05-16 10:10:11 -0700 | [diff] [blame] | 764 | Expression Index() throws ParseException: |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 765 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 766 | Expression expr = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 767 | } |
| 768 | { |
| 769 | "[" ( expr = Expression() |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 770 | { |
| 771 | if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION) |
| 772 | { |
| 773 | Literal lit = ((LiteralExpr)expr).getValue(); |
| 774 | if(lit.getLiteralType() != Literal.Type.INTEGER && |
| 775 | lit.getLiteralType() != Literal.Type.LONG) { |
| 776 | throw new ParseException("Index should be an INTEGER"); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 777 | } |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 778 | } |
| 779 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 780 | |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 781 | | "?" // ANY |
| 782 | |
| 783 | ) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 784 | |
| 785 | "]" |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 786 | { |
| 787 | return expr; |
| 788 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | |
| 792 | Expression PrimaryExpr()throws ParseException: |
| 793 | { |
| 794 | Expression expr = null; |
| 795 | } |
| 796 | { |
ilovesoup | c9fef1d | 2012-07-08 19:30:42 +0000 | [diff] [blame] | 797 | //Literal | VariableRef | ListConstructor | RecordConstructor | FunctionCallExpr | ParenthesizedExpression |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 798 | ( |
| 799 | expr =Literal() |
| 800 | | expr = FunctionCallExpr() |
| 801 | | expr =VariableRef() |
| 802 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 803 | { |
| 804 | if(((VariableExpr)expr).getIsNewVar() == true) |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 805 | throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 806 | } |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 807 | | expr = ListConstructor() |
| 808 | | expr = RecordConstructor() |
| 809 | | expr = ParenthesizedExpression() |
| 810 | | expr = MetaVariableRef() |
| 811 | ) |
| 812 | { |
| 813 | return expr; |
| 814 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | Expression Literal() throws ParseException: |
| 818 | { |
| 819 | |
| 820 | LiteralExpr lit = new LiteralExpr(); |
| 821 | Token t; |
| 822 | } |
| 823 | { |
| 824 | ( |
| 825 | <STRING_LITERAL> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 826 | { |
| 827 | t= getToken(0); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 828 | lit.setValue( new StringLiteral(removeQuotesAndEscapes(t.image))); |
| 829 | } |
| 830 | |
| 831 | | <INTEGER_LITERAL> |
| 832 | { |
| 833 | t= getToken(0); |
| 834 | try { |
| 835 | lit.setValue(new IntegerLiteral(new Integer(t.image))); |
| 836 | } catch(NumberFormatException ex) { |
| 837 | lit.setValue(new LongIntegerLiteral(new Long(t.image))); |
| 838 | } |
| 839 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 840 | | < FLOAT_LITERAL > |
| 841 | { |
| 842 | t= getToken(0); |
| 843 | lit.setValue(new FloatLiteral(new Float(t.image))); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 844 | } |
| 845 | | < DOUBLE_LITERAL > |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 846 | { |
| 847 | t= getToken(0); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 848 | lit.setValue(new DoubleLiteral(new Double(t.image))); |
| 849 | } |
| 850 | | <NULL> |
| 851 | { |
| 852 | t= getToken(0); |
| 853 | lit.setValue(NullLiteral.INSTANCE); |
| 854 | } |
| 855 | | <TRUE> |
| 856 | { |
| 857 | t= getToken(0); |
| 858 | lit.setValue(TrueLiteral.INSTANCE); |
| 859 | } |
| 860 | | <FALSE> |
| 861 | { |
| 862 | t= getToken(0); |
| 863 | lit.setValue(FalseLiteral.INSTANCE); |
| 864 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 865 | ) |
| 866 | { |
| 867 | return lit; |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | |
| 872 | VariableExpr VariableRef() throws ParseException: |
| 873 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 874 | VariableExpr varExp = new VariableExpr(); |
| 875 | VarIdentifier var = new VarIdentifier(); |
| 876 | Token t; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 877 | } |
| 878 | { |
| 879 | <VARIABLE> |
| 880 | { |
| 881 | t = getToken(0);//get current token |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 882 | String varName = t.toString(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 883 | Identifier ident = lookupSymbol(varName); |
| 884 | if (isInForbiddenScopes(varName)) { |
| 885 | 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."); |
| 886 | } |
| 887 | if(ident != null) { // exist such ident |
| 888 | varExp.setIsNewVar(false); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 889 | varExp.setVar((VarIdentifier)ident); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 890 | } else { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 891 | varExp.setVar(var); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 892 | } |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 893 | var.setValue(t.toString()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 894 | return varExp; |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | |
| 899 | VariableExpr Variable() throws ParseException: |
| 900 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 901 | VariableExpr varExp = new VariableExpr(); |
| 902 | VarIdentifier var = new VarIdentifier(); |
| 903 | Token t; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 904 | } |
| 905 | { |
| 906 | <VARIABLE> |
| 907 | { |
| 908 | t = getToken(0);//get current token |
| 909 | Identifier ident = lookupSymbol(t.toString()); |
| 910 | if(ident != null) { // exist such ident |
| 911 | varExp.setIsNewVar(false); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 912 | } |
| 913 | varExp.setVar(var); |
| 914 | var.setValue(t.toString()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 915 | return varExp; |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | MetaVariableExpr MetaVariableRef() throws ParseException: |
| 920 | { |
| 921 | MetaVariableExpr metaVarExp = new MetaVariableExpr(); |
| 922 | VarIdentifier var = new VarIdentifier(); |
| 923 | Token t; |
| 924 | } |
| 925 | { |
| 926 | <METAVARIABLE> |
| 927 | { |
| 928 | t = getToken(0);//get current token |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 929 | metaVarExp.setVar(var); |
| 930 | var.setValue(t.toString()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 931 | return metaVarExp; |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | Expression ListConstructor() throws ParseException: |
| 936 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 937 | Expression expr = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 938 | } |
| 939 | { |
| 940 | ( |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 941 | expr = OrderedListConstructor() | expr = UnorderedListConstructor() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 942 | ) |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 943 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 944 | { |
| 945 | return expr; |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | |
| 950 | ListConstructor OrderedListConstructor() throws ParseException: |
| 951 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 952 | ListConstructor expr = new ListConstructor(); |
| 953 | Expression tmp = null; |
| 954 | List<Expression> exprList = new ArrayList<Expression>(); |
| 955 | expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 956 | } |
| 957 | { |
| 958 | |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 959 | "[" |
| 960 | ( tmp = Expression() |
| 961 | { |
| 962 | exprList.add(tmp); |
| 963 | } |
| 964 | |
| 965 | ("," tmp = Expression() { exprList.add(tmp); })* |
| 966 | )? |
| 967 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 968 | "]" |
| 969 | |
| 970 | { |
| 971 | expr.setExprList(exprList); |
| 972 | return expr; |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 973 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | ListConstructor UnorderedListConstructor() throws ParseException: |
| 977 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 978 | ListConstructor expr = new ListConstructor(); |
| 979 | Expression tmp = null; |
| 980 | List<Expression> exprList = new ArrayList<Expression>(); |
| 981 | expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 982 | } |
| 983 | { |
| 984 | |
| 985 | "{{" ( tmp = Expression() |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 986 | { |
| 987 | exprList.add(tmp); |
| 988 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 989 | ("," tmp = Expression() { exprList.add(tmp); })*)? "}}" |
| 990 | { |
| 991 | expr.setExprList(exprList); |
| 992 | return expr; |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 993 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | RecordConstructor RecordConstructor() throws ParseException: |
| 997 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 998 | RecordConstructor expr = new RecordConstructor(); |
| 999 | FieldBinding tmp = null; |
| 1000 | List<FieldBinding> fbList = new ArrayList<FieldBinding>(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1001 | } |
| 1002 | { |
| 1003 | "{" (tmp = FieldBinding() |
| 1004 | { |
| 1005 | fbList.add(tmp); |
| 1006 | } |
| 1007 | ("," tmp = FieldBinding() { fbList.add(tmp); })*)? "}" |
| 1008 | { |
| 1009 | expr.setFbList(fbList); |
| 1010 | return expr; |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1011 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | FieldBinding FieldBinding() throws ParseException: |
| 1015 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1016 | FieldBinding fb = new FieldBinding(); |
| 1017 | Expression left, right; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1018 | } |
| 1019 | { |
| 1020 | left = Expression() ":" right = Expression() |
| 1021 | { |
| 1022 | fb.setLeftExpr(left); |
| 1023 | fb.setRightExpr(right); |
| 1024 | return fb; |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | Expression FunctionCallExpr() throws ParseException: |
| 1029 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1030 | CallExpr callExpr; |
| 1031 | List<Expression> argList = new ArrayList<Expression>(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1032 | Expression tmp; |
| 1033 | int arity = 0; |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1034 | String funcName; |
| 1035 | String dataverse; |
| 1036 | String hint=null; |
| 1037 | String id1=null; |
| 1038 | String id2=null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1039 | } |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1040 | { |
| 1041 | ( <IDENTIFIER> { dataverse = defaultDataverse; funcName = token.image;} |
| 1042 | ("." <IDENTIFIER> { dataverse = funcName; funcName = token.image;})? |
| 1043 | | |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1044 | <DATASET> {dataverse = MetadataConstants.METADATA_DATAVERSE_NAME; funcName = getToken(0).toString();} |
| 1045 | ) |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1046 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1047 | hint=getHint(token); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1048 | } |
| 1049 | <LEFTPAREN> (tmp = Expression() |
| 1050 | { |
| 1051 | argList.add(tmp); |
| 1052 | arity ++; |
| 1053 | } ("," tmp = Expression() { argList.add(tmp); arity++; })*)? <RIGHTPAREN> |
| 1054 | |
| 1055 | { |
RamanGrover29@gmail.com | 58cf330 | 2012-11-09 00:27:45 +0000 | [diff] [blame] | 1056 | FunctionSignature signature = lookupFunctionSignature(dataverse, funcName.toString(), arity); |
| 1057 | if(signature == null) |
| 1058 | { |
| 1059 | signature = new FunctionSignature(dataverse, funcName.toString(), arity); |
| 1060 | } |
| 1061 | callExpr = new CallExpr(signature,argList); |
| 1062 | if (hint != null && hint.startsWith(INDEXED_NESTED_LOOP_JOIN_HINT)) { |
| 1063 | callExpr.addHint(IndexedNLJoinExpressionAnnotation.INSTANCE); |
| 1064 | } |
| 1065 | return callExpr; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | |
| 1070 | Expression ParenthesizedExpression() throws ParseException: |
| 1071 | { |
| 1072 | Expression expr; |
| 1073 | } |
| 1074 | { |
| 1075 | <LEFTPAREN> expr = Expression() <RIGHTPAREN> |
| 1076 | { |
| 1077 | return expr; |
| 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | Expression IfThenElse() throws ParseException: |
| 1082 | { |
| 1083 | Expression condExpr; |
| 1084 | Expression thenExpr; |
| 1085 | Expression elseExpr; |
| 1086 | IfExpr ifExpr = new IfExpr(); |
| 1087 | } |
| 1088 | { |
| 1089 | "if" <LEFTPAREN> condExpr = Expression() <RIGHTPAREN> "then" thenExpr = Expression() "else" elseExpr = Expression() |
| 1090 | |
| 1091 | { |
| 1092 | ifExpr.setCondExpr(condExpr); |
| 1093 | ifExpr.setThenExpr(thenExpr); |
| 1094 | ifExpr.setElseExpr(elseExpr); |
| 1095 | return ifExpr; |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | Expression FLWOGR() throws ParseException: |
| 1100 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1101 | FLWOGRExpression flworg = new FLWOGRExpression(); |
| 1102 | List<Clause> clauseList = new ArrayList<Clause>(); |
| 1103 | Expression returnExpr; |
| 1104 | Clause tmp; |
| 1105 | createNewScope(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1106 | } |
| 1107 | { |
| 1108 | (tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);} | tmp = MetaVariableClause() {clauseList.add(tmp);}) |
| 1109 | (tmp = Clause() {clauseList.add(tmp);})* "return" returnExpr = Expression() |
| 1110 | |
| 1111 | { |
| 1112 | flworg.setClauseList(clauseList); |
| 1113 | flworg.setReturnExpr(returnExpr); |
| 1114 | removeCurrentScope(); |
| 1115 | return flworg; |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | List<Clause> Clauses() throws ParseException: |
| 1120 | { |
| 1121 | List<Clause> clauses = new ArrayList<Clause>(); |
| 1122 | Clause c = null; |
| 1123 | } |
| 1124 | { |
| 1125 | ( |
| 1126 | ( |
| 1127 | c = Clause() { |
| 1128 | clauses.add(c); |
| 1129 | } |
| 1130 | )* |
| 1131 | ) |
| 1132 | { |
| 1133 | return clauses; |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | Clause Clause() throws ParseException : |
| 1138 | { |
| 1139 | Clause clause; |
| 1140 | } |
| 1141 | { |
| 1142 | ( |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1143 | clause = ForClause() |
| 1144 | | clause = LetClause() |
| 1145 | | clause = WhereClause() |
| 1146 | | clause = OrderbyClause() |
| 1147 | | clause = GroupClause() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1148 | | clause = LimitClause() |
| 1149 | | clause = DistinctClause() |
| 1150 | | clause = MetaVariableClause() |
| 1151 | | clause = JoinClause() |
| 1152 | ) |
| 1153 | { |
| 1154 | return clause; |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | Clause MetaVariableClause() throws ParseException : |
| 1159 | { |
| 1160 | MetaVariableClause mc = new MetaVariableClause(); |
| 1161 | VarIdentifier var = new VarIdentifier(); |
| 1162 | Token t; |
| 1163 | } |
| 1164 | { |
| 1165 | <METAVARIABLECLAUSE> |
| 1166 | { |
| 1167 | t = getToken(0); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1168 | mc.setVar(var); |
| 1169 | var.setValue(t.toString()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1170 | return mc; |
| 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | Clause JoinClause() throws ParseException : |
| 1175 | { |
| 1176 | Expression whereExpr; |
| 1177 | List<Clause> leftClauses, rightClauses; |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1178 | JoinClause.JoinKind kind = JoinClause.JoinKind.INNER; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1179 | } |
| 1180 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1181 | ("join" | "loj" { kind = JoinClause.JoinKind.LEFT_OUTER; } ) |
| 1182 | <LEFTPAREN> <LEFTPAREN> leftClauses = Clauses() <RIGHTPAREN> "," |
| 1183 | <LEFTPAREN> rightClauses = Clauses() <RIGHTPAREN> "," |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1184 | whereExpr = Expression() <RIGHTPAREN> |
| 1185 | { |
| 1186 | JoinClause jc = new JoinClause(kind); |
| 1187 | jc.setLeftClauses(leftClauses); |
| 1188 | jc.setRightClauses(rightClauses); |
| 1189 | jc.setWhereExpr(whereExpr); |
| 1190 | return jc; |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | Clause ForClause()throws ParseException : |
| 1195 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1196 | ForClause fc = new ForClause(); |
| 1197 | VariableExpr varExp; |
| 1198 | VariableExpr varPos = null; |
| 1199 | Expression inExp; |
| 1200 | extendCurrentScope(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1201 | } |
| 1202 | { |
| 1203 | "for" varExp = Variable() |
| 1204 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1205 | getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); |
| 1206 | } |
| 1207 | ("at" varPos = Variable() |
| 1208 | { |
| 1209 | getCurrentScope().addNewVarSymbolToScope(varPos.getVar()); |
| 1210 | } |
| 1211 | )? |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1212 | "in" ( inExp = Expression() ) |
| 1213 | { |
| 1214 | fc.setVarExpr(varExp); |
| 1215 | fc.setInExpr(inExp); |
| 1216 | if (varPos != null) { |
| 1217 | fc.setPosExpr(varPos); |
| 1218 | } |
| 1219 | return fc; |
| 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | Clause LetClause() throws ParseException: |
| 1224 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1225 | LetClause lc = new LetClause(); |
| 1226 | VariableExpr varExp; |
| 1227 | Expression beExp; |
| 1228 | extendCurrentScope(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1229 | } |
| 1230 | { |
ilovesoup | b2527c1 | 2012-07-12 03:21:13 +0000 | [diff] [blame] | 1231 | "let" varExp = Variable() ":=" beExp = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1232 | { |
| 1233 | getCurrentScope().addNewVarSymbolToScope(varExp.getVar()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1234 | lc.setVarExpr(varExp); |
| 1235 | lc.setBeExpr(beExp); |
| 1236 | return lc; |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | Clause WhereClause()throws ParseException : |
| 1241 | { |
| 1242 | WhereClause wc = new WhereClause(); |
| 1243 | Expression whereExpr; |
| 1244 | } |
| 1245 | { |
| 1246 | "where" whereExpr = Expression() |
| 1247 | { |
| 1248 | wc.setWhereExpr(whereExpr); |
| 1249 | return wc; |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | Clause OrderbyClause()throws ParseException : |
| 1254 | { |
| 1255 | OrderbyClause oc = new OrderbyClause(); |
| 1256 | Expression orderbyExpr; |
| 1257 | List<Expression> orderbyList = new ArrayList<Expression>(); |
| 1258 | List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >(); |
| 1259 | int numOfOrderby = 0; |
| 1260 | } |
| 1261 | { |
| 1262 | ( |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1263 | "order" |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1264 | { |
| 1265 | String hint = getHint(token); |
| 1266 | if (hint != null && hint.startsWith(INMEMORY_HINT)) { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1267 | String splits[] = hint.split(" +"); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1268 | int numFrames = Integer.parseInt(splits[1]); |
| 1269 | int numTuples = Integer.parseInt(splits[2]); |
| 1270 | oc.setNumFrames(numFrames); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1271 | oc.setNumTuples(numTuples); |
| 1272 | } |
| 1273 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1274 | "by" orderbyExpr = Expression() |
| 1275 | { |
| 1276 | orderbyList.add(orderbyExpr); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1277 | OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1278 | } |
| 1279 | ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; }) |
| 1280 | | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))? |
| 1281 | { |
| 1282 | modifierList.add(modif); |
| 1283 | } |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1284 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1285 | ("," orderbyExpr = Expression() |
| 1286 | { |
| 1287 | orderbyList.add(orderbyExpr); |
| 1288 | modif = OrderbyClause.OrderModifier.ASC; |
| 1289 | } |
| 1290 | ( ("asc" { modif = OrderbyClause.OrderModifier.ASC; }) |
| 1291 | | ("desc" { modif = OrderbyClause.OrderModifier.DESC; }))? |
| 1292 | { |
| 1293 | modifierList.add(modif); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1294 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1295 | )* |
| 1296 | ) |
| 1297 | { |
| 1298 | oc.setModifierList(modifierList); |
| 1299 | oc.setOrderbyList(orderbyList); |
| 1300 | return oc; |
| 1301 | } |
| 1302 | } |
| 1303 | Clause GroupClause()throws ParseException : |
| 1304 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1305 | GroupbyClause gbc = new GroupbyClause(); |
| 1306 | // GbyVariableExpressionPair pair = new GbyVariableExpressionPair(); |
| 1307 | List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1308 | List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>(); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1309 | List<VariableExpr> withVarList= new ArrayList<VariableExpr>(); |
| 1310 | VariableExpr var = null; |
| 1311 | VariableExpr withVar = null; |
| 1312 | Expression expr = null; |
| 1313 | VariableExpr decorVar = null; |
| 1314 | Expression decorExpr = null; |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1315 | } |
| 1316 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1317 | { |
| 1318 | Scope newScope = extendCurrentScopeNoPush(true); |
| 1319 | // extendCurrentScope(true); |
| 1320 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1321 | "group" |
| 1322 | { |
| 1323 | String hint = getHint(token); |
| 1324 | if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1325 | gbc.setHashGroupByHint(true); |
| 1326 | } |
| 1327 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1328 | "by" (LOOKAHEAD(2) var = Variable() |
| 1329 | { |
| 1330 | newScope.addNewVarSymbolToScope(var.getVar()); |
| 1331 | } ":=")? |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1332 | expr = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1333 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1334 | GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1335 | vePairList.add(pair1); |
| 1336 | } |
| 1337 | ("," ( LOOKAHEAD(2) var = Variable() |
| 1338 | { |
| 1339 | newScope.addNewVarSymbolToScope(var.getVar()); |
| 1340 | } ":=")? |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1341 | expr = Expression() |
| 1342 | { |
| 1343 | GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1344 | vePairList.add(pair2); |
| 1345 | } |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1346 | )* |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1347 | ("decor" decorVar = Variable() ":=" decorExpr = Expression() |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1348 | { |
| 1349 | newScope.addNewVarSymbolToScope(decorVar.getVar()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1350 | GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr); |
| 1351 | decorPairList.add(pair3); |
| 1352 | } |
| 1353 | ("," "decor" decorVar = Variable() ":=" decorExpr = Expression() |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1354 | { |
| 1355 | newScope.addNewVarSymbolToScope(decorVar.getVar()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1356 | GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1357 | decorPairList.add(pair4); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1358 | } |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1359 | )* |
| 1360 | )? |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1361 | "with" withVar = VariableRef() |
| 1362 | { |
| 1363 | if(withVar.getIsNewVar()==true) |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1364 | throw new ParseException("can't find variable " + withVar.getVar()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1365 | withVarList.add(withVar); |
| 1366 | newScope.addNewVarSymbolToScope(withVar.getVar()); |
| 1367 | } |
| 1368 | ("," withVar = VariableRef() |
| 1369 | { |
| 1370 | if(withVar.getIsNewVar()==true) |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1371 | throw new ParseException("can't find variable " + withVar.getVar()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1372 | withVarList.add(withVar); |
| 1373 | newScope.addNewVarSymbolToScope(withVar.getVar()); |
| 1374 | })* |
| 1375 | { |
| 1376 | gbc.setGbyPairList(vePairList); |
| 1377 | gbc.setDecorPairList(decorPairList); |
| 1378 | gbc.setWithVarList(withVarList); |
| 1379 | replaceCurrentScope(newScope); |
| 1380 | return gbc; |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | |
| 1385 | LimitClause LimitClause() throws ParseException: |
| 1386 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1387 | LimitClause lc = new LimitClause(); |
| 1388 | Expression expr; |
| 1389 | pushForbiddenScope(getCurrentScope()); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1390 | } |
| 1391 | { |
| 1392 | "limit" expr = Expression() { lc.setLimitExpr(expr); } |
| 1393 | ("offset" expr = Expression() { lc.setOffset(expr); })? |
| 1394 | |
| 1395 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1396 | popForbiddenScope(); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1397 | return lc; |
| 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | DistinctClause DistinctClause() throws ParseException: |
| 1402 | { |
| 1403 | List<Expression> exprs = new ArrayList<Expression>(); |
| 1404 | Expression expr; |
| 1405 | } |
| 1406 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1407 | "distinct" "by" expr = Expression() |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1408 | { |
| 1409 | exprs.add(expr); |
| 1410 | } |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1411 | ("," expr = Expression() |
| 1412 | { |
| 1413 | exprs.add(expr); |
| 1414 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1415 | )* |
| 1416 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1417 | return new DistinctClause(exprs); |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1418 | } |
| 1419 | } |
| 1420 | |
| 1421 | |
| 1422 | QuantifiedExpression QuantifiedExpression()throws ParseException: |
| 1423 | { |
| 1424 | QuantifiedExpression qc = new QuantifiedExpression(); |
| 1425 | List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>(); |
| 1426 | Expression satisfiesExpr; |
| 1427 | VariableExpr var; |
| 1428 | Expression inExpr; |
| 1429 | QuantifiedPair pair; |
| 1430 | } |
| 1431 | { |
| 1432 | { |
| 1433 | createNewScope(); |
| 1434 | } |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1435 | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1436 | ( ("some" { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); }) |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1437 | | ("every" { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); })) |
| 1438 | var = Variable() "in" inExpr = Expression() |
| 1439 | { |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1440 | pair = new QuantifiedPair(var, inExpr); |
| 1441 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1442 | quantifiedList.add(pair); |
| 1443 | } |
| 1444 | ( |
| 1445 | "," var = Variable() "in" inExpr = Expression() |
| 1446 | { |
| 1447 | pair = new QuantifiedPair(var, inExpr); |
| 1448 | getCurrentScope().addNewVarSymbolToScope(var.getVar()); |
| 1449 | quantifiedList.add(pair); |
| 1450 | } |
| 1451 | )* |
| 1452 | "satisfies" satisfiesExpr = Expression() |
| 1453 | { |
| 1454 | qc.setSatisfiesExpr(satisfiesExpr); |
| 1455 | qc.setQuantifiedList(quantifiedList); |
| 1456 | removeCurrentScope(); |
| 1457 | return qc; |
| 1458 | } |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | TOKEN_MGR_DECLS: |
| 1462 | { |
| 1463 | public int commentDepth = 0; |
| 1464 | } |
| 1465 | |
| 1466 | <DEFAULT> |
| 1467 | TOKEN : |
| 1468 | { |
| 1469 | <CARET : "^" > |
| 1470 | } |
| 1471 | |
| 1472 | <DEFAULT> |
| 1473 | TOKEN : |
| 1474 | { |
| 1475 | <DATASET : "dataset" > |
| 1476 | } |
| 1477 | |
| 1478 | <DEFAULT> |
| 1479 | TOKEN : |
| 1480 | { |
| 1481 | <LEFTPAREN : "(" > |
| 1482 | } |
| 1483 | |
| 1484 | <DEFAULT> |
| 1485 | TOKEN : |
| 1486 | { |
| 1487 | <RIGHTPAREN : ")" > |
| 1488 | } |
| 1489 | |
| 1490 | |
| 1491 | <DEFAULT> |
| 1492 | TOKEN : |
| 1493 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1494 | <INTEGER_LITERAL : (<DIGIT>)+ > |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | |
| 1498 | <DEFAULT> |
| 1499 | TOKEN : |
| 1500 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1501 | <NULL : "null"> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | <DEFAULT> |
| 1505 | TOKEN : |
| 1506 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1507 | <TRUE : "true"> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | <DEFAULT> |
| 1511 | TOKEN : |
| 1512 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1513 | <FALSE : "false"> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | <DEFAULT> |
| 1517 | TOKEN : |
| 1518 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1519 | <#DIGIT : ["0" - "9"]> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | |
| 1523 | TOKEN: |
| 1524 | { |
| 1525 | < DOUBLE_LITERAL: <INTEGER> |
| 1526 | | <INTEGER> ( "." <INTEGER> )? |
| 1527 | | "." <INTEGER> |
| 1528 | > |
| 1529 | | |
| 1530 | < FLOAT_LITERAL: <INTEGER> ( "f" | "F" ) |
| 1531 | | <INTEGER> ( "." <INTEGER> ( "f" | "F" ) )? |
| 1532 | | "." <INTEGER> ( "f" | "F" ) |
| 1533 | > |
| 1534 | | |
| 1535 | <INTEGER : (<DIGIT>)+ > |
| 1536 | } |
| 1537 | |
| 1538 | <DEFAULT> |
| 1539 | TOKEN : |
| 1540 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1541 | <#LETTER : ["A" - "Z", "a" - "z"]> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | <DEFAULT> |
| 1545 | TOKEN : |
| 1546 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1547 | <SPECIALCHARS : ["$", "_", "-"] > |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | <DEFAULT> |
| 1551 | TOKEN : |
| 1552 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1553 | <STRING_LITERAL : ("\"" (<EscapeQuot> | ~["\""])* "\"") | ("\'"(<EscapeApos> | ~["\'"])* "\'")> |
| 1554 | | |
| 1555 | < #EscapeQuot: "\\\"" > |
| 1556 | | |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1557 | < #EscapeApos: "\\\'" > |
| 1558 | } |
| 1559 | |
| 1560 | <DEFAULT> |
| 1561 | TOKEN : |
| 1562 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1563 | <IDENTIFIER : (<LETTER>)+ (<LETTER> | <DIGIT> | <SPECIALCHARS>)*> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | <DEFAULT> |
| 1567 | TOKEN : |
| 1568 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1569 | <VARIABLE : "$" <IDENTIFIER> > |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | <DEFAULT> |
| 1573 | TOKEN : |
| 1574 | { |
| 1575 | <METAVARIABLECLAUSE : "#" <IDENTIFIER> > |
| 1576 | } |
| 1577 | |
| 1578 | <DEFAULT> |
| 1579 | TOKEN : |
| 1580 | { |
| 1581 | <METAVARIABLE : "$$" <IDENTIFIER> > |
| 1582 | } |
| 1583 | |
| 1584 | SKIP: |
| 1585 | { |
| 1586 | " " |
| 1587 | | "\t" |
| 1588 | | "\r" |
| 1589 | | "\n" |
| 1590 | } |
| 1591 | |
| 1592 | SKIP: |
| 1593 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1594 | <"//" (~["\n"])* "\n"> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | SKIP: |
| 1598 | { |
Taewoo Kim | a12d8cd | 2015-03-04 13:47:08 -0800 | [diff] [blame] | 1599 | <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?> |
vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | |
| 1603 | SKIP: |
| 1604 | { |
| 1605 | <"/*"> {commentDepth=1;}: INSIDE_COMMENT |
| 1606 | } |
| 1607 | |
| 1608 | <INSIDE_COMMENT> |
| 1609 | SPECIAL_TOKEN: |
| 1610 | { |
| 1611 | <"+"(" ")*(~["/","*"])*> |
| 1612 | } |
| 1613 | |
| 1614 | <INSIDE_COMMENT> |
| 1615 | SKIP: |
| 1616 | { |
| 1617 | <"/*"> {commentDepth++;} |
| 1618 | } |
| 1619 | |
| 1620 | <INSIDE_COMMENT> |
| 1621 | SKIP: |
| 1622 | { |
| 1623 | <"*/"> {commentDepth--; if (commentDepth == 0) SwitchTo(DEFAULT);} |
| 1624 | | <~[]> |
| 1625 | } |