diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index c3a9c0b..a7771b9 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -67,9 +67,12 @@
 import org.apache.asterix.common.exceptions.ErrorCode;
 import org.apache.asterix.common.functions.FunctionConstants;
 import org.apache.asterix.common.functions.FunctionSignature;
+import org.apache.asterix.lang.common.base.AbstractLangExpression;
+import org.apache.asterix.lang.common.base.AbstractStatement;
 import org.apache.asterix.lang.common.base.Expression;
 import org.apache.asterix.lang.common.base.Literal;
 import org.apache.asterix.lang.common.base.IParser;
+import org.apache.asterix.lang.common.base.ILangExpression;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.clause.GroupbyClause;
 import org.apache.asterix.lang.common.clause.LetClause;
@@ -175,6 +178,7 @@
 import org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation;
 import org.apache.hyracks.algebricks.core.algebra.expressions.IndexedNLJoinExpressionAnnotation;
 import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.api.exceptions.SourceLocation;
 
 class SQLPPParser extends ScopeChecker implements IParser {
 
@@ -216,13 +220,14 @@
     };
 
     private static class FunctionName {
-       public String dataverse = null;
-       public String library = null;
-       public String function = null;
-       public String hint = null;
+       public String dataverse;
+       public String library;
+       public String function;
+       public String hint;
+       public SourceLocation sourceLoc;
     }
 
-    private static String getHint(Token t) {
+    private String getHint(Token t) {
         if (t.specialToken == null) {
             return null;
         }
@@ -234,7 +239,11 @@
         return s.substring(1).trim();
     }
 
-    private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
+    private Token getHintToken(Token t) {
+        return t.specialToken;
+    }
+
+    private IRecordFieldDataGen parseFieldDataGen(String hint, Token hintToken) throws ParseException {
       IRecordFieldDataGen rfdg = null;
       String splits[] = hint.split(" +");
       if (splits[0].equals(VAL_FILE_HINT)) {
@@ -260,7 +269,7 @@
         } else if (splits[1].equals("double")) {
           vt = FieldIntervalDataGen.ValueType.DOUBLE;
         } else {
-          throw new ParseException("Unknown type for interval data gen: " + splits[1]);
+          throw new SqlppParseException(getSourceLocation(hintToken), "Unknown type for interval data gen: " + splits[1]);
         }
         rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
       } else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
@@ -294,10 +303,12 @@
         try {
             return Statement();
         } catch (Error e) {
-            // this is here as the JavaCharStream that's below the lexer somtimes throws Errors that are not handled
+            // this is here as the JavaCharStream that's below the lexer sometimes throws Errors that are not handled
             // by the ANTLR-generated lexer or parser (e.g it does this for invalid backslash u + 4 hex digits escapes)
             final String msg = e.getClass().getSimpleName() + (e.getMessage() != null ? ": " + e.getMessage() : "");
             throw new CompilationException(ErrorCode.PARSE_ERROR, msg);
+        } catch (SqlppParseException e) {
+            throw new CompilationException(ErrorCode.PARSE_ERROR, e.getSourceLocation(), getMessage(e));
         } catch (ParseException e) {
             throw new CompilationException(ErrorCode.PARSE_ERROR, getMessage(e));
         }
@@ -315,34 +326,42 @@
         int maxSize = appendExpected(expected, expectedTokenSequences, tokenImage);
         Token tok = currentToken.next;
         int line = tok.beginLine;
-        String message = "In line " + line + " >>" + getLine(line) + "<<" + sep + "Encountered ";
+        StringBuilder message = new StringBuilder(128);
+        message.append("In line ").append(line).append(" >>").append(getLine(line)).append("<<").append(sep).append("Encountered ");
         for (int i = 0; i < maxSize; i++) {
             if (i != 0) {
-                message += " ";
+                message.append(' ');
             }
             if (tok.kind == 0) {
-                message += fixQuotes(tokenImage[0]);
+                message.append(fixQuotes(tokenImage[0]));
                 break;
             }
             final String fixedTokenImage = tokenImage[tok.kind];
             if (! tok.image.equalsIgnoreCase(stripQuotes(fixedTokenImage))) {
-                message += fixQuotes(fixedTokenImage) + " ";
+                message.append(fixQuotes(fixedTokenImage)).append(' ');
             }
-            message += quot + addEscapes(tok.image) + quot;
+            message.append(quot).append(addEscapes(tok.image)).append(quot);
             tok = tok.next;
         }
-        message += " at column " + currentToken.next.beginColumn + "." + sep;
+        message.append(" at column ").append(currentToken.next.beginColumn).append('.').append(sep);
         if (REPORT_EXPECTED_TOKENS) {
             if (expectedTokenSequences.length == 1) {
-                message += "Was expecting:" + sep + "    ";
+                message.append("Was expecting:").append(sep).append("    ");
             } else {
-                message += "Was expecting one of:" + sep + "    ";
+                message.append("Was expecting one of:").append(sep).append("    ");
             }
-            message += expected.toString();
+            message.append(expected);
         }
-        return message;
+        return message.toString();
     }
 
+    protected static SourceLocation getSourceLocation(Token token) {
+        return token != null ? new SourceLocation(token.beginLine, token.beginColumn) : null;
+    }
+
+    protected static void setSourceLocation(AbstractLangExpression expr, Token sourceLocToken) {
+        expr.setSourceLocation(getSourceLocation(sourceLocToken));
+    }
 }
 
 PARSER_END(SQLPPParser)
@@ -399,46 +418,52 @@
 
 DataverseDecl DataverseDeclaration() throws ParseException:
 {
+  Token startToken = null;
   String dvName = null;
 }
 {
-  <USE> dvName = Identifier()
+  <USE> { startToken = token; } dvName = Identifier()
     {
       defaultDataverse = dvName;
-      return new DataverseDecl(new Identifier(dvName));
+      DataverseDecl dvDecl = new DataverseDecl(new Identifier(dvName));
+      setSourceLocation(dvDecl, startToken);
+      return dvDecl;
     }
 }
 
 Statement CreateStatement() throws ParseException:
 {
+  Token startToken = null;
   String hint = null;
-  boolean dgen = false;
+  Token hintToken = null;
+  boolean hintDGen = false;
   Statement stmt = null;
 }
 {
-  <CREATE>
+  <CREATE> { startToken = token; }
   (
     {
       hint = getHint(token);
-      if (hint != null && hint.startsWith(DGEN_HINT)) {
-        dgen = true;
+      if (hint != null) {
+        hintToken = getHintToken(token);
+        hintDGen = hint.startsWith(DGEN_HINT);
       }
     }
-    stmt = TypeSpecification(hint, dgen)
-    | stmt = NodegroupSpecification()
-    | stmt = DatasetSpecification()
-    | stmt = IndexSpecification()
-    | stmt = DataverseSpecification()
-    | stmt = FunctionSpecification()
-    | stmt = FeedSpecification()
-    | stmt = FeedPolicySpecification()
+    stmt = TypeSpecification(startToken, hint, hintDGen, hintToken)
+    | stmt = NodegroupSpecification(startToken)
+    | stmt = DatasetSpecification(startToken)
+    | stmt = IndexSpecification(startToken)
+    | stmt = DataverseSpecification(startToken)
+    | stmt = FunctionSpecification(startToken)
+    | stmt = FeedSpecification(startToken)
+    | stmt = FeedPolicySpecification(startToken)
   )
   {
     return stmt;
   }
 }
 
-TypeDecl TypeSpecification(String hint, boolean dgen) throws ParseException:
+TypeDecl TypeSpecification(Token startStmtToken, String hint, boolean dgen, Token hintToken) throws ParseException:
 {
   Pair<Identifier,Identifier> nameComponents = null;
   boolean ifNotExists = false;
@@ -453,18 +478,19 @@
       if (dgen) {
         String splits[] = hint.split(" +");
         if (splits.length != 3) {
-          throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
+          throw new SqlppParseException(getSourceLocation(hintToken), "Expecting /*+ dgen <filename> <numberOfItems> */");
         }
         filename = splits[1];
         numValues = Long.parseLong(splits[2]);
       }
       TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
-      return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
+      TypeDecl stmt = new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
+      setSourceLocation(stmt, startStmtToken);
+      return stmt;
     }
 }
 
-
-NodegroupDecl NodegroupSpecification() throws ParseException:
+NodegroupDecl NodegroupSpecification(Token startStmtToken) throws ParseException:
 {
   String name = null;
   String tmp = null;
@@ -484,11 +510,13 @@
     }
   )*
     {
-      return new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
+      NodegroupDecl stmt = new NodegroupDecl(new Identifier(name), ncNames, ifNotExists);
+      setSourceLocation(stmt, startStmtToken);
+      return stmt;
     }
 }
 
-DatasetDecl DatasetSpecification() throws ParseException:
+DatasetDecl DatasetSpecification(Token startStmtToken) throws ParseException:
 {
   Pair<Identifier,Identifier> nameComponents = null;
   boolean ifNotExists = false;
@@ -499,7 +527,7 @@
   Pair<List<Integer>, List<List<String>>> primaryKeyFields = null;
   String nodeGroupName = null;
   Map<String,String> hints = new HashMap<String,String>();
-  DatasetDecl dsetDecl = null;
+  DatasetDecl stmt = null;
   boolean autogenerated = false;
   Pair<Integer, List<String>> filterField = null;
   Pair<Identifier,Identifier> metaTypeComponents = new Pair<Identifier, Identifier>(null, null);
@@ -519,7 +547,7 @@
         edd.setAdapter(adapterName);
         edd.setProperties(properties);
         try{
-        dsetDecl = new DatasetDecl(nameComponents.first,
+        stmt = new DatasetDecl(nameComponents.first,
                                    nameComponents.second,
                                    typeComponents.first,
                                    typeComponents.second,
@@ -532,7 +560,7 @@
                                    withRecord,
                                    ifNotExists);
         } catch (CompilationException e){
-           throw new ParseException(e.getMessage());
+           throw new SqlppParseException(getSourceLocation(startStmtToken), e.getMessage());
         }
       }
 
@@ -544,8 +572,9 @@
         <WITH>
         name = Identifier()
         {
-            if(!name.toLowerCase().equals("meta")){
-                throw new ParseException("We can only support one additional associated field called \"meta\".");
+            if (!name.equalsIgnoreCase("meta")){
+                throw new SqlppParseException(getSourceLocation(startStmtToken),
+                    "We can only support one additional associated field called \"meta\".");
             }
         }
         <LEFTPAREN> metaTypeComponents = TypeName() <RIGHTPAREN>
@@ -559,14 +588,15 @@
     ( <WITH> withRecord = RecordConstructor() )?
       {
         if(filterField!=null && filterField.first!=0){
-          throw new ParseException("A filter field can only be a field in the main record of the dataset.");
+          throw new SqlppParseException(getSourceLocation(startStmtToken),
+            "A filter field can only be a field in the main record of the dataset.");
         }
         InternalDetailsDecl idd = new InternalDetailsDecl(primaryKeyFields.second,
                                                           primaryKeyFields.first,
                                                           autogenerated,
                                                           filterField == null? null : filterField.second);
         try{
-        dsetDecl = new DatasetDecl(nameComponents.first,
+        stmt = new DatasetDecl(nameComponents.first,
                                    nameComponents.second,
                                    typeComponents.first,
                                    typeComponents.second,
@@ -579,33 +609,36 @@
                                    withRecord,
                                    ifNotExists);
         } catch (CompilationException e){
-           throw new ParseException(e.getMessage());
+           throw new SqlppParseException(getSourceLocation(startStmtToken), e.getMessage());
         }
       }
   )
     {
-      return dsetDecl;
+      setSourceLocation(stmt, startStmtToken);
+      return stmt;
     }
 }
 
 RefreshExternalDatasetStatement RefreshExternalDatasetStatement() throws ParseException:
 {
-  RefreshExternalDatasetStatement redss = new RefreshExternalDatasetStatement();
+  Token startToken = null;
   Pair<Identifier,Identifier> nameComponents = null;
   String datasetName = null;
 }
 {
-    <REFRESH> <EXTERNAL> Dataset() nameComponents = QualifiedName()
+    <REFRESH> { startToken = token; } <EXTERNAL> Dataset() nameComponents = QualifiedName()
     {
-    redss.setDataverseName(nameComponents.first);
-    redss.setDatasetName(nameComponents.second);
-    return redss;
+      RefreshExternalDatasetStatement stmt = new RefreshExternalDatasetStatement();
+      stmt.setDataverseName(nameComponents.first);
+      stmt.setDatasetName(nameComponents.second);
+      setSourceLocation(stmt, startToken);
+      return stmt;
     }
 }
 
-CreateIndexStatement IndexSpecification() throws ParseException:
+CreateIndexStatement IndexSpecification(Token startStmtToken) throws ParseException:
 {
-  CreateIndexStatement cis = new CreateIndexStatement();
+  CreateIndexStatement stmt = new CreateIndexStatement();
   String indexName = null;
   boolean ifNotExists = false;
   Pair<Identifier,Identifier> nameComponents = null;
@@ -621,13 +654,13 @@
     <ON> nameComponents = QualifiedName()
     <LEFTPAREN> ( fieldPair = OpenField()
       {
-        cis.addFieldExprPair(fieldPair.second);
-        cis.addFieldIndexIndicator(fieldPair.first);
+        stmt.addFieldExprPair(fieldPair.second);
+        stmt.addFieldIndexIndicator(fieldPair.first);
       }
     ) (<COMMA> fieldPair = OpenField()
       {
-        cis.addFieldExprPair(fieldPair.second);
-        cis.addFieldIndexIndicator(fieldPair.first);
+        stmt.addFieldExprPair(fieldPair.second);
+        stmt.addFieldIndexIndicator(fieldPair.first);
       }
     )* <RIGHTPAREN> ( <TYPE> indexType = IndexType() )? ( <ENFORCED> { enforced = true; } )?)
     |
@@ -642,16 +675,17 @@
     if (isPrimaryIdx && indexName == null) {
       indexName = "primary_idx_" + nameComponents.second;
     }
-    cis.setIndexName(new Identifier(indexName));
-    cis.setIfNotExists(ifNotExists);
-    cis.setDataverseName(nameComponents.first);
-    cis.setDatasetName(nameComponents.second);
+    stmt.setIndexName(new Identifier(indexName));
+    stmt.setIfNotExists(ifNotExists);
+    stmt.setDataverseName(nameComponents.first);
+    stmt.setDatasetName(nameComponents.second);
     if (indexType != null) {
-      cis.setIndexType(indexType.type);
-      cis.setGramLength(indexType.gramLength);
+      stmt.setIndexType(indexType.type);
+      stmt.setGramLength(indexType.gramLength);
     }
-    cis.setEnforced(enforced);
-    return cis;
+    stmt.setEnforced(enforced);
+    setSourceLocation(stmt, startStmtToken);
+    return stmt;
   }
 }
 
@@ -710,7 +744,7 @@
     }
 }
 
-CreateDataverseStatement DataverseSpecification() throws ParseException :
+CreateDataverseStatement DataverseSpecification(Token startStmtToken) throws ParseException :
 {
   String dvName = null;
   boolean ifNotExists = false;
@@ -719,11 +753,13 @@
   <DATAVERSE> dvName = Identifier()
   ifNotExists = IfNotExists()
     {
-      return new CreateDataverseStatement(new Identifier(dvName), null, ifNotExists);
+      CreateDataverseStatement stmt = new CreateDataverseStatement(new Identifier(dvName), null, ifNotExists);
+      setSourceLocation(stmt, startStmtToken);
+      return stmt;
     }
 }
 
-CreateFunctionStatement FunctionSpecification() throws ParseException:
+CreateFunctionStatement FunctionSpecification(Token startStmtToken) throws ParseException:
 {
   FunctionSignature signature;
   boolean ifNotExists = false;
@@ -759,17 +795,19 @@
       getCurrentScope().addFunctionDescriptor(signature, false);
       removeCurrentScope();
       defaultDataverse = currentDataverse;
-      return new CreateFunctionStatement(signature, paramList, functionBody, functionBodyExpr, ifNotExists);
+      CreateFunctionStatement stmt = new CreateFunctionStatement(signature, paramList, functionBody, functionBodyExpr, ifNotExists);
+      setSourceLocation(stmt, startStmtToken);
+      return stmt;
     }
 }
 
-CreateFeedStatement FeedSpecification() throws ParseException:
+CreateFeedStatement FeedSpecification(Token startStmtToken) throws ParseException:
 {
   Pair<Identifier,Identifier> nameComponents = null;
   boolean ifNotExists = false;
   String adapterName = null;
   Map<String,String> properties = null;
-  CreateFeedStatement cfs = null;
+  CreateFeedStatement stmt = null;
   Pair<Identifier,Identifier> sourceNameComponents = null;
   RecordConstructor withRecord = null;
 }
@@ -778,15 +816,16 @@
   <WITH> withRecord = RecordConstructor()
   {
     try {
-      cfs = new CreateFeedStatement(nameComponents, withRecord, ifNotExists);
-      return cfs;
+      stmt = new CreateFeedStatement(nameComponents, withRecord, ifNotExists);
+      setSourceLocation(stmt, startStmtToken);
+      return stmt;
     } catch (AlgebricksException e) {
-      throw new ParseException(e.getMessage());
+      throw new SqlppParseException(getSourceLocation(startStmtToken), e.getMessage());
     }
   }
 }
 
-CreateFeedPolicyStatement FeedPolicySpecification() throws ParseException:
+CreateFeedPolicyStatement FeedPolicySpecification(Token startStmtToken) throws ParseException:
 {
   String policyName = null;
   String basePolicyName = null;
@@ -794,7 +833,7 @@
   String definition = null;
   boolean ifNotExists = false;
   Map<String,String> properties = null;
-  CreateFeedPolicyStatement cfps = null;
+  CreateFeedPolicyStatement stmt = null;
 }
 {
   (
@@ -802,22 +841,21 @@
       <FROM>
       (<POLICY> basePolicyName = Identifier() properties = Configuration() (<DEFINITION> definition = ConstantString())?
       {
-        cfps = new CreateFeedPolicyStatement(policyName,
+        stmt = new CreateFeedPolicyStatement(policyName,
                                    basePolicyName, properties, definition, ifNotExists);
       }
      | <PATH> sourcePolicyFile = ConstantString() (<DEFINITION> definition = ConstantString())?
        {
-        cfps = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists);
+        stmt = new CreateFeedPolicyStatement(policyName, sourcePolicyFile, definition, ifNotExists);
        }
      )
   )
     {
-      return cfps;
+      setSourceLocation(stmt, startStmtToken);
+      return stmt;
     }
 }
 
-
-
 List<VarIdentifier> ParameterList() throws ParseException:
 {
   List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
@@ -896,7 +934,7 @@
     {
       arity = new Integer(token.image);
       if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
-        throw new ParseException(" invalid arity:" + arity);
+        throw new SqlppParseException(getSourceLocation(token), "Invalid arity:" + arity);
       }
 
       // TODO use fctName.library
@@ -930,15 +968,16 @@
 
 Statement DropStatement() throws ParseException:
 {
+  Token startToken = null;
   String id = null;
   Pair<Identifier,Identifier> pairId = null;
   Triple<Identifier,Identifier,Identifier> tripleId = null;
   FunctionSignature funcSig = null;
   boolean ifExists = false;
-  Statement stmt = null;
+  AbstractStatement stmt = null;
 }
 {
-  <DROP>
+  <DROP> { startToken = token; }
   (
     Dataset() pairId = QualifiedName() ifExists = IfExists()
       {
@@ -974,6 +1013,7 @@
       }
   )
   {
+    setSourceLocation(stmt, startToken);
     return stmt;
   }
 }
@@ -994,54 +1034,61 @@
 
 InsertStatement InsertStatement() throws ParseException:
 {
+  Token startToken = null;
   Pair<Identifier,Identifier> nameComponents = null;
   VariableExpr var = null;
   Query query = null;
   Expression returnExpression = null;
 }
 {
-  <INSERT> <INTO> nameComponents = QualifiedName() (<AS> var = Variable())?
+  <INSERT> { startToken = token; } <INTO> nameComponents = QualifiedName() (<AS> var = Variable())?
     query = Query(false)
     ( <RETURNING> returnExpression = Expression())?
     {
       if (returnExpression != null && var == null) {
-         var = ExpressionToVariableUtil.getGeneratedVariable(query.getBody(), true);
+        var = ExpressionToVariableUtil.getGeneratedVariable(query.getBody(), true);
       }
       query.setTopLevel(true);
-      return new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(), var,
-                                 returnExpression);
+      InsertStatement stmt = new InsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(),
+        var, returnExpression);
+      setSourceLocation(stmt, startToken);
+      return stmt;
     }
 }
 
 UpsertStatement UpsertStatement() throws ParseException:
 {
+  Token startToken = null;
   Pair<Identifier,Identifier> nameComponents = null;
   VariableExpr var = null;
   Query query = null;
   Expression returnExpression = null;
 }
 {
-  <UPSERT> <INTO> nameComponents = QualifiedName() (<AS> var = Variable())?
+  <UPSERT> { startToken = token; } <INTO> nameComponents = QualifiedName() (<AS> var = Variable())?
     query = Query(false)
     ( <RETURNING> returnExpression = Expression())?
     {
       if (returnExpression != null && var == null) {
-         var = ExpressionToVariableUtil.getGeneratedVariable(query.getBody(), true);
+        var = ExpressionToVariableUtil.getGeneratedVariable(query.getBody(), true);
       }
       query.setTopLevel(true);
-      return new UpsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(), var,
-                                 returnExpression);
+      UpsertStatement stmt = new UpsertStatement(nameComponents.first, nameComponents.second, query, getVarCounter(),
+        var, returnExpression);
+      setSourceLocation(stmt, startToken);
+      return stmt;
     }
 }
 
 DeleteStatement DeleteStatement() throws ParseException:
 {
+  Token startToken = null;
   VariableExpr varExpr = null;
   Expression condition = null;
   Pair<Identifier, Identifier> nameComponents;
 }
 {
-  <DELETE>
+  <DELETE> { startToken = token; }
   <FROM> nameComponents  = QualifiedName()
          ((<AS>)? varExpr = Variable())?
   (<WHERE> condition = Expression())?
@@ -1050,14 +1097,18 @@
         varExpr = new VariableExpr();
         VarIdentifier var = SqlppVariableUtil.toInternalVariableIdentifier(nameComponents.second.getValue());
         varExpr.setVar(var);
+        setSourceLocation(varExpr, startToken);
       }
-      return new DeleteStatement(varExpr, nameComponents.first, nameComponents.second,
+      DeleteStatement stmt = new DeleteStatement(varExpr, nameComponents.first, nameComponents.second,
           condition, getVarCounter());
+      setSourceLocation(stmt, startToken);
+      return stmt;
   }
 }
 
 UpdateStatement UpdateStatement() throws ParseException:
 {
+  Token startToken = null;
   VariableExpr vars;
   Expression target;
   Expression condition;
@@ -1065,7 +1116,7 @@
   List<UpdateClause> ucs = new ArrayList<UpdateClause>();
 }
 {
-  <UPDATE> vars = Variable() <IN> target = Expression()
+  <UPDATE> { startToken = token; } vars = Variable() <IN> target = Expression()
   <WHERE> condition = Expression()
   <LEFTPAREN> (uc = UpdateClause()
     {
@@ -1077,7 +1128,9 @@
     }
   )*) <RIGHTPAREN>
     {
-      return new UpdateStatement(vars, target, condition, ucs);
+      UpdateStatement stmt = new UpdateStatement(vars, target, condition, ucs);
+      setSourceLocation(stmt, startToken);
+      return stmt;
     }
 }
 
@@ -1108,18 +1161,22 @@
 
 Statement SetStatement() throws ParseException:
 {
+  Token startToken = null;
   String pn = null;
   String pv = null;
 }
 {
-  <SET> pn = Identifier() pv = ConstantString()
+  <SET> { startToken = token; } pn = Identifier() pv = ConstantString()
     {
-      return new SetStatement(pn, pv);
+      SetStatement stmt = new SetStatement(pn, pv);
+      setSourceLocation(stmt, startToken);
+      return stmt;
     }
 }
 
 Statement WriteStatement() throws ParseException:
 {
+  Token startToken = null;
   String nodeName = null;
   String fileName = null;
   Query query;
@@ -1127,15 +1184,18 @@
   Pair<Identifier,Identifier> nameComponents = null;
 }
 {
-  <WRITE> <OUTPUT> <TO> nodeName = Identifier() <COLON> fileName = ConstantString()
+  <WRITE> { startToken = token; } <OUTPUT> <TO> nodeName = Identifier() <COLON> fileName = ConstantString()
     ( <USING> writerClass = ConstantString() )?
     {
-      return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
+      WriteStatement stmt = new WriteStatement(new Identifier(nodeName), fileName, writerClass);
+      setSourceLocation(stmt, startToken);
+      return stmt;
     }
 }
 
 LoadStatement LoadStatement() throws ParseException:
 {
+  Token startToken = null;
   Identifier dataverseName = null;
   Identifier datasetName = null;
   boolean alreadySorted = false;
@@ -1144,7 +1204,7 @@
   Pair<Identifier,Identifier> nameComponents = null;
 }
 {
-  <LOAD> Dataset() nameComponents = QualifiedName()
+  <LOAD> { startToken = token; } Dataset() nameComponents = QualifiedName()
     {
       dataverseName = nameComponents.first;
       datasetName = nameComponents.second;
@@ -1156,7 +1216,9 @@
     }
   )?
     {
-      return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
+      LoadStatement stmt = new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
+      setSourceLocation(stmt, startToken);
+      return stmt;
     }
 }
 
@@ -1174,77 +1236,71 @@
 
 Statement CompactStatement() throws ParseException:
 {
+  Token startToken = null;
   Pair<Identifier,Identifier> nameComponents = null;
-  Statement stmt = null;
 }
 {
-  <COMPACT> Dataset() nameComponents = QualifiedName()
+  <COMPACT> { startToken = token; } Dataset() nameComponents = QualifiedName()
     {
-      stmt = new CompactStatement(nameComponents.first, nameComponents.second);
-    }
-    {
+      CompactStatement stmt = new CompactStatement(nameComponents.first, nameComponents.second);
+      setSourceLocation(stmt, startToken);
       return stmt;
     }
 }
 
 Statement ConnectionStatement() throws ParseException:
 {
-  Pair<Identifier,Identifier> feedNameComponents = null;
-  Pair<Identifier,Identifier> datasetNameComponents = null;
-
-  Map<String,String> configuration = null;
+  Token startToken = null;
   Statement stmt = null;
-  String policy = null;
 }
 {
   (
-    <CONNECT> stmt = ConnectStatement()
-  | <DISCONNECT> stmt = DisconnectStatement()
-  | <START> stmt = StartStatement()
-  | <STOP> stmt = StopStatement()
+    <CONNECT> { startToken = token; } stmt = ConnectStatement(startToken)
+  | <DISCONNECT> { startToken = token; } stmt = DisconnectStatement(startToken)
+  | <START> { startToken = token; } stmt = StartStatement(startToken)
+  | <STOP> { startToken = token; } stmt = StopStatement(startToken)
   )
   {
     return stmt;
   }
 }
 
-Statement StartStatement() throws ParseException:
+Statement StartStatement(Token startStmtToken) throws ParseException:
 {
   Pair<Identifier,Identifier> feedNameComponents = null;
 
-  Statement stmt = null;
+  AbstractStatement stmt = null;
 }
 {
   <FEED> feedNameComponents = QualifiedName()
   {
     stmt = new StartFeedStatement (feedNameComponents);
+    setSourceLocation(stmt, startStmtToken);
     return stmt;
   }
 }
 
-Statement StopStatement () throws ParseException:
+AbstractStatement StopStatement(Token startStmtToken) throws ParseException:
 {
   Pair<Identifier,Identifier> feedNameComponents = null;
 
-  Statement stmt = null;
+  AbstractStatement stmt = null;
 }
 {
   <FEED> feedNameComponents = QualifiedName()
   {
     stmt = new StopFeedStatement (feedNameComponents);
+    setSourceLocation(stmt, startStmtToken);
     return stmt;
   }
 }
 
-
-Statement DisconnectStatement() throws ParseException:
+AbstractStatement DisconnectStatement(Token startStmtToken) throws ParseException:
 {
   Pair<Identifier,Identifier> feedNameComponents = null;
   Pair<Identifier,Identifier> datasetNameComponents = null;
 
-  Map<String,String> configuration = null;
-  Statement stmt = null;
-  String policy = null;
+  AbstractStatement stmt = null;
 }
 {
   (
@@ -1254,18 +1310,19 @@
       }
   )
   {
+    setSourceLocation(stmt, startStmtToken);
     return stmt;
   }
 }
 
-Statement ConnectStatement() throws ParseException:
+AbstractStatement ConnectStatement(Token startStmtToken) throws ParseException:
 {
   Pair<Identifier,Identifier> feedNameComponents = null;
   Pair<Identifier,Identifier> datasetNameComponents = null;
 
   Map<String,String> configuration = null;
   List<FunctionSignature> appliedFunctions = new ArrayList<FunctionSignature>();
-  Statement stmt = null;
+  AbstractStatement stmt = null;
   String policy = null;
   String whereClauseBody = null;
   WhereClause whereClause = null;
@@ -1301,6 +1358,7 @@
       }
   )
   {
+    setSourceLocation(stmt, startStmtToken);
     return stmt;
   }
 }
@@ -1368,9 +1426,9 @@
   ( value = ConstantString() | <INTEGER_LITERAL>
     {
       try {
-        value = "" + Long.valueOf(token.image);
+        value = String.valueOf(Long.parseLong(token.image));
       } catch (NumberFormatException nfe) {
-        throw new ParseException("inapproriate value: " + token.image);
+        throw new SqlppParseException(getSourceLocation(token), "inapproriate value: " + token.image);
       }
     }
   )
@@ -1414,6 +1472,7 @@
 
 RecordTypeDefinition RecordTypeDef() throws ParseException:
 {
+  Token startToken = null;
   RecordTypeDefinition recType = new RecordTypeDefinition();
   RecordTypeDefinition.RecordKind recordKind = null;
 }
@@ -1422,15 +1481,18 @@
     | <OPEN> { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
    <LEFTBRACE>
     {
+      startToken = token;
       String hint = getHint(token);
       if (hint != null) {
         String splits[] = hint.split(" +");
         if (splits[0].equals(GEN_FIELDS_HINT)) {
           if (splits.length != 5) {
-            throw new ParseException("Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
+            throw new SqlppParseException(getSourceLocation(getHintToken(token)),
+                "Expecting: /*+ gen-fields <type> <min> <max> <prefix>*/");
           }
           if (!splits[1].equals("int")) {
-            throw new ParseException("The only supported type for gen-fields is int.");
+            throw new SqlppParseException(getSourceLocation(getHintToken(token)),
+                "The only supported type for gen-fields is int.");
           }
           UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
              Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
@@ -1449,6 +1511,7 @@
         recordKind = RecordTypeDefinition.RecordKind.OPEN;
       }
       recType.setRecordKind(recordKind);
+      setSourceLocation(recType, startToken);
       return recType;
    }
 }
@@ -1463,7 +1526,7 @@
   fieldName = Identifier()
     {
       String hint = getHint(token);
-      IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint) : null;
+      IRecordFieldDataGen rfdg = hint != null ? parseFieldDataGen(hint, token.specialToken) : null;
     }
   <COLON> type =  TypeExpr() (<QUES> { nullable = true; } )?
     {
@@ -1476,40 +1539,47 @@
   Pair<Identifier,Identifier> id = null;
 }
 {
- id = QualifiedName()
-   {
-     if (id.first == null && id.second.getValue().equalsIgnoreCase("int")) {
-        id.second.setValue("int64");
-     }
+  id = QualifiedName()
+  {
+    if (id.first == null && id.second.getValue().equalsIgnoreCase("int")) {
+      id.second.setValue("int64");
+    }
 
-     return new TypeReferenceExpression(id);
-   }
+    TypeReferenceExpression typeRef = new TypeReferenceExpression(id);
+    setSourceLocation(typeRef, token);
+    return typeRef;
+  }
 }
 
 OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
 {
+  Token startToken = null;
   TypeExpression type = null;
 }
 {
-  <LEFTBRACKET>
-    ( type =  TypeExpr() )
+  <LEFTBRACKET> { startToken = token; }
+    ( type = TypeExpr() )
   <RIGHTBRACKET>
   {
-    return new OrderedListTypeDefinition(type);
+    OrderedListTypeDefinition typeDef = new OrderedListTypeDefinition(type);
+    setSourceLocation(typeDef, startToken);
+    return typeDef;
   }
 }
 
-
 UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
 {
+  Token startToken = null;
   TypeExpression type = null;
 }
 {
-  <LEFTDBLBRACE>
+  <LEFTDBLBRACE> { startToken = token; }
     ( type =  TypeExpr() )
   <RIGHTDBLBRACE>
   {
-    return new UnorderedListTypeDefinition(type);
+    UnorderedListTypeDefinition typeDef = new UnorderedListTypeDefinition(type);
+    setSourceLocation(typeDef, startToken);
+    return typeDef;
   }
 }
 
@@ -1525,6 +1595,7 @@
   {
     FunctionName result = new FunctionName();
     result.hint = getHint(token);
+    result.sourceLoc = getSourceLocation(token);
   }
   ( <DOT> second = Identifier()
     {
@@ -1614,19 +1685,21 @@
 {
   List<String> exprList = new ArrayList<String>();
   String lit = null;
+  Token litToken = null;
   int source = 0;
 }
 {
   lit = Identifier()
   {
     boolean meetParens = false;
+    litToken = token;
   }
   (
     LOOKAHEAD(1)
     <LEFTPAREN><RIGHTPAREN>
     {
-        if(!lit.toLowerCase().equals("meta")){
-            throw new ParseException("The string before () has to be \"meta\".");
+        if(!lit.equalsIgnoreCase("meta")){
+            throw new SqlppParseException(getSourceLocation(litToken), "The string before () has to be \"meta\".");
         }
         meetParens = true;
         source = 1;
@@ -1659,7 +1732,6 @@
   }
 }
 
-
 String QuotedString() throws ParseException:
 {
 }
@@ -1670,7 +1742,6 @@
     }
 }
 
-
 String StringLiteral() throws ParseException:
 {
 }
@@ -1728,26 +1799,26 @@
 
 FunctionDecl FunctionDeclaration() throws ParseException:
 {
-  FunctionDecl funcDecl;
-  FunctionSignature signature;
+  Token startToken = null;
   String functionName;
   List<VarIdentifier> paramList = new ArrayList<VarIdentifier>();
   Expression funcBody;
   createNewScope();
 }
 {
-  <DECLARE> <FUNCTION>
+  <DECLARE> { startToken = token; } <FUNCTION>
     functionName = Identifier()
     paramList = ParameterList()
   <LEFTBRACE>
     (funcBody = SelectExpression(true) | funcBody = Expression())
   <RIGHTBRACE>
   {
-    signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
+    FunctionSignature signature = new FunctionSignature(defaultDataverse, functionName, paramList.size());
     getCurrentScope().addFunctionDescriptor(signature, false);
-    funcDecl = new FunctionDecl(signature, paramList, funcBody);
+    FunctionDecl stmt = new FunctionDecl(signature, paramList, funcBody);
     removeCurrentScope();
-    return funcDecl;
+    setSourceLocation(stmt, startToken);
+    return stmt;
   }
 }
 
@@ -1775,12 +1846,12 @@
   )
   {
     query.setBody(expr);
+    query.setSourceLocation(expr.getSourceLocation());
     return query;
   }
 }
 
 
-
 Expression Expression():
 {
   Expression expr = null;
@@ -1797,9 +1868,7 @@
     }
 }
 
-
-
-Expression OperatorExpr()throws ParseException:
+Expression OperatorExpr() throws ParseException:
 {
   OperatorExpr op = null;
   Expression operand = null;
@@ -1807,18 +1876,18 @@
 {
     operand = AndExpr()
     (
-
       <OR>
       {
         if (op == null) {
           op = new OperatorExpr();
+          op.setSourceLocation(getSourceLocation(token));
           op.addOperand(operand);
           op.setCurrentop(true);
         }
         try{
             op.addOperator(token.image.toLowerCase());
         } catch (Exception e){
-            throw new ParseException(e.getMessage());
+            throw new SqlppParseException(getSourceLocation(token), e.getMessage());
         }
       }
 
@@ -1834,7 +1903,7 @@
     }
 }
 
-Expression AndExpr()throws ParseException:
+Expression AndExpr() throws ParseException:
 {
   OperatorExpr op = null;
   Expression operand = null;
@@ -1842,18 +1911,18 @@
 {
     operand = NotExpr()
     (
-
       <AND>
       {
         if (op == null) {
           op = new OperatorExpr();
+          op.setSourceLocation(getSourceLocation(token));
           op.addOperand(operand);
           op.setCurrentop(true);
         }
         try{
            op.addOperator(token.image.toLowerCase());
         } catch (CompilationException e){
-           throw new ParseException(e.getMessage());
+           throw new SqlppParseException(getSourceLocation(token), e.getMessage());
         }
     }
 
@@ -1865,28 +1934,31 @@
     )*
 
     {
-      return op==null? operand: op;
+      return op==null ? operand: op;
     }
 }
 
-Expression NotExpr()throws ParseException:
+Expression NotExpr() throws ParseException:
 {
    Expression inputExpr;
    boolean not = false;
+   Token startToken = null;
 }
 {
-  (<NOT> { not = true; } )? inputExpr = RelExpr()
+  (<NOT> { not = true; startToken = token; } )? inputExpr = RelExpr()
   {
-    if(not){
+    if(not) {
         FunctionSignature signature = new FunctionSignature(BuiltinFunctions.NOT);
-        return new CallExpr(signature, new ArrayList<Expression>(Collections.singletonList(inputExpr)));
+        CallExpr callExpr = new CallExpr(signature, new ArrayList<Expression>(Collections.singletonList(inputExpr)));
+        setSourceLocation(callExpr, startToken);
+        return callExpr;
     } else {
         return inputExpr;
     }
   }
 }
 
-Expression RelExpr()throws ParseException:
+Expression RelExpr() throws ParseException:
 {
   boolean not = false;
   OperatorExpr op = null;
@@ -1920,13 +1992,14 @@
           }
           if (op == null) {
             op = new OperatorExpr();
+            op.setSourceLocation(getSourceLocation(token));
             op.addOperand(operand, false); // broadcast is always for the right branch
             op.setCurrentop(true);
           }
           try{
             op.addOperator(operator);
           } catch (CompilationException e){
-            throw new ParseException(e.getMessage());
+            throw new SqlppParseException(getSourceLocation(token), e.getMessage());
           }
         }
 
@@ -1944,8 +2017,7 @@
      }
 }
 
-
-Expression BetweenExpr()throws ParseException:
+Expression BetweenExpr() throws ParseException:
 {
   boolean not = false;
   OperatorExpr op = null;
@@ -1972,13 +2044,14 @@
           }
           if (op == null) {
             op = new OperatorExpr();
+            op.setSourceLocation(getSourceLocation(token));
             op.addOperand(operand);
             op.setCurrentop(true);
           }
           try{
             op.addOperator(operator);
           } catch (CompilationException e){
-            throw new ParseException(e.getMessage());
+            throw new SqlppParseException(getSourceLocation(token), e.getMessage());
           }
         }
 
@@ -1999,13 +2072,14 @@
        if (annotation != null) {
          op.addHint(annotation);
        }
-       return op==null? operand: op;
+       return op==null ? operand: op;
     }
 }
 
 Expression IsExpr() throws ParseException:
 {
-    Expression expr = null;
+    Token notToken = null;
+    CallExpr expr = null;
     Expression operand = null;
     boolean not = false;
     FunctionIdentifier fn = null;
@@ -2013,7 +2087,7 @@
 {
     operand = LikeExpr()
     ( <IS>
-        (<NOT> { not = true; })?
+        (<NOT> { not = true; notToken = token; })?
         (
             <NULL> { fn = BuiltinFunctions.IS_NULL; } |
             <MISSING> { fn = BuiltinFunctions.IS_MISSING; } |
@@ -2023,19 +2097,20 @@
       {
         FunctionSignature signature = new FunctionSignature(fn);
         expr = new CallExpr(signature, new ArrayList<Expression>(Collections.singletonList(operand)));
-        if(not) {
+        expr.setSourceLocation(getSourceLocation(token));
+        if (not) {
            FunctionSignature notSignature = new FunctionSignature(BuiltinFunctions.NOT);
            expr = new CallExpr(notSignature, new ArrayList<Expression>(Collections.singletonList(expr)));
+           expr.setSourceLocation(getSourceLocation(notToken));
         }
       }
     )?
     {
-        return expr = expr==null? operand : expr;
+        return expr == null ? operand : expr;
     }
 }
 
-
-Expression LikeExpr()throws ParseException:
+Expression LikeExpr() throws ParseException:
 {
   boolean not = false;
   OperatorExpr op = null;
@@ -2048,6 +2123,7 @@
         (<NOT> { not = true; })? <LIKE>
         {
           op = new OperatorExpr();
+          op.setSourceLocation(getSourceLocation(token));
           op.addOperand(operand);
           op.setCurrentop(true);
 
@@ -2055,10 +2131,10 @@
           if (not) {
             operator = "not_" + operator;
           }
-          try{
+          try {
             op.addOperator(operator);
           } catch (CompilationException e){
-            throw new ParseException(e.getMessage());
+            throw new SqlppParseException(getSourceLocation(token), e.getMessage());
           }
         }
 
@@ -2073,7 +2149,7 @@
      }
 }
 
-Expression ConcatExpr()throws ParseException:
+Expression ConcatExpr() throws ParseException:
 {
   OperatorExpr op = null;
   Expression operand = null;
@@ -2082,18 +2158,15 @@
     operand = AddExpr()
     (
       LOOKAHEAD(1)
-      (<CONCAT>)
+      <CONCAT>
       {
         if (op == null) {
           op = new OperatorExpr();
+          op.setSourceLocation(getSourceLocation(token));
           op.addOperand(operand);
           op.setCurrentop(true);
         }
-        try{
-            ((OperatorExpr)op).addOperator(token.image);
-        } catch (Exception e){
-            throw new ParseException(e.getMessage());
-        }
+        op.addOperator(OperatorType.CONCAT);
     }
     operand = AddExpr()
     {
@@ -2102,31 +2175,29 @@
     )*
 
     {
-       return op==null? operand: op;
+       return op == null ? operand : op;
     }
 }
 
-Expression AddExpr()throws ParseException:
+Expression AddExpr() throws ParseException:
 {
   OperatorExpr op = null;
+  OperatorType opType = null;
   Expression operand = null;
 }
 {
     operand = MultExpr()
     (
       LOOKAHEAD(1)
-      (<PLUS> | <MINUS>)
+      (<PLUS> { opType = OperatorType.PLUS; } | <MINUS> { opType = OperatorType.MINUS; } )
       {
         if (op == null) {
           op = new OperatorExpr();
-        op.addOperand(operand);
-        op.setCurrentop(true);
+          op.setSourceLocation(getSourceLocation(token));
+          op.addOperand(operand);
+          op.setCurrentop(true);
         }
-        try{
-            ((OperatorExpr)op).addOperator(token.image);
-        } catch (Exception e){
-            throw new ParseException(e.getMessage());
-        }
+        op.addOperator(opType);
     }
 
     operand = MultExpr()
@@ -2136,11 +2207,11 @@
     )*
 
     {
-       return op==null? operand: op;
+       return op == null ? operand : op;
     }
 }
 
-Expression MultExpr()throws ParseException:
+Expression MultExpr() throws ParseException:
 {
   OperatorExpr op = null;
   OperatorType opType = null;
@@ -2158,6 +2229,7 @@
       {
         if (op == null) {
           op = new OperatorExpr();
+          op.setSourceLocation(getSourceLocation(token));
           op.addOperand(operand);
           op.setCurrentop(true);
         }
@@ -2170,11 +2242,11 @@
     )*
 
      {
-       return op==null?operand:op;
+       return op == null ? operand : op;
      }
 }
 
-Expression ExponentExpr()throws ParseException:
+Expression ExponentExpr() throws ParseException:
 {
   OperatorExpr op = null;
   Expression operand = null;
@@ -2185,14 +2257,11 @@
     {
         if (op == null) {
           op = new OperatorExpr();
+          op.setSourceLocation(getSourceLocation(token));
           op.addOperand(operand);
           op.setCurrentop(true);
         }
-        try{
-            op.addOperator(token.image);
-        } catch (Exception e){
-            throw new ParseException(e.getMessage());
-        }
+        op.addOperator(OperatorType.CARET);
     }
     operand = UnaryExpr()
     {
@@ -2200,7 +2269,7 @@
     }
     )?
     {
-       return op==null?operand:op;
+       return op == null ? operand : op;
     }
 }
 
@@ -2214,93 +2283,92 @@
     ( (<PLUS> | <MINUS> | (<NOT> { not = true; } )? <EXISTS> )
     {
         String exprType = token.image.toLowerCase();
-        if(not){
+        if (not) {
            exprType = "not_" + exprType;
         }
         uexpr = new UnaryExpr();
-        try{
+        uexpr.setSourceLocation(getSourceLocation(token));
+        try {
             uexpr.setExprType(exprType);
         } catch (CompilationException e){
-            throw new ParseException(e.getMessage());
+            throw new SqlppParseException(getSourceLocation(token), e.getMessage());
         }
     }
     )?
 
     expr = ValueExpr()
     {
-       if(uexpr==null){
-            return expr;
+       if (uexpr == null) {
+         return expr;
        }
-       uexpr.setExpr(expr);
-       return uexpr;
+       else {
+         uexpr.setExpr(expr);
+         return uexpr;
+       }
     }
 }
 
-Expression ValueExpr()throws ParseException:
+Expression ValueExpr() throws ParseException:
 {
   Expression expr = null;
-  Identifier ident = null;
-  AbstractAccessor fa = null;
-  Expression indexExpr = null;
+  AbstractAccessor accessor = null;
 }
 {
   expr = PrimaryExpr() (
-     ident = Field()
-     {
-      fa = (fa == null ? new FieldAccessor(expr, ident)
-                       : new FieldAccessor(fa, ident));
-     }
-     | indexExpr = Index()
-     {
-      fa = (fa == null ? new IndexAccessor(expr, indexExpr)
-                       : new IndexAccessor(fa, indexExpr));
-     }
-    )*
-    {
-      return fa == null ? expr : fa;
-    }
+     accessor = FieldAccessor(accessor != null ? accessor : expr)
+     | accessor = IndexAccessor(accessor != null ? accessor : expr)
+  )*
+  {
+    return accessor == null ? expr : accessor;
+  }
 }
 
-Identifier Field() throws ParseException:
+FieldAccessor FieldAccessor(Expression inputExpr) throws ParseException:
 {
+  Token startToken = null;
   String ident = null;
 }
 {
-   <DOT> ident = Identifier()
+   <DOT> { startToken = token; } ident = Identifier()
     {
-      return new Identifier(ident);
+      FieldAccessor fa = new FieldAccessor(inputExpr, new Identifier(ident));
+      setSourceLocation(fa, startToken);
+      return fa;
     }
 }
 
-Expression Index() throws ParseException:
+IndexAccessor IndexAccessor(Expression inputExpr) throws ParseException:
 {
-    Expression expr = null;
+  Token startToken = null;
+  Expression expr = null;
 }
 {
-  <LEFTBRACKET> ( expr = Expression()
+  <LEFTBRACKET> { startToken = token; }
+  ( expr = Expression()
     {
-        if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
+        if (expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
         {
             Literal lit = ((LiteralExpr)expr).getValue();
-            if(lit.getLiteralType() != Literal.Type.INTEGER &&
-               lit.getLiteralType() != Literal.Type.LONG) {
-                throw new ParseException("Index should be an INTEGER");
+            if (lit.getLiteralType() != Literal.Type.INTEGER &&
+                lit.getLiteralType() != Literal.Type.LONG) {
+                throw new SqlppParseException(expr.getSourceLocation(), "Index should be an INTEGER");
             }
         }
     }
 
-      | <QUES> // ANY
+  | <QUES> // ANY
 
-      )
+  )
 
-   <RIGHTBRACKET>
-    {
-      return expr;
-    }
+  <RIGHTBRACKET>
+  {
+    IndexAccessor ia = new IndexAccessor(inputExpr, expr);
+    setSourceLocation(ia, startToken);
+    return ia;
+  }
 }
 
-
-Expression PrimaryExpr()throws ParseException:
+Expression PrimaryExpr() throws ParseException:
 {
   Expression expr = null;
 }
@@ -2334,7 +2402,7 @@
         try {
             lit.setValue(new LongIntegerLiteral(Long.valueOf(token.image)));
         } catch (NumberFormatException e) {
-            throw new ParseException("Could not parse numeric literal \"" + token.image +'"');
+            throw new SqlppParseException(getSourceLocation(token), "Could not parse numeric literal \"" + token.image +'"');
         }
     }
   | <FLOAT_LITERAL>
@@ -2342,7 +2410,7 @@
         try {
             lit.setValue(new FloatLiteral(Float.valueOf(token.image)));
         } catch (NumberFormatException e) {
-            throw new ParseException("Could not parse numeric literal \"" + token.image +'"');
+            throw new SqlppParseException(getSourceLocation(token), "Could not parse numeric literal \"" + token.image +'"');
         }
     }
   | <DOUBLE_LITERAL>
@@ -2350,7 +2418,7 @@
         try {
             lit.setValue(new DoubleLiteral(Double.valueOf(token.image)));
         } catch (NumberFormatException e) {
-            throw new ParseException("Could not parse numeric literal \"" + token.image +'"');
+            throw new SqlppParseException(getSourceLocation(token), "Could not parse numeric literal \"" + token.image +'"');
         }
     }
   | <MISSING>
@@ -2371,53 +2439,55 @@
     }
   )
     {
+      setSourceLocation(lit, token);
       return lit;
     }
 }
 
-
 VariableExpr VariableRef() throws ParseException:
 {
-    VariableExpr varExp = new VariableExpr();
     VarIdentifier var = new VarIdentifier();
+    String id = null;
 }
 {
-    { String id = null; }
     (<IDENTIFIER> { id = token.image; } | id = QuotedString())
     {
      id = SqlppVariableUtil.toInternalVariableName(id); // Prefix user-defined variables with "$"
      Identifier ident = lookupSymbol(id);
      if (isInForbiddenScopes(id)) {
-       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.");
+       throw new SqlppParseException(getSourceLocation(token),
+        "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.");
      }
-     if(ident != null) { // exist such ident
+     VariableExpr varExp = new VariableExpr();
+     if (ident != null) { // exist such ident
        varExp.setVar((VarIdentifier)ident);
      } else {
        varExp.setVar(var);
        varExp.setIsNewVar(false);
        var.setValue(id);
      }
+     setSourceLocation(varExp, token);
      return varExp;
     }
 }
 
-
 VariableExpr Variable() throws ParseException:
 {
-    VariableExpr varExp = new VariableExpr();
     VarIdentifier var = new VarIdentifier();
+    String id = null;
 }
 {
-    { String id = null; }
     (<IDENTIFIER> { id = token.image; } | id = QuotedString())
     {
      id = SqlppVariableUtil.toInternalVariableName(id); // prefix user-defined variables with "$".
      Identifier ident = lookupSymbol(id);
+     VariableExpr varExp = new VariableExpr();
      if(ident != null) { // exist such ident
        varExp.setIsNewVar(false);
      }
      varExp.setVar(var);
      var.setValue(id);
+     setSourceLocation(varExp, token);
      return varExp;
     }
 }
@@ -2428,96 +2498,99 @@
 }
 {
     (
-        expr = OrderedListConstructor() | expr = UnorderedListConstructor()
+      expr = OrderedListConstructor() |
+      expr = UnorderedListConstructor()
     )
-
     {
       return expr;
     }
 }
 
-
 ListConstructor OrderedListConstructor() throws ParseException:
 {
-      ListConstructor expr = new ListConstructor();
-      List<Expression> exprList = null;
-      expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
+  Token startToken = null;
+  List<Expression> exprList = null;
 }
 {
-    <LEFTBRACKET> exprList = ExpressionList() <RIGHTBRACKET>
-    {
-      expr.setExprList(exprList);
-      return expr;
-    }
+  <LEFTBRACKET> { startToken = token; }
+  exprList = ExpressionList()
+  <RIGHTBRACKET>
+  {
+    ListConstructor expr = new ListConstructor(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR, exprList);
+    setSourceLocation(expr, startToken);
+    return expr;
+  }
 }
 
 ListConstructor UnorderedListConstructor() throws ParseException:
 {
-      ListConstructor expr = new ListConstructor();
-      List<Expression> exprList = null;
-      expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
+  Token startToken = null;
+  List<Expression> exprList = null;
 }
 {
-    <LEFTDBLBRACE> exprList = ExpressionList() <RIGHTDBLBRACE>
-    {
-      expr.setExprList(exprList);
-      return expr;
-    }
+  <LEFTDBLBRACE> { startToken = token; }
+  exprList = ExpressionList()
+  <RIGHTDBLBRACE>
+  {
+    ListConstructor expr = new ListConstructor(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR, exprList);
+    setSourceLocation(expr, startToken);
+    return expr;
+  }
 }
 
 List<Expression> ExpressionList() throws ParseException:
 {
-      Expression expr = null;
-      List<Expression> list = null;
-      List<Expression> exprList = new ArrayList<Expression>();
+  Expression expr = null;
+  List<Expression> exprList = new ArrayList<Expression>();
 }
 {
-    (
-      expr = Expression()
+  (
+    expr = Expression()
+    {
+      exprList.add(expr);
+    }
+    ( <COMMA> expr = Expression()
       {
         exprList.add(expr);
       }
-      ( <COMMA> expr = Expression()
-        {
-          exprList.add(expr);
-        }
-      )*
-    )?
-    {
-      return exprList;
-    }
+    )*
+  )?
+  {
+    return exprList;
+  }
 }
 
 RecordConstructor RecordConstructor() throws ParseException:
 {
-      RecordConstructor expr = new RecordConstructor();
-      FieldBinding tmp = null;
-      List<FieldBinding> fbList = new ArrayList<FieldBinding>();
+  Token startToken = null;
+  FieldBinding fb = null;
+  List<FieldBinding> fbList = new ArrayList<FieldBinding>();
 }
 {
-    <LEFTBRACE> (tmp = FieldBinding()
-    {
-      fbList.add(tmp);
-    }
-    (<COMMA> tmp = FieldBinding() { fbList.add(tmp);  })*)? <RIGHTBRACE>
-    {
-      expr.setFbList(fbList);
-      return expr;
-    }
+  <LEFTBRACE> { startToken = token; }
+  (
+    fb = FieldBinding() { fbList.add(fb); }
+    (<COMMA> fb = FieldBinding() { fbList.add(fb); })*
+  )?
+  <RIGHTBRACE>
+  {
+    RecordConstructor expr = new RecordConstructor(fbList);
+    setSourceLocation(expr, startToken);
+    return expr;
+  }
 }
 
 FieldBinding FieldBinding() throws ParseException:
 {
-    Expression left, right;
+  Expression left, right;
 }
 {
-    left = Expression() <COLON> right = Expression()
-    {
-      return new FieldBinding(left, right);
-    }
+  left = Expression() <COLON> right = Expression()
+  {
+    return new FieldBinding(left, right);
+  }
 }
 
-
 Expression FunctionCallExpr() throws ParseException:
 {
   CallExpr callExpr;
@@ -2531,16 +2604,16 @@
 }
 {
   funcName = FunctionName()
-    {
-      hint = funcName.hint;
-    }
+  {
+    hint = funcName.hint;
+  }
   <LEFTPAREN> (
     ( <DISTINCT> { distinct = true; } )?
     ( tmp = Expression() | <MUL> { star = true; } )
     {
       if(star){
-        if(!funcName.function.toLowerCase().equals("count")){
-           throw new ParseException("The parameter * can only be used in COUNT().");
+        if(!funcName.function.equalsIgnoreCase("count")){
+           throw new SqlppParseException(getSourceLocation(token), "The parameter * can only be used in COUNT().");
         }
         argList.add(new LiteralExpr(new LongIntegerLiteral(1L)));
       } else {
@@ -2574,6 +2647,7 @@
           callExpr.addHint(SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE);
         }
       }
+      callExpr.setSourceLocation(funcName.sourceLoc);
       return callExpr;
     }
 }
@@ -2594,19 +2668,19 @@
     }
 }
 
-
 Expression CaseExpr() throws ParseException:
 {
-   Expression conditionExpr = new LiteralExpr(TrueLiteral.INSTANCE);
+   Token startToken = null;
+   Expression conditionExpr = null;
    List<Expression> whenExprs = new ArrayList<Expression>();
    List<Expression> thenExprs = new ArrayList<Expression>();
    Expression elseExpr = null;
-
    Expression whenExpr = null;
    Expression thenExpr = null;
 }
 {
-   <CASE> (  conditionExpr = Expression() )?
+   <CASE> { startToken = token; }
+   ( conditionExpr = Expression() )?
    (
      <WHEN> whenExpr = Expression()
      {
@@ -2620,7 +2694,14 @@
    (<ELSE> elseExpr = Expression() )?
    <END>
    {
-     return new CaseExpression(conditionExpr, whenExprs, thenExprs, elseExpr);
+     if (conditionExpr == null) {
+        LiteralExpr litExpr = new LiteralExpr(TrueLiteral.INSTANCE);
+        setSourceLocation(litExpr, startToken);
+        conditionExpr = litExpr;
+     }
+     CaseExpression caseExpr = new CaseExpression(conditionExpr, whenExprs, thenExprs, elseExpr);
+     setSourceLocation(caseExpr, startToken);
+     return caseExpr;
    }
 }
 
@@ -2638,7 +2719,10 @@
     (orderbyClause = OrderbyClause() {})?
     (limitClause = LimitClause() {})?
     {
-      return new SelectExpression(letClauses, selectSetOperation, orderbyClause, limitClause, subquery);
+      SelectExpression selectExpr =
+        new SelectExpression(letClauses, selectSetOperation, orderbyClause, limitClause, subquery);
+      selectExpr.setSourceLocation((!letClauses.isEmpty() ? letClauses.get(0) : selectSetOperation).getSourceLocation());
+      return selectExpr;
     }
 }
 
@@ -2671,7 +2755,9 @@
     }
   )*
   {
-    return new SelectSetOperation(setOperationInputLeft, setOperationRights);
+    SelectSetOperation selectSetOp = new SelectSetOperation(setOperationInputLeft, setOperationRights);
+    selectSetOp.setSourceLocation(selectBlockLeft.getSourceLocation());
+    return selectSetOp;
   }
 }
 
@@ -2695,10 +2781,11 @@
   GroupbyClause groupbyClause = null;
   List<LetClause> gbyLetClauses = null;
   HavingClause havingClause = null;
+  SourceLocation startSrcLoc = null;
 }
 {
   (
-     selectClause = SelectClause()
+     selectClause = SelectClause() { startSrcLoc = selectClause.getSourceLocation(); }
      (
         LOOKAHEAD(1)
         fromClause = FromClause()
@@ -2717,7 +2804,7 @@
         (havingClause = HavingClause())?
      )?
     |
-     fromClause = FromClause()
+     fromClause = FromClause() { startSrcLoc = fromClause.getSourceLocation(); }
      (
         LOOKAHEAD(1)
         fromLetClauses = LetClause()
@@ -2733,65 +2820,85 @@
      selectClause = SelectClause()
   )
   {
-    return new SelectBlock(selectClause, fromClause, fromLetClauses, whereClause, groupbyClause, gbyLetClauses, havingClause);
+    SelectBlock selectBlock = new SelectBlock(selectClause, fromClause, fromLetClauses, whereClause, groupbyClause,
+      gbyLetClauses, havingClause);
+    selectBlock.setSourceLocation(startSrcLoc);
+    return selectBlock;
   }
 }
 
 SelectClause SelectClause() throws ParseException:
 {
+  Token startToken = null;
   SelectRegular selectRegular = null;
   SelectElement selectElement = null;
   boolean distinct = false;
 }
 {
-  <SELECT> (<ALL>|<DISTINCT> {distinct = true; } )?
+  <SELECT> { startToken = token; } (<ALL>|<DISTINCT> { distinct = true; } )?
   (
     selectRegular = SelectRegular()
     |
     selectElement = SelectElement()
   )?
   {
-    if(selectRegular == null && selectElement == null){
+    SourceLocation sourceLoc = getSourceLocation(startToken);
+    if (selectRegular == null && selectElement == null){
         Projection projection = new Projection(null, null, true, false);
+        projection.setSourceLocation(sourceLoc);
         List<Projection> projections = new ArrayList<Projection>();
         projections.add(projection);
         selectRegular = new SelectRegular(projections);
+        selectRegular.setSourceLocation(sourceLoc);
     }
-    return new SelectClause(selectElement, selectRegular, distinct);
+    SelectClause selectClause = new SelectClause(selectElement, selectRegular, distinct);
+    selectClause.setSourceLocation(sourceLoc);
+    return selectClause;
   }
 }
 
 SelectRegular SelectRegular() throws ParseException:
 {
+  SourceLocation startSrcLoc = null;
   List<Projection> projections = new ArrayList<Projection>();
+  Projection projection = null;
 }
 {
-   {
-      Projection projection = null;
-   }
-   projection = Projection() { projections.add(projection); }
-    ( LOOKAHEAD(2) <COMMA>
-       projection = Projection() {projections.add(projection);}
-    )*
+  projection = Projection()
   {
-    return new SelectRegular(projections);
+    projections.add(projection);
+    startSrcLoc = projection.getSourceLocation();
+  }
+  ( LOOKAHEAD(2) <COMMA> projection = Projection()
+    {
+      projections.add(projection);
+    }
+  )*
+  {
+    SelectRegular selectRegular = new SelectRegular(projections);
+    selectRegular.setSourceLocation(startSrcLoc);
+    return selectRegular;
   }
 }
 
 SelectElement SelectElement() throws ParseException:
 {
+  Token startToken = null;
   Expression expr = null;
   String name = null;
 }
 {
-  (<RAW>|<ELEMENT>|<VALUE>) expr = Expression()
+  (<RAW>|<ELEMENT>|<VALUE>) { startToken = token; } expr = Expression()
   {
-    return new SelectElement(expr);
+    SelectElement selectElement = new SelectElement(expr);
+    setSourceLocation(selectElement, startToken);
+    return selectElement;
   }
 }
 
 Projection Projection() throws ParseException :
 {
+  SourceLocation startSrcLoc = null;
   Expression expr = null;
   Identifier identifier = null;
   String name = null;
@@ -2800,8 +2907,8 @@
 }
 {
   (
-    <MUL> {star = true; }
-    | LOOKAHEAD(3) expr = VariableRef() <DOT> <MUL> {varStar = true; }
+    <MUL> { star = true; startSrcLoc = getSourceLocation(token); }
+    | LOOKAHEAD(3) expr = VariableRef() <DOT> <MUL> { varStar = true; }
     | expr = Expression() ((<AS>)? name = Identifier())?
       {
         if (name == null) {
@@ -2813,12 +2920,15 @@
       }
   )
   {
-    return new Projection(expr, name, star, varStar);
+    Projection projection = new Projection(expr, name, star, varStar);
+    projection.setSourceLocation(expr != null ? expr.getSourceLocation() : startSrcLoc);
+    return projection;
   }
 }
 
 FromClause FromClause() throws ParseException :
 {
+  Token startToken = null;
   List<FromTerm> fromTerms = new ArrayList<FromTerm>();
   extendCurrentScope();
 }
@@ -2826,10 +2936,12 @@
   {
     FromTerm fromTerm = null;
   }
-    <FROM> fromTerm = FromTerm() { fromTerms.add(fromTerm); }
+    <FROM> { startToken = token; } fromTerm = FromTerm() { fromTerms.add(fromTerm); }
     (LOOKAHEAD(2) <COMMA> fromTerm = FromTerm() { fromTerms.add(fromTerm); } )*
   {
-    return new FromClause(fromTerms);
+    FromClause fromClause = new FromClause(fromTerms);
+    setSourceLocation(fromClause, startToken);
+    return fromClause;
   }
 }
 
@@ -2856,47 +2968,54 @@
      }
   )*
   {
-    if(leftVar==null){
+    if (leftVar == null) {
         leftVar = ExpressionToVariableUtil.getGeneratedVariable(leftExpr, true);
     }
-    return new FromTerm(leftExpr, leftVar, posVar, correlateClauses);
+    FromTerm fromTerm = new FromTerm(leftExpr, leftVar, posVar, correlateClauses);
+    fromTerm.setSourceLocation(leftExpr.getSourceLocation());
+    return fromTerm;
   }
 }
 
 JoinClause JoinClause(JoinType joinType) throws ParseException :
 {
+    Token startToken = null;
     Expression rightExpr = null;
     VariableExpr rightVar = null;
     VariableExpr posVar = null;
     Expression conditionExpr = null;
 }
 {
-  <JOIN> rightExpr = Expression() ((<AS>)? rightVar = Variable())? (<AT> posVar = Variable())? <ON> conditionExpr = Expression()
+  <JOIN> { startToken = token; } rightExpr = Expression() ((<AS>)? rightVar = Variable())? (<AT> posVar = Variable())? <ON> conditionExpr = Expression()
   {
     if(rightVar==null){
         rightVar = ExpressionToVariableUtil.getGeneratedVariable(rightExpr, true);
     }
-    return new JoinClause(joinType, rightExpr, rightVar, posVar, conditionExpr);
+    JoinClause joinClause = new JoinClause(joinType, rightExpr, rightVar, posVar, conditionExpr);
+    setSourceLocation(joinClause, startToken);
+    return joinClause;
   }
 }
 
 UnnestClause UnnestClause(JoinType joinType) throws ParseException :
 {
+    Token startToken = null;
     Expression rightExpr;
     VariableExpr rightVar;
     VariableExpr posVar = null;
 }
 {
-  (<UNNEST>|<CORRELATE>|<FLATTEN>) rightExpr = Expression() ((<AS>)? rightVar = Variable()) (<AT> posVar = Variable())?
+  (<UNNEST>|<CORRELATE>|<FLATTEN>) { startToken = token; } rightExpr = Expression() ((<AS>)? rightVar = Variable()) (<AT> posVar = Variable())?
   {
-    if(rightVar==null){
-        rightVar = ExpressionToVariableUtil.getGeneratedVariable(rightExpr, true);
+    if (rightVar == null) {
+      rightVar = ExpressionToVariableUtil.getGeneratedVariable(rightExpr, true);
     }
-    return new UnnestClause(joinType, rightExpr, rightVar, posVar);
+    UnnestClause unnestClause = new UnnestClause(joinType, rightExpr, rightVar, posVar);
+    setSourceLocation(unnestClause, startToken);
+    return unnestClause;
   }
 }
 
-
 JoinType JoinType() throws ParseException :
 {
    JoinType joinType = JoinType.INNER;
@@ -2924,30 +3043,33 @@
     }
 }
 
-WhereClause WhereClause()throws ParseException :
+WhereClause WhereClause() throws ParseException :
 {
-  WhereClause wc = new WhereClause();
+  Token startToken = null;
   Expression whereExpr;
 }
 {
-    <WHERE> whereExpr = Expression()
+    <WHERE> { startToken = token; } whereExpr = Expression()
     {
-      wc.setWhereExpr(whereExpr);
+      WhereClause wc = new WhereClause(whereExpr);
+      setSourceLocation(wc, startToken);
       return wc;
     }
 }
 
-OrderbyClause OrderbyClause()throws ParseException :
+OrderbyClause OrderbyClause() throws ParseException :
 {
+    Token startToken = null;
     OrderbyClause oc = new OrderbyClause();
     Expression orderbyExpr;
     List<Expression> orderbyList = new ArrayList<Expression>();
-    List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier >();
+    List<OrderbyClause.OrderModifier> modifierList = new ArrayList<OrderbyClause.OrderModifier>();
     int numOfOrderby = 0;
 }
 {
     <ORDER>
       {
+        startToken = token;
         String hint = getHint(token);
         if (hint != null) {
           if (hint.startsWith(INMEMORY_HINT)) {
@@ -2985,12 +3107,14 @@
     {
       oc.setModifierList(modifierList);
       oc.setOrderbyList(orderbyList);
+      setSourceLocation(oc, startToken);
       return oc;
     }
 }
 
 GroupbyClause GroupbyClause()throws ParseException :
 {
+    Token startToken = null;
     GroupbyClause gbc = new GroupbyClause();
     List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
     VariableExpr var = null;
@@ -3008,6 +3132,7 @@
       }
     <GROUP>
       {
+         startToken = token;
          String hint = getHint(token);
          if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
            gbc.setHashGroupByHint(true);
@@ -3068,6 +3193,7 @@
       gbc.setWithVarMap(new HashMap<Expression, VariableExpr>());
       gbc.setGroupVar(groupVar);
       gbc.setGroupFieldList(groupFieldList);
+      setSourceLocation(gbc, startToken);
       replaceCurrentScope(newScope);
       return gbc;
     }
@@ -3075,26 +3201,31 @@
 
 HavingClause HavingClause() throws ParseException:
 {
+   Token startToken = null;
    Expression filterExpr = null;
 }
 {
-    <HAVING> filterExpr = Expression()
+    <HAVING> { startToken = token; } filterExpr = Expression()
     {
-       return new HavingClause(filterExpr);
+       HavingClause havingClause = new HavingClause(filterExpr);
+       setSourceLocation(havingClause, startToken);
+       return havingClause;
     }
 }
 
 LimitClause LimitClause() throws ParseException:
 {
+    Token startToken = null;
     LimitClause lc = new LimitClause();
     Expression expr;
     pushForbiddenScope(getCurrentScope());
 }
 {
-    <LIMIT> expr = Expression()    { lc.setLimitExpr(expr);    }
-    (<OFFSET> expr = Expression() { lc.setOffset(expr);    })?
+    <LIMIT> { startToken = token; } expr = Expression() { lc.setLimitExpr(expr); }
+    (<OFFSET> expr = Expression() { lc.setOffset(expr); })?
 
   {
+    setSourceLocation(lc, startToken);
     popForbiddenScope();
     return lc;
   }
@@ -3102,6 +3233,7 @@
 
 QuantifiedExpression QuantifiedExpression()throws ParseException:
 {
+  Token startToken = null;
   QuantifiedExpression qc = new QuantifiedExpression();
   List<QuantifiedPair> quantifiedList = new ArrayList<QuantifiedPair>();
   Expression satisfiesExpr;
@@ -3114,8 +3246,8 @@
     createNewScope();
   }
 
-   (      ((<ANY>|<SOME>)  {  qc.setQuantifier(QuantifiedExpression.Quantifier.SOME);    })
-        | (<EVERY> {  qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY);    }))
+   ( ((<ANY>|<SOME>) { startToken = token; qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
+     | (<EVERY> {  startToken = token; qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
     var = Variable() <IN> inExpr = Expression()
     {
       pair = new QuantifiedPair(var, inExpr);
@@ -3132,6 +3264,7 @@
      {
        qc.setSatisfiesExpr(satisfiesExpr);
        qc.setQuantifiedList(quantifiedList);
+       setSourceLocation(qc, startToken);
        removeCurrentScope();
        return qc;
      }
@@ -3139,7 +3272,6 @@
 
 LetClause LetElement() throws ParseException:
 {
-    LetClause lc = new LetClause();
     VariableExpr varExp;
     Expression beExp;
     extendCurrentScope();
@@ -3147,15 +3279,14 @@
 {
     varExp = Variable() <EQ> beExp = Expression()
     {
-      lc.setVarExpr(varExp);
-      lc.setBindingExpr(beExp);
+      LetClause lc = new LetClause(varExp, beExp);
+      lc.setSourceLocation(varExp.getSourceLocation());
       return lc;
     }
 }
 
 LetClause WithElement() throws ParseException:
 {
-    LetClause lc = new LetClause();
     VariableExpr varExp;
     Expression beExp;
     extendCurrentScope();
@@ -3163,8 +3294,8 @@
 {
     varExp = Variable() <AS> beExp = Expression()
     {
-      lc.setVarExpr(varExp);
-      lc.setBindingExpr(beExp);
+      LetClause lc = new LetClause(varExp, beExp);
+      lc.setSourceLocation(varExp.getSourceLocation());
       return lc;
     }
 }
