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