You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by de...@apache.org on 2017/08/24 23:41:14 UTC

[1/3] systemml git commit: [SYSTEMML-1858] Allow parsed text in validation errors

Repository: systemml
Updated Branches:
  refs/heads/master f1d35b780 -> c495533b6


http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/Statement.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/Statement.java b/src/main/java/org/apache/sysml/parser/Statement.java
index 744117d..0b3aac2 100644
--- a/src/main/java/org/apache/sysml/parser/Statement.java
+++ b/src/main/java/org/apache/sysml/parser/Statement.java
@@ -19,10 +19,12 @@
 
 package org.apache.sysml.parser;
 
+import org.antlr.v4.runtime.ParserRuleContext;
+import org.antlr.v4.runtime.misc.Interval;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-public abstract class Statement 
+public abstract class Statement implements ParseInfo
 {
 
 	
@@ -87,19 +89,57 @@ public abstract class Statement
 	private String _filename;
 	private int _beginLine, _beginColumn;
 	private int _endLine,   _endColumn;
+	private String _text;
 	
 	public void setFilename(String passed)  { _filename = passed;	}
 	public void setBeginLine(int passed)    { _beginLine = passed;	}
 	public void setBeginColumn(int passed) 	{ _beginColumn = passed;}
 	public void setEndLine(int passed) 		{ _endLine = passed;   }
 	public void setEndColumn(int passed)	{ _endColumn = passed; }
-	
-	public void setAllPositions(String filename, int blp, int bcp, int elp, int ecp){
-		_filename    = filename;
-		_beginLine	 = blp; 
-		_beginColumn = bcp; 
-		_endLine 	 = elp;
-		_endColumn 	 = ecp;
+
+	/**
+	 * Set ParserRuleContext values (begin line, begin column, end line, end
+	 * column, and text).
+	 *
+	 * @param ctx
+	 *            the antlr ParserRuleContext
+	 */
+	public void setCtxValues(ParserRuleContext ctx) {
+		setBeginLine(ctx.start.getLine());
+		setBeginColumn(ctx.start.getCharPositionInLine());
+		setEndLine(ctx.stop.getLine());
+		setEndColumn(ctx.stop.getCharPositionInLine());
+		// preserve whitespace if possible
+		if ((ctx.start != null) && (ctx.stop != null) && (ctx.start.getStartIndex() != -1)
+				&& (ctx.stop.getStopIndex() != -1) && (ctx.start.getStartIndex() <= ctx.stop.getStopIndex())
+				&& (ctx.start.getInputStream() != null)) {
+			String text = ctx.start.getInputStream()
+					.getText(Interval.of(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
+			if (text != null) {
+				text = text.trim();
+			}
+			setText(text);
+		} else {
+			String text = ctx.getText();
+			if (text != null) {
+				text = text.trim();
+			}
+			setText(text);
+		}
+	}
+
+	/**
+	 * Set ParserRuleContext values (begin line, begin column, end line, end
+	 * column, and text) and file name.
+	 *
+	 * @param ctx
+	 *            the antlr ParserRuleContext
+	 * @param filename
+	 *            the filename (if it exists)
+	 */
+	public void setCtxValuesAndFilename(ParserRuleContext ctx, String filename) {
+		setCtxValues(ctx);
+		setFilename(filename);
 	}
 
 	public int getBeginLine()	{ return _beginLine;   }
@@ -107,37 +147,77 @@ public abstract class Statement
 	public int getEndLine() 	{ return _endLine;   }
 	public int getEndColumn()	{ return _endColumn; }
 	public String getFilename() { return _filename;  }
-		
-	public String printErrorLocation(){
-		return "ERROR: " + _filename + " -- line " + _beginLine + ", column " + _beginColumn + " -- ";
+
+	public String printErrorLocation() {
+		String file = _filename;
+		if (file == null) {
+			file = "";
+		} else {
+			file = file + " ";
+		}
+		if (getText() != null) {
+			return "ERROR: " + file + "[line " + _beginLine + ":" + _beginColumn + "] -> " + getText() + " -- ";
+		} else {
+			return "ERROR: " + file + "[line " + _beginLine + ":" + _beginColumn + "] -- ";
+		}
 	}
-	
-	public String printWarningLocation(){
-		return "WARNING: " + _filename + " -- line " + _beginLine + ", column " + _beginColumn + " -- ";
+
+	public String printWarningLocation() {
+		String file = _filename;
+		if (file == null) {
+			file = "";
+		} else {
+			file = file + " ";
+		}
+		if (getText() != null) {
+			return "WARNING: " + file + "[line " + _beginLine + ":" + _beginColumn + "] -> " + getText() + " -- ";
+		} else {
+			return "WARNING: " + file + "[line " + _beginLine + ":" + _beginColumn + "] -- ";
+		}
 	}
 
-	public void raiseValidateError( String msg, boolean conditional ) throws LanguageException {
+	public void raiseValidateError(String msg, boolean conditional) throws LanguageException {
 		raiseValidateError(msg, conditional, null);
 	}
-	
-	public void raiseValidateError( String msg, boolean conditional, String errorCode ) 
-		throws LanguageException
-	{
-		if( conditional )  //warning if conditional
-		{
+
+	public void raiseValidateError(String msg, boolean conditional, String errorCode) throws LanguageException {
+		if (conditional) {// warning if conditional
 			String fullMsg = this.printWarningLocation() + msg;
-			
-			LOG.warn( fullMsg );
-		}
-		else  //error and exception if unconditional
-		{
+			LOG.warn(fullMsg);
+		} else {// error and exception if unconditional
 			String fullMsg = this.printErrorLocation() + msg;
-			
-			//LOG.error( fullMsg ); //no redundant error	
-			if( errorCode != null )
-				throw new LanguageException( fullMsg, errorCode );
-			else 
-				throw new LanguageException( fullMsg );
+			if (errorCode != null)
+				throw new LanguageException(fullMsg, errorCode);
+			else
+				throw new LanguageException(fullMsg);
 		}
-	}	
+	}
+
+	public String getText() {
+		return _text;
+	}
+
+	public void setText(String text) {
+		this._text = text;
+	}
+
+	/**
+	 * Set parse information.
+	 *
+	 * @param parseInfo
+	 *            parse information, such as beginning line position, beginning
+	 *            column position, ending line position, ending column position,
+	 *            text, and filename
+	 * @param filename
+	 *            the DML/PYDML filename (if it exists)
+	 */
+	public void setParseInfo(ParseInfo parseInfo) {
+		_beginLine = parseInfo.getBeginLine();
+		_beginColumn = parseInfo.getBeginColumn();
+		_endLine = parseInfo.getEndLine();
+		_endColumn = parseInfo.getEndColumn();
+		_text = parseInfo.getText();
+		_filename = parseInfo.getFilename();
+	}
+
 }

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/StatementBlock.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/StatementBlock.java b/src/main/java/org/apache/sysml/parser/StatementBlock.java
index d5cf1d7..768f6c0 100644
--- a/src/main/java/org/apache/sysml/parser/StatementBlock.java
+++ b/src/main/java/org/apache/sysml/parser/StatementBlock.java
@@ -41,7 +41,7 @@ import org.apache.sysml.runtime.controlprogram.parfor.util.IDSequence;
 import org.apache.sysml.utils.MLContextProxy;
 
 
-public class StatementBlock extends LiveVariableAnalysis
+public class StatementBlock extends LiveVariableAnalysis implements ParseInfo
 {
 
 	protected static final Log LOG = LogFactory.getLog(StatementBlock.class.getName());
@@ -188,14 +188,21 @@ public class StatementBlock extends LiveVariableAnalysis
 				|| (sourceExpr instanceof ParameterizedBuiltinFunctionExpression && ((ParameterizedBuiltinFunctionExpression)sourceExpr).multipleReturns()))
 				return false;
 
-			//function calls (only mergable if inlined dml-bodied function)
-			if (sourceExpr instanceof FunctionCallIdentifier){
+			// function calls (only mergable if inlined dml-bodied function)
+			if (sourceExpr instanceof FunctionCallIdentifier) {
 				FunctionCallIdentifier fcall = (FunctionCallIdentifier) sourceExpr;
-				FunctionStatementBlock fblock = dmlProg.getFunctionStatementBlock(fcall.getNamespace(), fcall.getName());
-				if (fblock == null){
-					throw new LanguageException(sourceExpr.printErrorLocation() + "function " + fcall.getName() + " is undefined in namespace " + fcall.getNamespace());
+				FunctionStatementBlock fblock = dmlProg.getFunctionStatementBlock(fcall.getNamespace(),
+						fcall.getName());
+				if (fblock == null) {
+					if (DMLProgram.DEFAULT_NAMESPACE.equals(fcall.getNamespace())) {
+						throw new LanguageException(
+								sourceExpr.printErrorLocation() + "Function " + fcall.getName() + "() is undefined.");
+					} else {
+						throw new LanguageException(sourceExpr.printErrorLocation() + "Function " + fcall.getName()
+								+ "() is undefined in namespace '" + fcall.getNamespace() + "'.");
+					}
 				}
-				if( !rIsInlineableFunction(fblock, dmlProg) )
+				if (!rIsInlineableFunction(fblock, dmlProg))
 					return false;
 			}
 		}
@@ -445,15 +452,15 @@ public class StatementBlock extends LiveVariableAnalysis
 
 					//auto casting of inputs on inlining (if required)
 					ValueType targetVT = newTarget.getValueType();
-					if( newTarget.getDataType()==DataType.SCALAR && currCallParam.getOutput() != null
-						&& targetVT != currCallParam.getOutput().getValueType() && targetVT != ValueType.STRING )
-					{
-						currCallParam = new BuiltinFunctionExpression(BuiltinFunctionExpression.getValueTypeCastOperator(targetVT), new Expression[] {currCallParam},
-												newTarget.getFilename(), newTarget.getBeginLine(), newTarget.getBeginColumn(), newTarget.getEndLine(), newTarget.getEndColumn());
+					if (newTarget.getDataType() == DataType.SCALAR && currCallParam.getOutput() != null
+							&& targetVT != currCallParam.getOutput().getValueType() && targetVT != ValueType.STRING) {
+						currCallParam = new BuiltinFunctionExpression(
+								BuiltinFunctionExpression.getValueTypeCastOperator(targetVT),
+								new Expression[] { currCallParam }, newTarget);
 					}
 
 					// create the assignment statement to bind the call parameter to formal parameter
-					AssignmentStatement binding = new AssignmentStatement(newTarget, currCallParam, newTarget.getBeginLine(), newTarget.getBeginColumn(), newTarget.getEndLine(), newTarget.getEndColumn());
+					AssignmentStatement binding = new AssignmentStatement(newTarget, currCallParam, newTarget);
 					newStatements.add(binding);
 				}
 
@@ -512,13 +519,14 @@ public class StatementBlock extends LiveVariableAnalysis
 
 					//auto casting of inputs on inlining (always, redundant cast removed during Hop Rewrites)
 					ValueType sourceVT = newSource.getValueType();
-					if( newSource.getDataType()==DataType.SCALAR && sourceVT != ValueType.STRING ){
-						newSource = new BuiltinFunctionExpression(BuiltinFunctionExpression.getValueTypeCastOperator(sourceVT), new Expression[] {newSource},
-								newTarget.getFilename(), newTarget.getBeginLine(), newTarget.getBeginColumn(), newTarget.getEndLine(), newTarget.getEndColumn());
+					if (newSource.getDataType() == DataType.SCALAR && sourceVT != ValueType.STRING) {
+						newSource = new BuiltinFunctionExpression(
+								BuiltinFunctionExpression.getValueTypeCastOperator(sourceVT),
+								new Expression[] { newSource }, newTarget);
 					}
 
 					// create the assignment statement to bind the call parameter to formal parameter
-					AssignmentStatement binding = new AssignmentStatement(newTarget, newSource, newTarget.getBeginLine(), newTarget.getBeginColumn(), newTarget.getEndLine(), newTarget.getEndColumn());
+					AssignmentStatement binding = new AssignmentStatement(newTarget, newSource, newTarget);
 
 					newStatements.add(binding);
 				}
@@ -618,12 +626,12 @@ public class StatementBlock extends LiveVariableAnalysis
 							bife.raiseValidateError("Undefined Variable (" + id.getName() + ") used in statement", false, LanguageErrorCodes.INVALID_PARAMETERS);
 						}
 						IntIdentifier intid = null;
-						if (bife.getOpCode() == Expression.BuiltinFunctionOp.NROW){
-							intid = new IntIdentifier((currVal instanceof IndexedIdentifier)?((IndexedIdentifier)currVal).getOrigDim1():currVal.getDim1(),
-									bife.getFilename(), bife.getBeginLine(), bife.getBeginColumn(), bife.getEndLine(), bife.getEndColumn());
+						if (bife.getOpCode() == Expression.BuiltinFunctionOp.NROW) {
+							intid = new IntIdentifier((currVal instanceof IndexedIdentifier)
+									? ((IndexedIdentifier) currVal).getOrigDim1() : currVal.getDim1(), bife);
 						} else {
-							intid = new IntIdentifier((currVal instanceof IndexedIdentifier)?((IndexedIdentifier)currVal).getOrigDim2():currVal.getDim2(),
-									bife.getFilename(), bife.getBeginLine(), bife.getBeginColumn(), bife.getEndLine(), bife.getEndColumn());
+							intid = new IntIdentifier((currVal instanceof IndexedIdentifier)
+									? ((IndexedIdentifier) currVal).getOrigDim2() : currVal.getDim2(), bife);
 						}
 
 						// handle case when nrow / ncol called on variable with size unknown (dims == -1)
@@ -766,10 +774,13 @@ public class StatementBlock extends LiveVariableAnalysis
 				for (Expression expression : expressions) {
 					expression.validateExpression(ids.getVariables(), currConstVars, conditional);
 					if (expression.getOutput().getDataType() != Expression.DataType.SCALAR) {
-						raiseValidateError("print statement can only print scalars", conditional);
+						if (expression.getOutput().getDataType() == Expression.DataType.MATRIX) {
+							pstmt.raiseValidateError("Print statements can only print scalars. To print a matrix, please wrap it in a toString() function.", conditional);
+						} else {
+							pstmt.raiseValidateError("Print statements can only print scalars.", conditional);
+						}
 					}
 				}
-
 			}
 
 			// no work to perform for PathStatement or ImportStatement
@@ -813,10 +824,8 @@ public class StatementBlock extends LiveVariableAnalysis
 			}
 		}
 		//case of unspecified format parameter, use default
-		else
-		{
-			s.addExprParam(DataExpression.FORMAT_TYPE, new StringIdentifier(FormatType.TEXT.toString(),
-					s.getFilename(), s.getBeginLine(), s.getBeginColumn(), s.getEndLine(), s.getEndColumn()), true);
+		else {
+			s.addExprParam(DataExpression.FORMAT_TYPE, new StringIdentifier(FormatType.TEXT.toString(), s), true);
 			s.getIdentifier().setFormatType(FormatType.TEXT);
 		}
 	}
@@ -850,8 +859,8 @@ public class StatementBlock extends LiveVariableAnalysis
 						+ " can only be a string with one of following values: binary, text, mm, csv", conditionalValidate, LanguageErrorCodes.INVALID_PARAMETERS);
 			}
 		} else {
-			dataExpr.addVarParam(DataExpression.FORMAT_TYPE, new StringIdentifier(FormatType.TEXT.toString(),
-					dataExpr.getFilename(), dataExpr.getBeginLine(), dataExpr.getBeginColumn(), dataExpr.getEndLine(), dataExpr.getEndColumn()));
+			dataExpr.addVarParam(DataExpression.FORMAT_TYPE,
+					new StringIdentifier(FormatType.TEXT.toString(), dataExpr));
 			s.getTarget().setFormatType(FormatType.TEXT);
 		}
 	}
@@ -1001,19 +1010,32 @@ public class StatementBlock extends LiveVariableAnalysis
 	private String _filename = "MAIN SCRIPT";
 	private int _beginLine = 0, _beginColumn = 0;
 	private int _endLine = 0, _endColumn = 0;
+	private String _text;
 
 	public void setFilename (String fname)  { _filename = fname;	}
 	public void setBeginLine(int passed)    { _beginLine = passed;  }
 	public void setBeginColumn(int passed) 	{ _beginColumn = passed; }
 	public void setEndLine(int passed) 		{ _endLine = passed;   }
 	public void setEndColumn(int passed)	{ _endColumn = passed; }
+	public void setText(String text) { _text = text; }
 
-	public void setAllPositions(String fname, int blp, int bcp, int elp, int ecp){
-		_filename    = fname;
-		_beginLine	 = blp;
-		_beginColumn = bcp;
-		_endLine 	 = elp;
-		_endColumn 	 = ecp;
+	/**
+	 * Set parse information.
+	 *
+	 * @param parseInfo
+	 *            parse information, such as beginning line position, beginning
+	 *            column position, ending line position, ending column position,
+	 *            text, and filename
+	 * @param filename
+	 *            the DML/PYDML filename (if it exists)
+	 */
+	public void setParseInfo(ParseInfo parseInfo) {
+		_beginLine = parseInfo.getBeginLine();
+		_beginColumn = parseInfo.getBeginColumn();
+		_endLine = parseInfo.getEndLine();
+		_endColumn = parseInfo.getEndColumn();
+		_text = parseInfo.getText();
+		_filename = parseInfo.getFilename();
 	}
 
 	public String getFilename() { return _filename;	   }
@@ -1021,6 +1043,7 @@ public class StatementBlock extends LiveVariableAnalysis
 	public int getBeginColumn() { return _beginColumn; }
 	public int getEndLine() 	{ return _endLine;   }
 	public int getEndColumn()	{ return _endColumn; }
+	public String getText() { return _text; }
 
 	public String printErrorLocation(){
 		return "ERROR: " + _filename + " -- line " + _beginLine + ", column " + _beginColumn + " -- ";

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/StringIdentifier.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/StringIdentifier.java b/src/main/java/org/apache/sysml/parser/StringIdentifier.java
index 6b8ba1e..ed0c1d6 100644
--- a/src/main/java/org/apache/sysml/parser/StringIdentifier.java
+++ b/src/main/java/org/apache/sysml/parser/StringIdentifier.java
@@ -19,24 +19,34 @@
 
 package org.apache.sysml.parser;
 
-
+import org.antlr.v4.runtime.ParserRuleContext;
 
 public class StringIdentifier extends ConstIdentifier 
 {
 	
 	private String _val;
-	
-	public Expression rewriteExpression(String prefix) throws LanguageException{
+
+	public Expression rewriteExpression(String prefix) throws LanguageException {
 		return this;
 	}
-	
-	public StringIdentifier(String val, String filename, int blp, int bcp, int elp, int ecp){
+
+	public StringIdentifier(String val, ParseInfo parseInfo) {
 		super();
-		 _val = val;
-		setDimensions(0,0);
-        computeDataType();
-        setValueType(ValueType.STRING);
-        setAllPositions(filename, blp, bcp, elp, ecp);
+		setInfo(val);
+		setParseInfo(parseInfo);
+	}
+
+	public StringIdentifier(ParserRuleContext ctx, String val, String filename) {
+		super();
+		setInfo(val);
+		setCtxValuesAndFilename(ctx, filename);
+	}
+
+	private void setInfo(String val) {
+		_val = val;
+		setDimensions(0, 0);
+		computeDataType();
+		setValueType(ValueType.STRING);
 	}
 
 	public String getValue(){

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java b/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java
index 3a7a347..bab9cd0 100644
--- a/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java
+++ b/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java
@@ -160,27 +160,11 @@ public abstract class CommonSyntacticValidator {
 	}
 
 	protected void setFileLineColumn(Expression expr, ParserRuleContext ctx) {
-		String txt = ctx.getText();
-		expr.setFilename(currentFile);
-		expr.setBeginLine(ctx.start.getLine());
-		expr.setBeginColumn(ctx.start.getCharPositionInLine());
-		expr.setEndLine(ctx.stop.getLine());
-		expr.setEndColumn(ctx.stop.getCharPositionInLine());
-		if(expr.getBeginColumn() == expr.getEndColumn() && expr.getBeginLine() == expr.getEndLine() && txt.length() > 1) {
-			expr.setEndColumn(expr.getBeginColumn() + txt.length() - 1);
-		}
+		expr.setCtxValuesAndFilename(ctx, currentFile);
 	}
 
 	protected void setFileLineColumn(Statement stmt, ParserRuleContext ctx) {
-		String txt = ctx.getText();
-		stmt.setFilename(currentFile);
-		stmt.setBeginLine(ctx.start.getLine());
-		stmt.setBeginColumn(ctx.start.getCharPositionInLine());
-		stmt.setEndLine(ctx.stop.getLine());
-		stmt.setEndColumn(ctx.stop.getCharPositionInLine());
-		if(stmt.getBeginColumn() == stmt.getEndColumn() && stmt.getBeginLine() == stmt.getEndLine() && txt.length() > 1) {
-			stmt.setEndColumn(stmt.getBeginColumn() + txt.length() - 1);
-		}
+		stmt.setCtxValuesAndFilename(ctx, currentFile);
 	}
 
 	// For String literal "True/TRUE"
@@ -234,11 +218,6 @@ public abstract class CommonSyntacticValidator {
 
 	protected void unaryExpressionHelper(ParserRuleContext ctx, ExpressionInfo left, ExpressionInfo me, String op) {
 		if(left.expr != null) {
-			Token start = ctx.start;
-			String fileName = currentFile;
-			int line = start.getLine();
-			int col = start.getCharPositionInLine();
-
 			if(left.expr instanceof IntIdentifier) {
 				if(op.equals("-")) {
 					((IntIdentifier) left.expr).multiplyByMinusOne();
@@ -252,9 +231,9 @@ public abstract class CommonSyntacticValidator {
 				me.expr = left.expr;
 			}
 			else {
-				Expression right = new IntIdentifier(1, fileName, line, col, line, col);
+				Expression right = new IntIdentifier(ctx, 1, currentFile);
 				if(op.equals("-")) {
-					right = new IntIdentifier(-1, fileName, line, col, line, col);
+					right = new IntIdentifier(ctx, -1, currentFile);
 				}
 
 				Expression.BinaryOp bop = Expression.getBinaryOp("*");
@@ -281,12 +260,8 @@ public abstract class CommonSyntacticValidator {
 
 	protected void constDoubleIdExpressionHelper(ParserRuleContext ctx, ExpressionInfo me) {
 		try {
-			Token start = ctx.start;
 			double val = Double.parseDouble(ctx.getText());
-			int linePosition = start.getLine();
-			int charPosition = start.getCharPositionInLine();
-			me.expr = new DoubleIdentifier(val, currentFile, linePosition, charPosition, linePosition, charPosition);
-			setFileLineColumn(me.expr, ctx);
+			me.expr = new DoubleIdentifier(ctx, val, currentFile);
 		}
 		catch(Exception e) {
 			notifyErrorListeners("cannot parse the float value: \'" +  ctx.getText() + "\'", ctx.getStart());
@@ -296,12 +271,8 @@ public abstract class CommonSyntacticValidator {
 
 	protected void constIntIdExpressionHelper(ParserRuleContext ctx, ExpressionInfo me) {
 		try {
-			Token start = ctx.start;
 			long val = Long.parseLong(ctx.getText());
-			int linePosition = start.getLine();
-			int charPosition = start.getCharPositionInLine();
-			me.expr = new IntIdentifier(val, currentFile, linePosition, charPosition, linePosition, charPosition);
-			setFileLineColumn(me.expr, ctx);
+			me.expr = new IntIdentifier(ctx, val, currentFile);
 		}
 		catch(Exception e) {
 			notifyErrorListeners("cannot parse the int value: \'" +  ctx.getText() + "\'", ctx.getStart());
@@ -348,16 +319,11 @@ public abstract class CommonSyntacticValidator {
 			return;
 		}
 
-		int linePosition = ctx.start.getLine();
-		int charPosition = ctx.start.getCharPositionInLine();
-		me.expr = new StringIdentifier(val, currentFile, linePosition, charPosition, linePosition, charPosition);
-		setFileLineColumn(me.expr, ctx);
+		me.expr = new StringIdentifier(ctx, val, currentFile);
 	}
 
 	protected void booleanIdentifierHelper(ParserRuleContext ctx, boolean val, ExpressionInfo info) {
-		int linePosition = ctx.start.getLine();
-		int charPosition = ctx.start.getCharPositionInLine();
-		info.expr = new BooleanIdentifier(val, currentFile, linePosition, charPosition, linePosition, charPosition);
+		info.expr = new BooleanIdentifier(ctx, val, currentFile);
 		setFileLineColumn(info.expr, ctx);
 	}
 
@@ -367,32 +333,25 @@ public abstract class CommonSyntacticValidator {
 		// error occurs, then dataInfo.expr is null which would cause a null pointer exception with the following code.
 		// Therefore, check for null so that parsing can continue so all parsing issues can be determined.
 		if (me.expr != null) {
-			int line = ctx.start.getLine();
-			int col = ctx.start.getCharPositionInLine();
-			me.expr.setAllPositions(currentFile, line, col, line, col);
-			setFileLineColumn(me.expr, ctx);
+			me.expr.setCtxValuesAndFilename(ctx, currentFile);
 		}
 	}
 
-	protected ConstIdentifier getConstIdFromString(String varValue, Token start) {
-
-		int linePosition = start.getLine();
-		int charPosition = start.getCharPositionInLine();
-
+	protected ConstIdentifier getConstIdFromString(ParserRuleContext ctx, String varValue) {
 		// Compare to "True/TRUE"
 		if(varValue.equals(trueStringLiteral()))
-			return new BooleanIdentifier(true, currentFile, linePosition, charPosition, linePosition, charPosition);
+			return new BooleanIdentifier(ctx, true, currentFile);
 
 		// Compare to "False/FALSE"
 		if(varValue.equals(falseStringLiteral()))
-			return new BooleanIdentifier(false, currentFile, linePosition, charPosition, linePosition, charPosition);
+			return new BooleanIdentifier(ctx, false, currentFile);
 
 		// Check for long literal
 		// NOTE: we use exception handling instead of Longs.tryParse for backwards compatibility with guava <14.1
 		// Also the alternative of Ints.tryParse and falling back to double would not be lossless in all cases. 
 		try {
 			long lval = Long.parseLong(varValue);
-			return new IntIdentifier(lval, currentFile, linePosition, charPosition, linePosition, charPosition);
+			return new IntIdentifier(ctx, lval, currentFile);
 		}
 		catch(Exception ex) {
 			//continue
@@ -402,7 +361,7 @@ public abstract class CommonSyntacticValidator {
 		// NOTE: we use exception handling instead of Doubles.tryParse for backwards compatibility with guava <14.0
 		try {
 			double dval = Double.parseDouble(varValue);
-			return new DoubleIdentifier(dval, currentFile, linePosition, charPosition, linePosition, charPosition);
+			return new DoubleIdentifier(ctx, dval, currentFile);
 		}
 		catch(Exception ex) {
 			//continue
@@ -420,14 +379,14 @@ public abstract class CommonSyntacticValidator {
 			// the commandline parameters can be passed without any quotes
 			val = extractStringInQuotes(text, false);
 		}
-		return new StringIdentifier(val, currentFile, linePosition, charPosition, linePosition, charPosition);
+		return new StringIdentifier(ctx, val, currentFile);
 	}
 
 
-	protected void fillExpressionInfoCommandLineParameters(String varName, ExpressionInfo dataInfo, Token start) {
+	protected void fillExpressionInfoCommandLineParameters(ParserRuleContext ctx, String varName, ExpressionInfo dataInfo) {
 
 		if(!varName.startsWith("$")) {
-			notifyErrorListeners("commandline param doesnot start with $", start);
+			notifyErrorListeners("commandline param does not start with $", ctx.start);
 			return;
 		}
 
@@ -435,7 +394,7 @@ public abstract class CommonSyntacticValidator {
 		for(Map.Entry<String, String> arg : this.argVals.entrySet()) {
 			if(arg.getKey().equals(varName)) {
 				if(varValue != null) {
-					notifyErrorListeners("multiple values passed for the parameter " + varName + " via commandline", start);
+					notifyErrorListeners("multiple values passed for the parameter " + varName + " via commandline", ctx.start);
 					return;
 				}
 				else {
@@ -453,7 +412,7 @@ public abstract class CommonSyntacticValidator {
 		if(varValue.equals(""))
 			return;
 
-		dataInfo.expr = getConstIdFromString(varValue, start);
+		dataInfo.expr = getConstIdFromString(ctx, varValue);
 	}
 
 	protected void exitAssignmentStatementHelper(ParserRuleContext ctx, String lhs, ExpressionInfo dataInfo,
@@ -467,12 +426,8 @@ public abstract class CommonSyntacticValidator {
 		if(dataInfo.expr instanceof DataIdentifier) {
 			target = (DataIdentifier) dataInfo.expr;
 			Expression source = rhs.expr;
-
-			int line = ctx.start.getLine();
-			int col = ctx.start.getCharPositionInLine();
 			try {
-				info.stmt = new AssignmentStatement(target, source, line, col, line, col);
-				setFileLineColumn(info.stmt, ctx);
+				info.stmt = new AssignmentStatement(ctx, target, source, currentFile);
 			} catch (LanguageException e) {
 				// TODO: extract more meaningful info from this exception.
 				notifyErrorListeners("invalid assignment", lhsStart);
@@ -494,11 +449,7 @@ public abstract class CommonSyntacticValidator {
 			ArrayList<ParameterExpression> paramExpression, StatementInfo thisinfo) {
 		if (DMLScript.VALIDATOR_IGNORE_ISSUES == true) { // create dummy print statement
 			try {
-				int line = ctx.start.getLine();
-				int col = ctx.start.getCharPositionInLine();
-				ArrayList<Expression> expList = new ArrayList<Expression>();
-				thisinfo.stmt = new PrintStatement(functionName, expList, line, col, line, col);
-				setFileLineColumn(thisinfo.stmt, ctx);
+				thisinfo.stmt = new PrintStatement(ctx, functionName, currentFile);
 			} catch (LanguageException e) {
 				e.printStackTrace();
 			}
@@ -515,12 +466,9 @@ public abstract class CommonSyntacticValidator {
 				return;
 			}
 			try {
-				int line = ctx.start.getLine();
-				int col = ctx.start.getCharPositionInLine();
-				ArrayList<Expression> expList = new ArrayList<Expression>();
+				List<Expression> expList = new ArrayList<Expression>();
 				expList.add(expr);
-				thisinfo.stmt = new PrintStatement(functionName, expList, line, col, line, col);
-				setFileLineColumn(thisinfo.stmt, ctx);
+				thisinfo.stmt = new PrintStatement(ctx, functionName, expList, currentFile);
 			} catch (LanguageException e) {
 				notifyErrorListeners("cannot process " + functionName + "() function", ctx.start);
 				return;
@@ -541,16 +489,12 @@ public abstract class CommonSyntacticValidator {
 				return;
 			}
 			try {
-				int line = ctx.start.getLine();
-				int col = ctx.start.getCharPositionInLine();
-
 				List<Expression> expressions = new ArrayList<Expression>();
 				for (ParameterExpression pe : paramExpression) {
 					Expression expression = pe.getExpr();
 					expressions.add(expression);
 				}
-				thisinfo.stmt = new PrintStatement(functionName, expressions, line, col, line, col);
-				setFileLineColumn(thisinfo.stmt, ctx);
+				thisinfo.stmt = new PrintStatement(ctx, functionName, expressions, currentFile);
 			} catch (LanguageException e) {
 				notifyErrorListeners("cannot process " + functionName + "() function", ctx.start);
 				return;
@@ -565,9 +509,6 @@ public abstract class CommonSyntacticValidator {
 			return;
 		}
 		if(paramExpression.get(0).getExpr() instanceof DataIdentifier) {
-			String fileName = currentFile;
-			int line = ctx.start.getLine();
-			int col = ctx.start.getCharPositionInLine();
 			HashMap<String, Expression> varParams = new HashMap<String, Expression>();
 			varParams.put(DataExpression.IO_FILENAME, paramExpression.get(1).getExpr());
 			for(int i = 2; i < paramExpression.size(); i++) {
@@ -575,9 +516,9 @@ public abstract class CommonSyntacticValidator {
 				varParams.put(paramExpression.get(i).getName(), paramExpression.get(i).getExpr());
 			}
 
-			DataExpression  dataExpression = new DataExpression(DataOp.WRITE, varParams, fileName, line, col, line, col);
-			info.stmt = new  OutputStatement((DataIdentifier) paramExpression.get(0).getExpr(), DataOp.WRITE, fileName, line, col, line, col);
-			setFileLineColumn(info.stmt, ctx);
+			DataExpression  dataExpression = new DataExpression(ctx, DataOp.WRITE, varParams, currentFile);
+			info.stmt = new OutputStatement(ctx, (DataIdentifier) paramExpression.get(0).getExpr(), DataOp.WRITE,
+					currentFile);
 			((OutputStatement)info.stmt).setExprParams(dataExpression);
 		}
 		else {
@@ -587,8 +528,7 @@ public abstract class CommonSyntacticValidator {
 
 	protected void setAssignmentStatement(ParserRuleContext ctx, StatementInfo info, DataIdentifier target, Expression expression) {
 		try {
-			info.stmt = new AssignmentStatement(target, expression, ctx.start.getLine(), ctx.start.getCharPositionInLine(), ctx.start.getLine(), ctx.start.getCharPositionInLine());
-			setFileLineColumn(info.stmt, ctx);
+			info.stmt = new AssignmentStatement(ctx, target, expression, currentFile);
 		} catch (LanguageException e) {
 			// TODO: extract more meaningful info from this exception.
 			notifyErrorListeners("invalid function call", ctx.start);
@@ -651,9 +591,6 @@ public abstract class CommonSyntacticValidator {
 	protected boolean buildForBuiltInFunction(ParserRuleContext ctx, String functionName, ArrayList<ParameterExpression> paramExpressions, Action f) {
 		// In global namespace, so it can be a builtin function
 		// Double verification: verify passed function name is a (non-parameterized) built-in function.
-		String fileName = currentFile;
-		int line = ctx.start.getLine();
-		int col = ctx.start.getCharPositionInLine();
 		try {
 			if (functions.contains(functionName)) {
 				// It is a user function definition (which takes precedence if name same as built-in)
@@ -667,14 +604,15 @@ public abstract class CommonSyntacticValidator {
 				return true;
 			}
 
-			BuiltinFunctionExpression bife = BuiltinFunctionExpression.getBuiltinFunctionExpression(functionName, paramExpressions, fileName, line, col, line, col);
+			BuiltinFunctionExpression bife = BuiltinFunctionExpression.getBuiltinFunctionExpression(ctx, functionName, paramExpressions, currentFile);
 			if (bife != null){
 				// It is a builtin function
 				f.execute(bife);
 				return true;
 			}
 
-			ParameterizedBuiltinFunctionExpression pbife = ParameterizedBuiltinFunctionExpression.getParamBuiltinFunctionExpression(functionName, paramExpressions, fileName, line, col, line, col);
+			ParameterizedBuiltinFunctionExpression pbife = ParameterizedBuiltinFunctionExpression
+					.getParamBuiltinFunctionExpression(ctx, functionName, paramExpressions, currentFile);
 			if (pbife != null){
 				// It is a parameterized builtin function
 				f.execute(pbife);
@@ -682,7 +620,7 @@ public abstract class CommonSyntacticValidator {
 			}
 
 			// built-in read, rand ...
-			DataExpression dbife = DataExpression.getDataExpression(functionName, paramExpressions, fileName, line, col, line, col, errorListener);
+			DataExpression dbife = DataExpression.getDataExpression(ctx, functionName, paramExpressions, currentFile, errorListener);
 			if (dbife != null){
 				f.execute(dbife);
 				return true;
@@ -748,7 +686,7 @@ public abstract class CommonSyntacticValidator {
 		String inferNamespace = (sourceNamespace != null && sourceNamespace.length() > 0 && DMLProgram.DEFAULT_NAMESPACE.equals(namespace)) ? sourceNamespace : namespace;
 		functCall.setFunctionNamespace(inferNamespace);
 
-		functCall.setAllPositions(currentFile, ctx.start.getLine(), ctx.start.getCharPositionInLine(), ctx.stop.getLine(), ctx.stop.getCharPositionInLine());
+		functCall.setCtxValuesAndFilename(ctx, currentFile);
 
 		setAssignmentStatement(ctx, info, target, functCall);
 	}
@@ -763,8 +701,7 @@ public abstract class CommonSyntacticValidator {
 
 	protected void setMultiAssignmentStatement(ArrayList<DataIdentifier> target, Expression expression, ParserRuleContext ctx, StatementInfo info) {
 		info.stmt = new MultiAssignmentStatement(target, expression);
-		info.stmt.setAllPositions(currentFile, ctx.start.getLine(), ctx.start.getCharPositionInLine(), ctx.start.getLine(), ctx.start.getCharPositionInLine());
-		setFileLineColumn(info.stmt, ctx);
+		info.stmt.setCtxValuesAndFilename(ctx, currentFile);
 	}
 
 	// -----------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/common/CustomErrorListener.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/common/CustomErrorListener.java b/src/main/java/org/apache/sysml/parser/common/CustomErrorListener.java
index 90d0265..6a27acf 100644
--- a/src/main/java/org/apache/sysml/parser/common/CustomErrorListener.java
+++ b/src/main/java/org/apache/sysml/parser/common/CustomErrorListener.java
@@ -29,6 +29,7 @@ import org.antlr.v4.runtime.Recognizer;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.sysml.api.DMLScript;
+import org.apache.sysml.parser.ParseInfo;
 
 public class CustomErrorListener extends BaseErrorListener {
 
@@ -85,6 +86,25 @@ public class CustomErrorListener extends BaseErrorListener {
 		}
 	}
 
+	public void validationError(ParseInfo parseInfo, String msg) {
+		parseIssues.add(new ParseIssue(parseInfo.getBeginLine(), parseInfo.getBeginColumn(), msg, currentFileName,
+				ParseIssueType.VALIDATION_ERROR));
+
+		try {
+			setAtLeastOneError(true);
+			if (currentFileName == null) {
+				log.error("line " + parseInfo.getBeginLine() + ":" + parseInfo.getBeginColumn() + " ("
+						+ parseInfo.getText() + "): " + msg);
+			} else {
+				String fileName = currentFileName;
+				log.error(fileName + " line " + parseInfo.getBeginLine() + ":" + parseInfo.getBeginColumn() + " ("
+						+ parseInfo.getText() + "): " + msg);
+			}
+		} catch (Exception e) {
+			log.error("ERROR: while customizing error message:" + e);
+		}
+	}
+
 	/**
 	 * Validation warning occurred. Add the warning to the list of parse issues.
 	 * 

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java b/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java
index bcedc97..62b499f 100644
--- a/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java
+++ b/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java
@@ -354,14 +354,14 @@ public class DmlSyntacticValidator extends CommonSyntacticValidator implements D
 	private void handleCommandlineArgumentExpression(DataIdentifierContext ctx)
 	{
 		String varName = ctx.getText().trim();
-		fillExpressionInfoCommandLineParameters(varName, ctx.dataInfo, ctx.start);
+		fillExpressionInfoCommandLineParameters(ctx, varName, ctx.dataInfo);
 
 		if(ctx.dataInfo.expr == null) {
 			if(!(ctx.parent instanceof IfdefAssignmentStatementContext)) {
 				String msg = "The parameter " + varName + " either needs to be passed "
 						+ "through commandline or initialized to default value.";
 				if( ConfigurationManager.getCompilerConfigFlag(ConfigType.IGNORE_UNSPECIFIED_ARGS) ) {
-					ctx.dataInfo.expr = getConstIdFromString(" ", ctx.start);
+					ctx.dataInfo.expr = getConstIdFromString(ctx, " ");
 					if (!ConfigurationManager.getCompilerConfigFlag(ConfigType.MLCONTEXT)) {
 						raiseWarning(msg, ctx.start);
 					}
@@ -607,10 +607,7 @@ public class DmlSyntacticValidator extends CommonSyntacticValidator implements D
 		IfStatement ifStmt = new IfStatement();
 		ConditionalPredicate predicate = new ConditionalPredicate(ctx.predicate.info.expr);
 		ifStmt.setConditionalPredicate(predicate);
-		String fileName = currentFile;
-		int line = ctx.start.getLine();
-		int col = ctx.start.getCharPositionInLine();
-		ifStmt.setAllPositions(fileName, line, col, line, col);
+		ifStmt.setCtxValuesAndFilename(ctx, currentFile);
 
 		if(ctx.ifBody.size() > 0) {
 			for(StatementContext stmtCtx : ctx.ifBody) {
@@ -635,9 +632,7 @@ public class DmlSyntacticValidator extends CommonSyntacticValidator implements D
 		WhileStatement whileStmt = new WhileStatement();
 		ConditionalPredicate predicate = new ConditionalPredicate(ctx.predicate.info.expr);
 		whileStmt.setPredicate(predicate);
-		int line = ctx.start.getLine();
-		int col = ctx.start.getCharPositionInLine();
-		whileStmt.setAllPositions(currentFile, line, col, line, col);
+		whileStmt.setCtxValuesAndFilename(ctx, currentFile);
 
 		if(ctx.body.size() > 0) {
 			for(StatementContext stmtCtx : ctx.body) {
@@ -653,8 +648,6 @@ public class DmlSyntacticValidator extends CommonSyntacticValidator implements D
 	@Override
 	public void exitForStatement(ForStatementContext ctx) {
 		ForStatement forStmt = new ForStatement();
-		int line = ctx.start.getLine();
-		int col = ctx.start.getCharPositionInLine();
 
 		DataIdentifier iterVar = new DataIdentifier(ctx.iterVar.getText());
 		HashMap<String, String> parForParamValues = null;
@@ -662,7 +655,8 @@ public class DmlSyntacticValidator extends CommonSyntacticValidator implements D
 		if(ctx.iterPred.info.increment != null) {
 			incrementExpr = ctx.iterPred.info.increment;
 		}
-		IterablePredicate predicate = new IterablePredicate(iterVar, ctx.iterPred.info.from, ctx.iterPred.info.to, incrementExpr, parForParamValues, currentFile, line, col, line, col);
+		IterablePredicate predicate = new IterablePredicate(ctx, iterVar, ctx.iterPred.info.from, ctx.iterPred.info.to,
+				incrementExpr, parForParamValues, currentFile);
 		forStmt.setPredicate(predicate);
 
 		if(ctx.body.size() > 0) {
@@ -672,14 +666,11 @@ public class DmlSyntacticValidator extends CommonSyntacticValidator implements D
 			forStmt.mergeStatementBlocks();
 		}
 		ctx.info.stmt = forStmt;
-		setFileLineColumn(ctx.info.stmt, ctx);
 	}
 
 	@Override
 	public void exitParForStatement(ParForStatementContext ctx) {
 		ParForStatement parForStmt = new ParForStatement();
-		int line = ctx.start.getLine();
-		int col = ctx.start.getCharPositionInLine();
 
 		DataIdentifier iterVar = new DataIdentifier(ctx.iterVar.getText());
 		HashMap<String, String> parForParamValues = new HashMap<String, String>();
@@ -696,7 +687,8 @@ public class DmlSyntacticValidator extends CommonSyntacticValidator implements D
 		if( ctx.iterPred.info.increment != null ) {
 			incrementExpr = ctx.iterPred.info.increment;
 		}
-		IterablePredicate predicate = new IterablePredicate(iterVar, ctx.iterPred.info.from, ctx.iterPred.info.to, incrementExpr, parForParamValues, currentFile, line, col, line, col);
+		IterablePredicate predicate = new IterablePredicate(ctx, iterVar, ctx.iterPred.info.from, ctx.iterPred.info.to,
+				incrementExpr, parForParamValues, currentFile);
 		parForStmt.setPredicate(predicate);
 		if(ctx.body.size() > 0) {
 			for(StatementContext stmtCtx : ctx.body) {
@@ -705,7 +697,6 @@ public class DmlSyntacticValidator extends CommonSyntacticValidator implements D
 			parForStmt.mergeStatementBlocks();
 		}
 		ctx.info.stmt = parForStmt;
-		setFileLineColumn(ctx.info.stmt, ctx);
 	}
 
 	private ArrayList<DataIdentifier> getFunctionParameters(List<TypedArgNoAssignContext> ctx) {
@@ -914,11 +905,8 @@ public class DmlSyntacticValidator extends CommonSyntacticValidator implements D
 				source = ctx.source.info.expr;
 			}
 
-			int line = ctx.start.getLine();
-			int col = ctx.start.getCharPositionInLine();
 			try {
-				ctx.info.stmt = new AssignmentStatement(target, source, line, col, line, col);
-				setFileLineColumn(ctx.info.stmt, ctx);
+				ctx.info.stmt = new AssignmentStatement(ctx, target, source, currentFile);
 			} catch (LanguageException e) {
 				notifyErrorListeners("invalid assignment for ifdef function", ctx.targetList.start);
 				return;

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java b/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java
index 4c9b416..8b75309 100644
--- a/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java
+++ b/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java
@@ -358,21 +358,14 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 					// Add expression for nrow(X) for implicit upper bound
 					Expression.BuiltinFunctionOp bop = Expression.BuiltinFunctionOp.NROW;
 					DataIdentifier x = new DataIdentifier(ctx.name.getText());
-					int line = ctx.start.getLine();
-					int col = ctx.start.getCharPositionInLine();
-					Expression expr = new BuiltinFunctionExpression(bop, new Expression[]{x},
-							currentFile, line, col, line, col);
-					setFileLineColumn(expr, ctx);
+					Expression expr = new BuiltinFunctionExpression(ctx, bop, new Expression[] { x }, currentFile);
 					rowIndices.add(expr);
 				}
 			}
 			else if(!isRowLower && isRowUpper && isRowSliceImplicit) {
 				// Add expression for `1` for implicit lower bound
 				// Note: We go ahead and increment by 1 to convert from 0-based to 1-based indexing
-				int line = ctx.start.getLine();
-				int col = ctx.start.getCharPositionInLine();
-				IntIdentifier one = new IntIdentifier(1, currentFile, line, col, line, col);
-				setFileLineColumn(one, ctx);
+				IntIdentifier one = new IntIdentifier(ctx, 1, currentFile);
 				rowIndices.add(one);
 
 				// Add given upper bound
@@ -398,21 +391,14 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 					// Add expression for ncol(X) for implicit upper bound
 					Expression.BuiltinFunctionOp bop = Expression.BuiltinFunctionOp.NCOL;
 					DataIdentifier x = new DataIdentifier(ctx.name.getText());
-					int line = ctx.start.getLine();
-					int col = ctx.start.getCharPositionInLine();
-					Expression expr = new BuiltinFunctionExpression(bop, new Expression[]{x},
-							currentFile, line, col, line, col);
-					setFileLineColumn(expr, ctx);
+					Expression expr = new BuiltinFunctionExpression(ctx, bop, new Expression[] { x }, currentFile);
 					colIndices.add(expr);
 				}
 			}
 			else if(!isColLower && isColUpper && isColSliceImplicit) {
 				// Add expression for `1` for implicit lower bound
 				// Note: We go ahead and increment by 1 to convert from 0-based to 1-based indexing
-				int line = ctx.start.getLine();
-				int col = ctx.start.getCharPositionInLine();
-				IntIdentifier one = new IntIdentifier(1, currentFile, line, col, line, col);
-				setFileLineColumn(one, ctx);
+				IntIdentifier one = new IntIdentifier(ctx, 1, currentFile);
 				colIndices.add(one);
 
 				// Add given upper bound
@@ -445,9 +431,7 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 		Expression.BinaryOp bop = Expression.getBinaryOp("+");
 		Expression retVal = new BinaryExpression(bop);
 		((BinaryExpression)retVal).setLeft(expr);
-		int line = ctx.start.getLine();
-		int col = ctx.start.getCharPositionInLine();
-		((BinaryExpression)retVal).setRight(new DoubleIdentifier(1.0, currentFile, line, col, line, col));
+		((BinaryExpression)retVal).setRight(new DoubleIdentifier(ctx, 1.0, currentFile));
 		setFileLineColumn(retVal, ctx);
 		return retVal;
 	}
@@ -470,14 +454,14 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 	private void handleCommandlineArgumentExpression(DataIdentifierContext ctx)
 	{
 		String varName = ctx.getText().trim();
-		fillExpressionInfoCommandLineParameters(varName, ctx.dataInfo, ctx.start);
+		fillExpressionInfoCommandLineParameters(ctx, varName, ctx.dataInfo);
 
 		if(ctx.dataInfo.expr == null) {
 			if(!(ctx.parent instanceof IfdefAssignmentStatementContext)) {
 				String msg = "The parameter " + varName + " either needs to be passed "
 						+ "through commandline or initialized to default value.";
 				if( ConfigurationManager.getCompilerConfigFlag(ConfigType.IGNORE_UNSPECIFIED_ARGS) ) {
-					ctx.dataInfo.expr = getConstIdFromString(" ", ctx.start);
+					ctx.dataInfo.expr = getConstIdFromString(ctx, " ");
 					if (!ConfigurationManager.getCompilerConfigFlag(ConfigType.MLCONTEXT)) {
 						raiseWarning(msg, ctx.start);
 					}
@@ -664,10 +648,6 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 			return new ConvertedDMLSyntax(namespace, functionName, paramExpression);
 		}
 
-		String fileName = currentFile;
-		int line = ctx.start.getLine();
-		int col = ctx.start.getCharPositionInLine();
-
 		if(namespace.equals(DMLProgram.DEFAULT_NAMESPACE) && functionName.equals("len")) {
 			if(paramExpression.size() != 1) {
 				notifyErrorListeners("The builtin function \'" + functionName + "\' accepts 1 arguments", fnName);
@@ -812,7 +792,7 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 			paramExpression.get(0).setName("rows");
 			paramExpression.get(1).setName("cols");
 			paramExpression.get(2).setName("sparsity");
-			paramExpression.add(new ParameterExpression("pdf", new StringIdentifier("normal", fileName, line, col, line, col)));
+			paramExpression.add(new ParameterExpression("pdf", new StringIdentifier(ctx, "normal", currentFile)));
 			functionName = "rand";
 			namespace = DMLProgram.DEFAULT_NAMESPACE;
 		}
@@ -826,7 +806,7 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 			paramExpression.get(1).setName("cols");
 			paramExpression.get(2).setName("sparsity");
 			paramExpression.get(3).setName("lambda");
-			paramExpression.add(new ParameterExpression("pdf", new StringIdentifier("poisson", fileName, line, col, line, col)));
+			paramExpression.add(new ParameterExpression("pdf", new StringIdentifier(ctx, "poisson", currentFile)));
 			functionName = "rand";
 			namespace = DMLProgram.DEFAULT_NAMESPACE;
 		}
@@ -841,7 +821,7 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 			paramExpression.get(2).setName("sparsity");
 			paramExpression.get(3).setName("min");
 			paramExpression.get(4).setName("max");
-			paramExpression.add(new ParameterExpression("pdf", new StringIdentifier("uniform", fileName, line, col, line, col)));
+			paramExpression.add(new ParameterExpression("pdf", new StringIdentifier(ctx, "uniform", currentFile)));
 			functionName = "rand";
 			namespace = DMLProgram.DEFAULT_NAMESPACE;
 		}
@@ -885,9 +865,9 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 				initializerString = initializerString.replaceAll("\\[", "");
 				initializerString = initializerString.replaceAll("\\]", "");
 				paramExpression = new ArrayList<ParameterExpression>();
-				paramExpression.add(new ParameterExpression(null, new StringIdentifier(initializerString, fileName, line, col, line, col)));
-				paramExpression.add(new ParameterExpression("rows", new IntIdentifier(rows, fileName, line, col, line, col)));
-				paramExpression.add(new ParameterExpression("cols", new IntIdentifier(cols, fileName, line, col, line, col)));
+				paramExpression.add(new ParameterExpression(null, new StringIdentifier(ctx, initializerString, currentFile)));
+				paramExpression.add(new ParameterExpression("rows", new IntIdentifier(ctx, rows, currentFile)));
+				paramExpression.add(new ParameterExpression("cols", new IntIdentifier(ctx, cols, currentFile)));
 			}
 			else {
 				functionName = "as.matrix";
@@ -955,10 +935,10 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 			}
 			StringIdentifier marginVal = null;
 			if(axis == 0) {
-				marginVal = new StringIdentifier("rows", fileName, line, col, line, col);
+				marginVal = new StringIdentifier(ctx, "rows", currentFile);
 			}
 			else {
-				marginVal = new StringIdentifier("cols", fileName, line, col, line, col);
+				marginVal = new StringIdentifier(ctx, "cols", currentFile);
 			}
 			paramExpression.get(0).setName("target");
 			paramExpression.get(1).setName("margin");
@@ -997,7 +977,7 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 			paramExpression.get(0).setName("target");
 			paramExpression.get(1).setName("mean");
 			paramExpression.get(2).setName("sd");
-			paramExpression.add(new ParameterExpression("dist", new StringIdentifier("normal", fileName, line, col, line, col)));
+			paramExpression.add(new ParameterExpression("dist", new StringIdentifier(ctx, "normal", currentFile)));
 			namespace = DMLProgram.DEFAULT_NAMESPACE;
 		}
 		else if(namespace.equals("expon") && functionName.equals("cdf")) {
@@ -1009,7 +989,7 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 			functionName = "cdf";
 			paramExpression.get(0).setName("target");
 			paramExpression.get(1).setName("mean");
-			paramExpression.add(new ParameterExpression("dist", new StringIdentifier("exp", fileName, line, col, line, col)));
+			paramExpression.add(new ParameterExpression("dist", new StringIdentifier(ctx, "exp", currentFile)));
 			namespace = DMLProgram.DEFAULT_NAMESPACE;
 		}
 		else if(namespace.equals("chi") && functionName.equals("cdf")) {
@@ -1021,7 +1001,7 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 			functionName = "cdf";
 			paramExpression.get(0).setName("target");
 			paramExpression.get(1).setName("df");
-			paramExpression.add(new ParameterExpression("dist", new StringIdentifier("chisq", fileName, line, col, line, col)));
+			paramExpression.add(new ParameterExpression("dist", new StringIdentifier(ctx, "chisq", currentFile)));
 			namespace = DMLProgram.DEFAULT_NAMESPACE;
 		}
 		else if(namespace.equals("f") && functionName.equals("cdf")) {
@@ -1034,7 +1014,7 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 			paramExpression.get(0).setName("target");
 			paramExpression.get(1).setName("df1");
 			paramExpression.get(2).setName("df2");
-			paramExpression.add(new ParameterExpression("dist", new StringIdentifier("f", fileName, line, col, line, col)));
+			paramExpression.add(new ParameterExpression("dist", new StringIdentifier(ctx, "f", currentFile)));
 			namespace = DMLProgram.DEFAULT_NAMESPACE;
 		}
 		else if(namespace.equals("t") && functionName.equals("cdf")) {
@@ -1046,7 +1026,7 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 			functionName = "cdf";
 			paramExpression.get(0).setName("target");
 			paramExpression.get(1).setName("df");
-			paramExpression.add(new ParameterExpression("dist", new StringIdentifier("t", fileName, line, col, line, col)));
+			paramExpression.add(new ParameterExpression("dist", new StringIdentifier(ctx, "t", currentFile)));
 			namespace = DMLProgram.DEFAULT_NAMESPACE;
 		}
 		else if(namespace.equals(DMLProgram.DEFAULT_NAMESPACE) && functionName.equals("percentile")) {
@@ -1245,10 +1225,7 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 		IfStatement ifStmt = new IfStatement();
 		ConditionalPredicate predicate = new ConditionalPredicate(ctx.predicate.info.expr);
 		ifStmt.setConditionalPredicate(predicate);
-		String fileName = currentFile;
-		int line = ctx.start.getLine();
-		int col = ctx.start.getCharPositionInLine();
-		ifStmt.setAllPositions(fileName, line, col, line, col);
+		ifStmt.setCtxValuesAndFilename(ctx, currentFile);
 
 		if(ctx.ifBody.size() > 0) {
 			for(StatementContext stmtCtx : ctx.ifBody) {
@@ -1282,10 +1259,7 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 		IfStatement elifStmt = new IfStatement();
 		ConditionalPredicate predicate = new ConditionalPredicate(ctx.predicate.info.expr);
 		elifStmt.setConditionalPredicate(predicate);
-		String fileName = currentFile;
-		int line = ctx.start.getLine();
-		int col = ctx.start.getCharPositionInLine();
-		elifStmt.setAllPositions(fileName, line, col, line, col);
+		elifStmt.setCtxValuesAndFilename(ctx, currentFile);
 
 		if(ctx.elifBody.size() > 0) {
 			for (StatementContext stmtCtx : ctx.elifBody) {
@@ -1303,9 +1277,7 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 		WhileStatement whileStmt = new WhileStatement();
 		ConditionalPredicate predicate = new ConditionalPredicate(ctx.predicate.info.expr);
 		whileStmt.setPredicate(predicate);
-		int line = ctx.start.getLine();
-		int col = ctx.start.getCharPositionInLine();
-		whileStmt.setAllPositions(currentFile, line, col, line, col);
+		whileStmt.setCtxValuesAndFilename(ctx, currentFile);
 
 		if(ctx.body.size() > 0) {
 			for(StatementContext stmtCtx : ctx.body) {
@@ -1321,8 +1293,6 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 	@Override
 	public void exitForStatement(ForStatementContext ctx) {
 		ForStatement forStmt = new ForStatement();
-		int line = ctx.start.getLine();
-		int col = ctx.start.getCharPositionInLine();
 
 		DataIdentifier iterVar = new DataIdentifier(ctx.iterVar.getText());
 		HashMap<String, String> parForParamValues = null;
@@ -1330,7 +1300,8 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 		if(ctx.iterPred.info.increment != null) {
 			incrementExpr = ctx.iterPred.info.increment;
 		}
-		IterablePredicate predicate = new IterablePredicate(iterVar, ctx.iterPred.info.from, ctx.iterPred.info.to, incrementExpr, parForParamValues, currentFile, line, col, line, col);
+		IterablePredicate predicate = new IterablePredicate(ctx, iterVar, ctx.iterPred.info.from, ctx.iterPred.info.to,
+				incrementExpr, parForParamValues, currentFile);
 		forStmt.setPredicate(predicate);
 
 		if(ctx.body.size() > 0) {
@@ -1346,8 +1317,6 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 	@Override
 	public void exitParForStatement(ParForStatementContext ctx) {
 		ParForStatement parForStmt = new ParForStatement();
-		int line = ctx.start.getLine();
-		int col = ctx.start.getCharPositionInLine();
 
 		DataIdentifier iterVar = new DataIdentifier(ctx.iterVar.getText());
 		HashMap<String, String> parForParamValues = new HashMap<String, String>();
@@ -1364,7 +1333,8 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 		if( ctx.iterPred.info.increment != null ) {
 			incrementExpr = ctx.iterPred.info.increment;
 		}
-		IterablePredicate predicate = new IterablePredicate(iterVar, ctx.iterPred.info.from, ctx.iterPred.info.to, incrementExpr, parForParamValues, currentFile, line, col, line, col);
+		IterablePredicate predicate = new IterablePredicate(ctx, iterVar, ctx.iterPred.info.from, ctx.iterPred.info.to,
+				incrementExpr, parForParamValues, currentFile);
 		parForStmt.setPredicate(predicate);
 		if(ctx.body.size() > 0) {
 			for(StatementContext stmtCtx : ctx.body) {
@@ -1373,7 +1343,6 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 			parForStmt.mergeStatementBlocks();
 		}
 		ctx.info.stmt = parForStmt;
-		setFileLineColumn(ctx.info.stmt, ctx);
 	}
 
 
@@ -1576,11 +1545,8 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 				source = ctx.source.info.expr;
 			}
 
-			int line = ctx.start.getLine();
-			int col = ctx.start.getCharPositionInLine();
 			try {
-				ctx.info.stmt = new AssignmentStatement(target, source, line, col, line, col);
-				setFileLineColumn(ctx.info.stmt, ctx);
+				ctx.info.stmt = new AssignmentStatement(ctx, target, source, currentFile);
 			} catch (LanguageException e) {
 				notifyErrorListeners("invalid assignment for ifdef function", ctx.targetList.start);
 				return;
@@ -1621,7 +1587,7 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 		// Introduce empty StatementInfo
 		// This is later ignored by PyDMLParserWrapper
 		try {
-			ctx.info.stmt = new AssignmentStatement(null, null, 0, 0, 0, 0);
+			ctx.info.stmt = new AssignmentStatement(ctx, null, null);
 			ctx.info.stmt.setEmptyNewLineStatement(true);
 		} catch (LanguageException e) {
 			e.printStackTrace();

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/runtime/controlprogram/ProgramBlock.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/controlprogram/ProgramBlock.java b/src/main/java/org/apache/sysml/runtime/controlprogram/ProgramBlock.java
index 43e93f4..f1b3d5d 100644
--- a/src/main/java/org/apache/sysml/runtime/controlprogram/ProgramBlock.java
+++ b/src/main/java/org/apache/sysml/runtime/controlprogram/ProgramBlock.java
@@ -30,6 +30,7 @@ import org.apache.sysml.hops.OptimizerUtils;
 import org.apache.sysml.hops.recompile.Recompiler;
 import org.apache.sysml.lops.Lop;
 import org.apache.sysml.parser.Expression.ValueType;
+import org.apache.sysml.parser.ParseInfo;
 import org.apache.sysml.parser.StatementBlock;
 import org.apache.sysml.runtime.DMLRuntimeException;
 import org.apache.sysml.runtime.DMLScriptException;
@@ -50,7 +51,7 @@ import org.apache.sysml.utils.Statistics;
 import org.apache.sysml.yarn.DMLAppMasterUtils;
 
 
-public class ProgramBlock
+public class ProgramBlock implements ParseInfo
 {
 	protected static final Log LOG = LogFactory.getLog(ProgramBlock.class.getName());
 	private static final boolean CHECK_MATRIX_SPARSITY = false;
@@ -412,28 +413,43 @@ public class ProgramBlock
 	public String _filename;
 	public int _beginLine, _beginColumn;
 	public int _endLine, _endColumn;
+	public String _text;
 
 	public void setFilename(String passed)    { _filename = passed;   }
 	public void setBeginLine(int passed)    { _beginLine = passed;   }
 	public void setBeginColumn(int passed) 	{ _beginColumn = passed; }
 	public void setEndLine(int passed) 		{ _endLine = passed;   }
 	public void setEndColumn(int passed)	{ _endColumn = passed; }
-
-	public void setAllPositions(String filename, int blp, int bcp, int elp, int ecp){
-		_filename = filename;
-		_beginLine	 = blp;
-		_beginColumn = bcp;
-		_endLine 	 = elp;
-		_endColumn 	 = ecp;
-	}
+	public void setText(String text) { _text = text; }
 
 	public String getFilename()	{ return _filename;   }
 	public int getBeginLine()	{ return _beginLine;   }
 	public int getBeginColumn() { return _beginColumn; }
 	public int getEndLine() 	{ return _endLine;   }
 	public int getEndColumn()	{ return _endColumn; }
+	public String getText() { return _text; }
 
 	public String printBlockErrorLocation(){
 		return "ERROR: Runtime error in program block generated from statement block between lines " + _beginLine + " and " + _endLine + " -- ";
 	}
+
+	/**
+	 * Set parse information.
+	 *
+	 * @param parseInfo
+	 *            parse information, such as beginning line position, beginning
+	 *            column position, ending line position, ending column position,
+	 *            text, and filename
+	 * @param filename
+	 *            the DML/PYDML filename (if it exists)
+	 */
+	public void setParseInfo(ParseInfo parseInfo) {
+		_beginLine = parseInfo.getBeginLine();
+		_beginColumn = parseInfo.getBeginColumn();
+		_endLine = parseInfo.getEndLine();
+		_endColumn = parseInfo.getEndColumn();
+		_text = parseInfo.getText();
+		_filename = parseInfo.getFilename();
+	}
+
 }

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/runtime/controlprogram/parfor/ProgramConverter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/controlprogram/parfor/ProgramConverter.java b/src/main/java/org/apache/sysml/runtime/controlprogram/parfor/ProgramConverter.java
index d786eaa..afdf8be 100644
--- a/src/main/java/org/apache/sysml/runtime/controlprogram/parfor/ProgramConverter.java
+++ b/src/main/java/org/apache/sysml/runtime/controlprogram/parfor/ProgramConverter.java
@@ -551,7 +551,7 @@ public class ProgramConverter
 				//create new statement (shallow copy livein/liveout for recompile, line numbers for explain)
 				ret = new StatementBlock();
 				ret.setDMLProg(sb.getDMLProg());
-				ret.setAllPositions(sb.getFilename(), sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
+				ret.setParseInfo(sb);
 				ret.setLiveIn( sb.liveIn() ); 
 				ret.setLiveOut( sb.liveOut() ); 
 				ret.setUpdatedVariables( sb.variablesUpdated() );
@@ -591,7 +591,7 @@ public class ProgramConverter
 				//create new statement (shallow copy livein/liveout for recompile, line numbers for explain)
 				ret = new IfStatementBlock();
 				ret.setDMLProg(sb.getDMLProg());
-				ret.setAllPositions(sb.getFilename(), sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
+				ret.setParseInfo(sb);
 				ret.setLiveIn( sb.liveIn() );
 				ret.setLiveOut( sb.liveOut() );
 				ret.setUpdatedVariables( sb.variablesUpdated() );
@@ -632,7 +632,7 @@ public class ProgramConverter
 				//create new statement (shallow copy livein/liveout for recompile, line numbers for explain)
 				ret = new WhileStatementBlock();
 				ret.setDMLProg(sb.getDMLProg());
-				ret.setAllPositions(sb.getFilename(), sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
+				ret.setParseInfo(sb);
 				ret.setLiveIn( sb.liveIn() );
 				ret.setLiveOut( sb.liveOut() );
 				ret.setUpdatedVariables( sb.variablesUpdated() );
@@ -678,7 +678,7 @@ public class ProgramConverter
 				
 				//create new statement (shallow copy livein/liveout for recompile, line numbers for explain)
 				ret.setDMLProg(sb.getDMLProg());
-				ret.setAllPositions(sb.getFilename(), sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
+				ret.setParseInfo(sb);
 				ret.setLiveIn( sb.liveIn() );
 				ret.setLiveOut( sb.liveOut() );
 				ret.setUpdatedVariables( sb.variablesUpdated() );

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/test/java/org/apache/sysml/test/integration/functions/misc/OuterTableExpandTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/sysml/test/integration/functions/misc/OuterTableExpandTest.java b/src/test/java/org/apache/sysml/test/integration/functions/misc/OuterTableExpandTest.java
index 59f2423..2c09850 100644
--- a/src/test/java/org/apache/sysml/test/integration/functions/misc/OuterTableExpandTest.java
+++ b/src/test/java/org/apache/sysml/test/integration/functions/misc/OuterTableExpandTest.java
@@ -256,7 +256,7 @@ public class OuterTableExpandTest extends AutomatedTestBase
 			
 				//check compiled/executed jobs
 				if( rtplatform == RUNTIME_PLATFORM.HADOOP ) {
-					int expectedNumCompiled = 3; //reblock+gmr+gmr if rexpand; otherwise 3/5 
+					int expectedNumCompiled = 2; //reblock+gmr if rexpand; otherwise 3/5
 					int expectedNumExecuted = expectedNumCompiled; 
 					checkNumCompiledMRJobs(expectedNumCompiled); 
 					checkNumExecutedMRJobs(expectedNumExecuted); 	


[2/3] systemml git commit: [SYSTEMML-1858] Allow parsed text in validation errors

Posted by de...@apache.org.
http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/DataExpression.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/DataExpression.java b/src/main/java/org/apache/sysml/parser/DataExpression.java
index 1fa8fd3..d487020 100644
--- a/src/main/java/org/apache/sysml/parser/DataExpression.java
+++ b/src/main/java/org/apache/sysml/parser/DataExpression.java
@@ -26,6 +26,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map.Entry;
 
+import org.antlr.v4.runtime.ParserRuleContext;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -135,10 +136,15 @@ public class DataExpression extends DataIdentifier
 		_checkMetadata = checkMetadata;
 	}
 
+	public static DataExpression getDataExpression(ParserRuleContext ctx, String functionName,
+			ArrayList<ParameterExpression> passedParamExprs, String filename, CustomErrorListener errorListener)
+			throws LanguageException {
+		ParseInfo pi = ParseInfo.ctxAndFilenameToParseInfo(ctx, filename);
+		return getDataExpression(functionName, passedParamExprs, pi, errorListener);
+	}
 
-	public static DataExpression getDataExpression(String functionName, ArrayList<ParameterExpression> passedParamExprs, 
-				String filename, int blp, int bcp, int elp, int ecp, CustomErrorListener errorListener) throws LanguageException
-	{	
+	public static DataExpression getDataExpression(String functionName, ArrayList<ParameterExpression> passedParamExprs,
+			ParseInfo parseInfo, CustomErrorListener errorListener) throws LanguageException {
 		if (functionName == null || passedParamExprs == null)
 			return null;
 		
@@ -146,31 +152,28 @@ public class DataExpression extends DataIdentifier
 		//	 (assign built-in function op if function is built-in)
 		Expression.DataOp dop = null;
 		DataExpression dataExpr = null;
-		if (functionName.equals("read") || functionName.equals("readMM") || functionName.equals("read.csv"))
-		{
+		if (functionName.equals("read") || functionName.equals("readMM") || functionName.equals("read.csv")) {
 			dop = Expression.DataOp.READ;
-			dataExpr = new DataExpression(dop, new HashMap<String,Expression>(), filename, blp, bcp, elp, ecp);
-			
+			dataExpr = new DataExpression(dop, new HashMap<String, Expression>(), parseInfo);
+
 			if (functionName.equals("readMM"))
-				dataExpr.addVarParam(DataExpression.FORMAT_TYPE,  
-						new StringIdentifier(DataExpression.FORMAT_TYPE_VALUE_MATRIXMARKET,
-								filename, blp, bcp, elp, ecp));
-			
+				dataExpr.addVarParam(DataExpression.FORMAT_TYPE,
+						new StringIdentifier(DataExpression.FORMAT_TYPE_VALUE_MATRIXMARKET, parseInfo));
+
 			if (functionName.equals("read.csv"))
-				dataExpr.addVarParam(DataExpression.FORMAT_TYPE,  
-						new StringIdentifier(DataExpression.FORMAT_TYPE_VALUE_CSV, 
-								filename, blp, bcp, elp, ecp));
-			
+				dataExpr.addVarParam(DataExpression.FORMAT_TYPE,
+						new StringIdentifier(DataExpression.FORMAT_TYPE_VALUE_CSV, parseInfo));
+
 			// validate the filename is the first parameter
 			if (passedParamExprs.size() < 1){
-				errorListener.validationError(blp, bcp, "read method must have at least filename parameter");
+				errorListener.validationError(parseInfo, "read method must have at least filename parameter");
 				return null;
 			}
 			
 			ParameterExpression pexpr = (passedParamExprs.size() == 0) ? null : passedParamExprs.get(0);
 			
 			if ( (pexpr != null) &&  (!(pexpr.getName() == null) || (pexpr.getName() != null && pexpr.getName().equalsIgnoreCase(DataExpression.IO_FILENAME)))){
-				errorListener.validationError(blp, bcp, "first parameter to read statement must be filename");
+				errorListener.validationError(parseInfo, "first parameter to read statement must be filename");
 				return null;
 			} else if( pexpr != null ){
 				dataExpr.addVarParam(DataExpression.IO_FILENAME, pexpr.getExpr());
@@ -182,7 +185,7 @@ public class DataExpression extends DataIdentifier
 				Expression currExpr = passedParamExprs.get(i).getExpr();
 				
 				if (dataExpr.getVarParam(currName) != null){
-					errorListener.validationError(blp, bcp, "attempted to add IOStatement parameter " + currName + " more than once");
+					errorListener.validationError(parseInfo, "attempted to add IOStatement parameter " + currName + " more than once");
 					return null;
 				}
 				// verify parameter names for read function
@@ -192,7 +195,7 @@ public class DataExpression extends DataIdentifier
 						isValidName = true;
 				}
 				if (!isValidName){
-					errorListener.validationError(blp, bcp, "attempted to add invalid read statement parameter " + currName);
+					errorListener.validationError(parseInfo, "attempted to add invalid read statement parameter " + currName);
 					return null;
 				}	
 				dataExpr.addVarParam(currName, currExpr);
@@ -202,14 +205,13 @@ public class DataExpression extends DataIdentifier
 		else if (functionName.equalsIgnoreCase("rand")){
 			
 			dop = Expression.DataOp.RAND;
-			dataExpr = new DataExpression(dop, new HashMap<String,Expression>(), 
-					filename, blp, bcp, elp, ecp);
+			dataExpr = new DataExpression(dop, new HashMap<String, Expression>(), parseInfo);
 			
 			for (ParameterExpression currExpr : passedParamExprs){
 				String pname = currExpr.getName();
 				Expression pexpr = currExpr.getExpr();
 				if (pname == null){
-					errorListener.validationError(blp, bcp, "for rand statement, all arguments must be named parameters");
+					errorListener.validationError(parseInfo, "for rand statement, all arguments must be named parameters");
 					return null;
 				}
 				dataExpr.addRandExprParam(pname, pexpr); 
@@ -219,8 +221,7 @@ public class DataExpression extends DataIdentifier
 		
 		else if (functionName.equals("matrix")){
 			dop = Expression.DataOp.MATRIX;
-			dataExpr = new DataExpression(dop, new HashMap<String,Expression>(),
-					filename, blp, bcp, elp, ecp);
+			dataExpr = new DataExpression(dop, new HashMap<String, Expression>(), parseInfo);
 		
 			int namedParamCount = 0, unnamedParamCount = 0;
 			for (ParameterExpression currExpr : passedParamExprs) {
@@ -232,19 +233,19 @@ public class DataExpression extends DataIdentifier
 
 			// check whether named or unnamed parameters are used
 			if (passedParamExprs.size() < 3){
-				errorListener.validationError(blp, bcp, "for matrix statement, must specify at least 3 arguments: data, rows, cols");
+				errorListener.validationError(parseInfo, "for matrix statement, must specify at least 3 arguments: data, rows, cols");
 				return null;
 			}
 			
 			if (unnamedParamCount > 1){
 				
 				if (namedParamCount > 0) {
-					errorListener.validationError(blp, bcp, "for matrix statement, cannot mix named and unnamed parameters");
+					errorListener.validationError(parseInfo, "for matrix statement, cannot mix named and unnamed parameters");
 					return null;
 				}
 				
 				if (unnamedParamCount < 3) {
-					errorListener.validationError(blp, bcp, "for matrix statement, must specify at least 3 arguments: data, rows, cols");
+					errorListener.validationError(parseInfo, "for matrix statement, must specify at least 3 arguments: data, rows, cols");
 					return null;
 				}
 				
@@ -261,7 +262,7 @@ public class DataExpression extends DataIdentifier
 					dataExpr.addMatrixExprParam(DataExpression.RAND_DIMNAMES,passedParamExprs.get(4).getExpr());
 				
 				if (unnamedParamCount > 5) {
-					errorListener.validationError(blp, bcp, "for matrix statement, at most 5 arguments supported: data, rows, cols, byrow, dimname");
+					errorListener.validationError(parseInfo, "for matrix statement, at most 5 arguments supported: data, rows, cols, byrow, dimname");
 					return null;
 				}
 				
@@ -269,7 +270,7 @@ public class DataExpression extends DataIdentifier
 				// handle first parameter, which is data and may be unnamed
 				ParameterExpression firstParam = passedParamExprs.get(0);
 				if (firstParam.getName() != null && !firstParam.getName().equals(DataExpression.RAND_DATA)){
-					errorListener.validationError(blp, bcp, "matrix method must have data parameter as first parameter or unnamed parameter");
+					errorListener.validationError(parseInfo, "matrix method must have data parameter as first parameter or unnamed parameter");
 					return null;
 				} else {
 					dataExpr.addMatrixExprParam(DataExpression.RAND_DATA, passedParamExprs.get(0).getExpr());
@@ -277,7 +278,7 @@ public class DataExpression extends DataIdentifier
 				
 				for (int i=1; i<passedParamExprs.size(); i++){
 					if (passedParamExprs.get(i).getName() == null){
-						errorListener.validationError(blp, bcp, "for matrix statement, cannot mix named and unnamed parameters, only data parameter can be unnammed");
+						errorListener.validationError(parseInfo, "for matrix statement, cannot mix named and unnamed parameters, only data parameter can be unnammed");
 						return null;
 					} else {
 						dataExpr.addMatrixExprParam(passedParamExprs.get(i).getName(), passedParamExprs.get(i).getExpr());
@@ -286,9 +287,9 @@ public class DataExpression extends DataIdentifier
 			}
 			dataExpr.setMatrixDefault();
 		}
-		
+
 		if (dataExpr != null) {
-			dataExpr.setAllPositions(filename, blp, bcp, elp, ecp);
+			dataExpr.setParseInfo(parseInfo);
 		}
 		return dataExpr;
 	
@@ -321,19 +322,13 @@ public class DataExpression extends DataIdentifier
 			raiseValidateError("attempted to add Rand statement parameter " + paramValue + " more than once");
 		}
 		// Process the case where user provides double values to rows or cols
-		if (paramName.equals(RAND_ROWS) && paramValue instanceof DoubleIdentifier){
-			paramValue = new IntIdentifier((long)((DoubleIdentifier)paramValue).getValue(), 
-					this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-					this.getBeginLine(), this.getBeginColumn());
+		if (paramName.equals(RAND_ROWS) && paramValue instanceof DoubleIdentifier) {
+			paramValue = new IntIdentifier((long) ((DoubleIdentifier) paramValue).getValue(), this);
+		} else if (paramName.equals(RAND_COLS) && paramValue instanceof DoubleIdentifier) {
+			paramValue = new IntIdentifier((long) ((DoubleIdentifier) paramValue).getValue(), this);
 		}
-		else if (paramName.equals(RAND_COLS) && paramValue instanceof DoubleIdentifier){
-			paramValue = new IntIdentifier((long)((DoubleIdentifier)paramValue).getValue(),
-					this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-					this.getBeginLine(), this.getBeginColumn());
-		}
-			
 		// add the parameter to expression list
-		paramValue.setAllPositions(this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
+		paramValue.setParseInfo(this);
 		addVarParam(paramName,paramValue);
 		
 	}
@@ -361,27 +356,28 @@ public class DataExpression extends DataIdentifier
 			raiseValidateError("attempted to add matrix statement parameter " + paramValue + " more than once");
 		}
 		// Process the case where user provides double values to rows or cols
-		if (paramName.equals(RAND_ROWS) && paramValue instanceof DoubleIdentifier){
-			paramValue = new IntIdentifier((long)((DoubleIdentifier)paramValue).getValue(),
-					this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-					this.getBeginLine(), this.getBeginColumn());
+		if (paramName.equals(RAND_ROWS) && paramValue instanceof DoubleIdentifier) {
+			paramValue = new IntIdentifier((long) ((DoubleIdentifier) paramValue).getValue(), this);
+		} else if (paramName.equals(RAND_COLS) && paramValue instanceof DoubleIdentifier) {
+			paramValue = new IntIdentifier((long) ((DoubleIdentifier) paramValue).getValue(), this);
 		}
-		else if (paramName.equals(RAND_COLS) && paramValue instanceof DoubleIdentifier){
-			paramValue = new IntIdentifier((long)((DoubleIdentifier)paramValue).getValue(),
-					this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-					this.getBeginLine(), this.getBeginColumn());
-		}
-			
+
 		// add the parameter to expression list
-		paramValue.setAllPositions(this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
+		paramValue.setParseInfo(this);
 		addVarParam(paramName,paramValue);
 	}
-	
-	public DataExpression(DataOp op, HashMap<String,Expression> varParams, 
-			String filename, int blp, int bcp, int elp, int ecp) {
+
+	public DataExpression(DataOp op, HashMap<String, Expression> varParams, ParseInfo parseInfo) {
+		_opcode = op;
+		_varParams = varParams;
+		setParseInfo(parseInfo);
+	}
+
+	public DataExpression(ParserRuleContext ctx, DataOp op, HashMap<String,Expression> varParams, 
+			String filename) {
 		_opcode = op;
 		_varParams = varParams;
-		setAllPositions(filename, blp, bcp, elp, ecp);
+		setCtxValuesAndFilename(ctx, filename);
 	}
 
 	public Expression rewriteExpression(String prefix) throws LanguageException {
@@ -392,9 +388,7 @@ public class DataExpression extends DataIdentifier
 			Expression newExpr = e.getValue().rewriteExpression(prefix);
 			newVarParams.put(key, newExpr);
 		}	
-		DataExpression retVal = new DataExpression(_opcode, newVarParams,
-				this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
-		
+		DataExpression retVal = new DataExpression(_opcode, newVarParams, this);
 		retVal._strInit = this._strInit;
 		
 		return retVal;
@@ -407,63 +401,44 @@ public class DataExpression extends DataIdentifier
 	 */
 	public void setMatrixDefault(){
 		if (getVarParam(RAND_BY_ROW) == null)
-			addVarParam(RAND_BY_ROW, new BooleanIdentifier(true,
-					this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-					this.getBeginLine(), this.getBeginColumn()));
+			addVarParam(RAND_BY_ROW, new BooleanIdentifier(true, this));
 	}
-	
-	public void setRandDefault(){
-		if (getVarParam(RAND_ROWS)== null){
-			IntIdentifier id = new IntIdentifier(1L,
-					this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-					this.getBeginLine(), this.getBeginColumn());
-			addVarParam(RAND_ROWS, 	id);
+
+	public void setRandDefault() {
+		if (getVarParam(RAND_ROWS) == null) {
+			IntIdentifier id = new IntIdentifier(1L, this);
+			addVarParam(RAND_ROWS, id);
 		}
-		if (getVarParam(RAND_COLS)== null){
-			IntIdentifier id = new IntIdentifier(1L,
-					this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-					this.getBeginLine(), this.getBeginColumn());
-            addVarParam(RAND_COLS, 	id);
+		if (getVarParam(RAND_COLS) == null) {
+			IntIdentifier id = new IntIdentifier(1L, this);
+			addVarParam(RAND_COLS, id);
 		}
-		if (getVarParam(RAND_MIN)== null){
-			DoubleIdentifier id = new DoubleIdentifier(0.0,
-					this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-					this.getBeginLine(), this.getBeginColumn());
+		if (getVarParam(RAND_MIN) == null) {
+			DoubleIdentifier id = new DoubleIdentifier(0.0, this);
 			addVarParam(RAND_MIN, id);
 		}
-		if (getVarParam(RAND_MAX)== null){
-			DoubleIdentifier id = new DoubleIdentifier(1.0,
-					this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-					this.getBeginLine(), this.getBeginColumn());
+		if (getVarParam(RAND_MAX) == null) {
+			DoubleIdentifier id = new DoubleIdentifier(1.0, this);
 			addVarParam(RAND_MAX, id);
 		}
-		if (getVarParam(RAND_SPARSITY)== null){
-			DoubleIdentifier id = new DoubleIdentifier(1.0,
-					this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-					this.getBeginLine(), this.getBeginColumn());
-			addVarParam(RAND_SPARSITY,	id);
+		if (getVarParam(RAND_SPARSITY) == null) {
+			DoubleIdentifier id = new DoubleIdentifier(1.0, this);
+			addVarParam(RAND_SPARSITY, id);
 		}
-		if (getVarParam(RAND_SEED)== null){
-			IntIdentifier id = new IntIdentifier(DataGenOp.UNSPECIFIED_SEED,
-					this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-					this.getBeginLine(), this.getBeginColumn());
+		if (getVarParam(RAND_SEED) == null) {
+			IntIdentifier id = new IntIdentifier(DataGenOp.UNSPECIFIED_SEED, this);
 			addVarParam(RAND_SEED, id);
 		}
-		if (getVarParam(RAND_PDF)== null){
-			StringIdentifier id = new StringIdentifier(RAND_PDF_UNIFORM,
-					this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-					this.getBeginLine(), this.getBeginColumn());
+		if (getVarParam(RAND_PDF) == null) {
+			StringIdentifier id = new StringIdentifier(RAND_PDF_UNIFORM, this);
 			addVarParam(RAND_PDF, id);
 		}
-		if (getVarParam(RAND_LAMBDA)== null){
-			DoubleIdentifier id = new DoubleIdentifier(1.0,
-					this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-					this.getBeginLine(), this.getBeginColumn());
+		if (getVarParam(RAND_LAMBDA) == null) {
+			DoubleIdentifier id = new DoubleIdentifier(1.0, this);
 			addVarParam(RAND_LAMBDA, id);
 		}
 	}
-	
-	
+
 	public void setOpCode(DataOp op) {
 		_opcode = op;
 	}
@@ -496,6 +471,7 @@ public class DataExpression extends DataIdentifier
 		if (getBeginColumn() == 0) 	setBeginColumn(value.getBeginColumn());
 		if (getEndLine() == 0) 		setEndLine(value.getEndLine());
 		if (getEndColumn() == 0) 	setEndColumn(value.getEndColumn());
+		if (getText() == null) setText(value.getText());
 		
 	}
 	
@@ -517,15 +493,13 @@ public class DataExpression extends DataIdentifier
 			Expression.BinaryOp op = expr.getOpCode();
 			switch (op){
 			case PLUS:
-					filename = "";
-					filename = fileNameCat(expr, currConstVars, filename, conditional);
-					// Since we have computed the value of filename, we update
-					// varParams with a const string value
-					StringIdentifier fileString = new StringIdentifier(filename, 
-							this.getFilename(), this.getBeginLine(), this.getBeginColumn(), 
-							this.getEndLine(), this.getEndColumn());
-					removeVarParam(IO_FILENAME);
-					addVarParam(IO_FILENAME, fileString);
+				filename = "";
+				filename = fileNameCat(expr, currConstVars, filename, conditional);
+				// Since we have computed the value of filename, we update
+				// varParams with a const string value
+				StringIdentifier fileString = new StringIdentifier(filename, this);
+				removeVarParam(IO_FILENAME);
+				addVarParam(IO_FILENAME, fileString);
 				break;
 			default:
 				raiseValidateError("for read method, parameter " + IO_FILENAME + " can only be const string concatenations. ", conditional);
@@ -634,7 +608,7 @@ public class DataExpression extends DataIdentifier
 			{
 				String fsext = InfrastructureAnalyzer.isLocalMode() ? "FS (local mode)" : "HDFS";
 				raiseValidateError("Read input file does not exist on "+fsext+": " + 
-						inputFileName, conditional, LanguageErrorCodes.INVALID_PARAMETERS);								
+						inputFileName, conditional);
 			}
 
 			// track whether format type has been inferred 
@@ -646,12 +620,9 @@ public class DataExpression extends DataIdentifier
 			// check if file is matrix market format
 			if (formatTypeString == null && shouldReadMTD){
 				boolean isMatrixMarketFormat = checkHasMatrixMarketFormat(inputFileName, mtdFileName, conditional); 
-				if (isMatrixMarketFormat){
-					
+				if (isMatrixMarketFormat) {
 					formatTypeString = FORMAT_TYPE_VALUE_MATRIXMARKET;
-					addVarParam(FORMAT_TYPE,new StringIdentifier(FORMAT_TYPE_VALUE_MATRIXMARKET,
-							this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-							this.getBeginLine(), this.getBeginColumn()));
+					addVarParam(FORMAT_TYPE, new StringIdentifier(FORMAT_TYPE_VALUE_MATRIXMARKET, this));
 					inferredFormatType = true;
 					shouldReadMTD = false;
 				}
@@ -661,14 +632,12 @@ public class DataExpression extends DataIdentifier
 			if (formatTypeString == null && shouldReadMTD ) {
 				boolean isDelimitedFormat = checkHasDelimitedFormat(inputFileName, conditional); 
 				
-				if (isDelimitedFormat){
-					addVarParam(FORMAT_TYPE,new StringIdentifier(FORMAT_TYPE_VALUE_CSV,
-							this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-							this.getBeginLine(), this.getBeginColumn()));
+				if (isDelimitedFormat) {
+					addVarParam(FORMAT_TYPE, new StringIdentifier(FORMAT_TYPE_VALUE_CSV, this));
 					formatTypeString = FORMAT_TYPE_VALUE_CSV;
 					inferredFormatType = true;
-					//shouldReadMTD = false;
-				}	
+					// shouldReadMTD = false;
+				}
 			}
 			
 				
@@ -724,40 +693,36 @@ public class DataExpression extends DataIdentifier
 						rowsCount = Long.parseLong(sizeInfo[0]);
 						if (rowsCount < 1)
 							throw new Exception("invalid rows count");
-						addVarParam(READROWPARAM, new IntIdentifier(rowsCount,
-								this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-								this.getBeginLine(), this.getBeginColumn()));
-					}
-					catch(Exception e){
-						raiseValidateError("In MatrixMarket file " + getVarParam(IO_FILENAME) 
-								+  " invalid row count " + sizeInfo[0] + " (must be long value >= 1). Sizing info line from file: " + headerLines[1], conditional, LanguageErrorCodes.INVALID_PARAMETERS);
+						addVarParam(READROWPARAM, new IntIdentifier(rowsCount, this));
+					} catch (Exception e) {
+						raiseValidateError(
+								"In MatrixMarket file " + getVarParam(IO_FILENAME) + " invalid row count " + sizeInfo[0]
+										+ " (must be long value >= 1). Sizing info line from file: " + headerLines[1],
+								conditional, LanguageErrorCodes.INVALID_PARAMETERS);
 					}
-				
+
 					try {
 						colsCount = Long.parseLong(sizeInfo[1]);
 						if (colsCount < 1)
 							throw new Exception("invalid cols count");
-						addVarParam(READCOLPARAM, new IntIdentifier(colsCount,
-								this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-								this.getBeginLine(), this.getBeginColumn()));
+						addVarParam(READCOLPARAM, new IntIdentifier(colsCount, this));
+					} catch (Exception e) {
+						raiseValidateError("In MatrixMarket file " + getVarParam(IO_FILENAME) + " invalid column count "
+								+ sizeInfo[1] + " (must be long value >= 1). Sizing info line from file: "
+								+ headerLines[1], conditional, LanguageErrorCodes.INVALID_PARAMETERS);
 					}
-					catch(Exception e){
-						raiseValidateError("In MatrixMarket file " + getVarParam(IO_FILENAME) 
-								+  " invalid column count " + sizeInfo[1] + " (must be long value >= 1). Sizing info line from file: " + headerLines[1], conditional, LanguageErrorCodes.INVALID_PARAMETERS);
-					}
-					
+
 					try {
 						nnzCount = Long.parseLong(sizeInfo[2]);
 						if (nnzCount < 1)
 							throw new Exception("invalid nnz count");
-						addVarParam("nnz", new IntIdentifier(nnzCount, 
-								this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-								this.getBeginLine(), this.getBeginColumn()));
+						addVarParam("nnz", new IntIdentifier(nnzCount, this));
+					} catch (Exception e) {
+						raiseValidateError("In MatrixMarket file " + getVarParam(IO_FILENAME)
+								+ " invalid number non-zeros " + sizeInfo[2]
+								+ " (must be long value >= 1). Sizing info line from file: " + headerLines[1],
+								conditional, LanguageErrorCodes.INVALID_PARAMETERS);
 					}
-					catch(Exception e){
-						raiseValidateError("In MatrixMarket file " + getVarParam(IO_FILENAME) 
-								+  " invalid number non-zeros " + sizeInfo[2] + " (must be long value >= 1). Sizing info line from file: " + headerLines[1], conditional, LanguageErrorCodes.INVALID_PARAMETERS);
-					}	
 				}
 			}
 			
@@ -816,12 +781,9 @@ public class DataExpression extends DataIdentifier
 				}
 				
 				// DEFAULT for "sep" : ","
-				if (getVarParam(DELIM_DELIMITER) == null){
-					addVarParam(DELIM_DELIMITER, new StringIdentifier(DEFAULT_DELIM_DELIMITER,
-							this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-							this.getBeginLine(), this.getBeginColumn()));
-				}
-				else {
+				if (getVarParam(DELIM_DELIMITER) == null) {
+					addVarParam(DELIM_DELIMITER, new StringIdentifier(DEFAULT_DELIM_DELIMITER, this));
+				} else {
 					if ( (getVarParam(DELIM_DELIMITER) instanceof ConstIdentifier)
 						&& (! (getVarParam(DELIM_DELIMITER) instanceof StringIdentifier)))
 					{
@@ -831,12 +793,9 @@ public class DataExpression extends DataIdentifier
 				} 
 				
 				// DEFAULT for "default": 0
-				if (getVarParam(DELIM_FILL_VALUE) == null){
-					addVarParam(DELIM_FILL_VALUE, new DoubleIdentifier(DEFAULT_DELIM_FILL_VALUE,
-							this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-							this.getBeginLine(), this.getBeginColumn()));
-				}
-				else {
+				if (getVarParam(DELIM_FILL_VALUE) == null) {
+					addVarParam(DELIM_FILL_VALUE, new DoubleIdentifier(DEFAULT_DELIM_FILL_VALUE, this));
+				} else {
 					if ( (getVarParam(DELIM_FILL_VALUE) instanceof ConstIdentifier)
 							&& (! (getVarParam(DELIM_FILL_VALUE) instanceof IntIdentifier ||  getVarParam(DELIM_FILL_VALUE) instanceof DoubleIdentifier)))
 					{
@@ -845,12 +804,9 @@ public class DataExpression extends DataIdentifier
 				} 
 				
 				// DEFAULT for "header": boolean false
-				if (getVarParam(DELIM_HAS_HEADER_ROW) == null){
-					addVarParam(DELIM_HAS_HEADER_ROW, new BooleanIdentifier(DEFAULT_DELIM_HAS_HEADER_ROW,
-							this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-							this.getBeginLine(), this.getBeginColumn()));
-				}
-				else {
+				if (getVarParam(DELIM_HAS_HEADER_ROW) == null) {
+					addVarParam(DELIM_HAS_HEADER_ROW, new BooleanIdentifier(DEFAULT_DELIM_HAS_HEADER_ROW, this));
+				} else {
 					if ((getVarParam(DELIM_HAS_HEADER_ROW) instanceof ConstIdentifier)
 						&& (! (getVarParam(DELIM_HAS_HEADER_ROW) instanceof BooleanIdentifier)))
 					{
@@ -860,9 +816,7 @@ public class DataExpression extends DataIdentifier
 				
 				// DEFAULT for "fill": boolean false
 				if (getVarParam(DELIM_FILL) == null){
-					addVarParam(DELIM_FILL,new BooleanIdentifier(DEFAULT_DELIM_FILL,
-							this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-							this.getBeginLine(), this.getBeginColumn()));
+					addVarParam(DELIM_FILL, new BooleanIdentifier(DEFAULT_DELIM_FILL, this));
 				}
 				else {
 					
@@ -1013,20 +967,14 @@ public class DataExpression extends DataIdentifier
 			
 			// for delimited format, if no delimiter specified THEN set default ","
 			if (getVarParam(FORMAT_TYPE) == null || getVarParam(FORMAT_TYPE).toString().equalsIgnoreCase(FORMAT_TYPE_VALUE_CSV)){
-				if (getVarParam(DELIM_DELIMITER) == null){
-					addVarParam(DELIM_DELIMITER, new StringIdentifier(DEFAULT_DELIM_DELIMITER,
-							this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-							this.getBeginLine(), this.getBeginColumn()));
+				if (getVarParam(DELIM_DELIMITER) == null) {
+					addVarParam(DELIM_DELIMITER, new StringIdentifier(DEFAULT_DELIM_DELIMITER, this));
 				}
-				if (getVarParam(DELIM_HAS_HEADER_ROW) == null){
-					addVarParam(DELIM_HAS_HEADER_ROW, new BooleanIdentifier(DEFAULT_DELIM_HAS_HEADER_ROW,
-							this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-							this.getBeginLine(), this.getBeginColumn()));
+				if (getVarParam(DELIM_HAS_HEADER_ROW) == null) {
+					addVarParam(DELIM_HAS_HEADER_ROW, new BooleanIdentifier(DEFAULT_DELIM_HAS_HEADER_ROW, this));
 				}
-				if (getVarParam(DELIM_SPARSE) == null){
-					addVarParam(DELIM_SPARSE, new BooleanIdentifier(DEFAULT_DELIM_SPARSE, 
-							this.getFilename(), this.getBeginLine(), this.getBeginColumn(),
-							this.getBeginLine(), this.getBeginColumn()));
+				if (getVarParam(DELIM_SPARSE) == null) {
+					addVarParam(DELIM_SPARSE, new BooleanIdentifier(DEFAULT_DELIM_SPARSE, this));
 				}
 			}
 			
@@ -1085,24 +1033,21 @@ public class DataExpression extends DataIdentifier
 				// handle integer constant 
 				else if (dataParam instanceof IntIdentifier) {
 					long roundedValue = ((IntIdentifier)dataParam).getValue();
-					Expression minExpr = new DoubleIdentifier(roundedValue, getFilename(), 
-							getBeginLine(), getBeginColumn(), getEndLine(), getEndColumn());
+					Expression minExpr = new DoubleIdentifier(roundedValue, this);
 					addVarParam(RAND_MIN, minExpr);
 					addVarParam(RAND_MAX, minExpr);
 				}
 				// handle double constant 
 				else if (dataParam instanceof DoubleIdentifier) {
 					double roundedValue = ((DoubleIdentifier)dataParam).getValue();
-					Expression minExpr = new DoubleIdentifier(roundedValue, getFilename(), 
-							getBeginLine(), getBeginColumn(), getEndLine(), getEndColumn());
+					Expression minExpr = new DoubleIdentifier(roundedValue, this);
 					addVarParam(RAND_MIN, minExpr);
-					addVarParam(RAND_MAX, minExpr);				
+					addVarParam(RAND_MAX, minExpr);
 				}
 				// handle string constant (string init) 
 				else if (dataParam instanceof StringIdentifier) {
 					String data = ((StringIdentifier)dataParam).getValue();
-					Expression minExpr = new StringIdentifier(data, getFilename(), 
-							getBeginLine(), getBeginColumn(), getEndLine(), getEndColumn());
+					Expression minExpr = new StringIdentifier(data, this);
 					addVarParam(RAND_MIN, minExpr);
 					addVarParam(RAND_MAX, minExpr);	
 					_strInit = true;
@@ -1210,9 +1155,7 @@ public class DataExpression extends DataIdentifier
 						}
 						// update row expr with new IntIdentifier 
 						long roundedValue = ((IntIdentifier)constValue).getValue();
-						rowsExpr = new IntIdentifier(roundedValue, this.getFilename(), 
-								this.getBeginLine(), this.getBeginColumn(), 
-								this.getEndLine(), this.getEndColumn());
+						rowsExpr = new IntIdentifier(roundedValue, this);
 						addVarParam(RAND_ROWS, rowsExpr);
 						rowsLong = roundedValue; 
 					}
@@ -1225,9 +1168,7 @@ public class DataExpression extends DataIdentifier
 						}
 						// update row expr with new IntIdentifier (rounded down)
 						long roundedValue = Double.valueOf(Math.floor(((DoubleIdentifier)constValue).getValue())).longValue();
-						rowsExpr = new IntIdentifier(roundedValue, this.getFilename(),
-								this.getBeginLine(), this.getBeginColumn(), 
-								this.getEndLine(), this.getEndColumn());
+						rowsExpr = new IntIdentifier(roundedValue, this);
 						addVarParam(RAND_ROWS, rowsExpr);
 						rowsLong = roundedValue; 
 						
@@ -1289,9 +1230,7 @@ public class DataExpression extends DataIdentifier
 						}
 						// update col expr with new IntIdentifier 
 						long roundedValue = ((IntIdentifier)constValue).getValue();
-						colsExpr = new IntIdentifier(roundedValue, this.getFilename(), 
-								this.getBeginLine(), this.getBeginColumn(), 
-								this.getEndLine(), this.getEndColumn());
+						colsExpr = new IntIdentifier(roundedValue, this);
 						addVarParam(RAND_COLS, colsExpr);
 						colsLong = roundedValue; 
 					}
@@ -1304,9 +1243,7 @@ public class DataExpression extends DataIdentifier
 						}
 						// update col expr with new IntIdentifier (rounded down)
 						long roundedValue = Double.valueOf(Math.floor(((DoubleIdentifier)constValue).getValue())).longValue();
-						colsExpr = new IntIdentifier(roundedValue, this.getFilename(), 
-								this.getBeginLine(), this.getBeginColumn(), 
-								this.getEndLine(), this.getEndColumn());
+						colsExpr = new IntIdentifier(roundedValue, this);
 						addVarParam(RAND_COLS, colsExpr);
 						colsLong = roundedValue; 
 						
@@ -1346,9 +1283,7 @@ public class DataExpression extends DataIdentifier
 						
 						// update min expr with new IntIdentifier 
 						long roundedValue = ((IntIdentifier)constValue).getValue();
-						minExpr = new DoubleIdentifier(roundedValue, this.getFilename(), 
-								this.getBeginLine(), this.getBeginColumn(), 
-								this.getEndLine(), this.getEndColumn());
+						minExpr = new DoubleIdentifier(roundedValue, this);
 						addVarParam(RAND_MIN, minExpr);
 					}
 					// handle double constant 
@@ -1356,9 +1291,7 @@ public class DataExpression extends DataIdentifier
 		
 						// update col expr with new IntIdentifier (rounded down)
 						double roundedValue = ((DoubleIdentifier)constValue).getValue();
-						minExpr = new DoubleIdentifier(roundedValue, this.getFilename(), 
-								this.getBeginLine(), this.getBeginColumn(), 
-								this.getEndLine(), this.getEndColumn());
+						minExpr = new DoubleIdentifier(roundedValue, this);
 						addVarParam(RAND_MIN, minExpr);
 						
 					}
@@ -1398,9 +1331,7 @@ public class DataExpression extends DataIdentifier
 						
 						// update min expr with new IntIdentifier 
 						long roundedValue = ((IntIdentifier)constValue).getValue();
-						maxExpr = new DoubleIdentifier(roundedValue, this.getFilename(), 
-								this.getBeginLine(), this.getBeginColumn(), 
-								this.getEndLine(), this.getEndColumn());
+						maxExpr = new DoubleIdentifier(roundedValue, this);
 						addVarParam(RAND_MAX, maxExpr);
 					}
 					// handle double constant 
@@ -1408,9 +1339,7 @@ public class DataExpression extends DataIdentifier
 		
 						// update col expr with new IntIdentifier (rounded down)
 						double roundedValue = ((DoubleIdentifier)constValue).getValue();
-						maxExpr = new DoubleIdentifier(roundedValue, this.getFilename(), 
-								this.getBeginLine(), this.getBeginColumn(), 
-								this.getEndLine(), this.getEndColumn());
+						maxExpr = new DoubleIdentifier(roundedValue, this);
 						addVarParam(RAND_MAX, maxExpr);
 						
 					}
@@ -1530,9 +1459,7 @@ public class DataExpression extends DataIdentifier
 							}
 							// update row expr with new IntIdentifier 
 							long roundedValue = ((IntIdentifier)constValue).getValue();
-							rowsExpr = new IntIdentifier(roundedValue, this.getFilename(), 
-									this.getBeginLine(), this.getBeginColumn(), 
-									this.getEndLine(), this.getEndColumn());
+							rowsExpr = new IntIdentifier(roundedValue, this);
 							addVarParam(RAND_ROWS, rowsExpr);
 							rowsLong = roundedValue; 
 						}
@@ -1545,9 +1472,7 @@ public class DataExpression extends DataIdentifier
 							}
 							// update row expr with new IntIdentifier (rounded down)
 							long roundedValue = Double.valueOf(Math.floor(((DoubleIdentifier)constValue).getValue())).longValue();
-							rowsExpr = new IntIdentifier(roundedValue,  this.getFilename(), 
-									this.getBeginLine(), this.getBeginColumn(), 
-									this.getEndLine(), this.getEndColumn());
+							rowsExpr = new IntIdentifier(roundedValue, this);
 							addVarParam(RAND_ROWS, rowsExpr);
 							rowsLong = roundedValue; 
 							
@@ -1611,9 +1536,7 @@ public class DataExpression extends DataIdentifier
 							}
 							// update col expr with new IntIdentifier 
 							long roundedValue = ((IntIdentifier)constValue).getValue();
-							colsExpr = new IntIdentifier(roundedValue, this.getFilename(), 
-									this.getBeginLine(), this.getBeginColumn(), 
-									this.getEndLine(), this.getEndColumn());
+							colsExpr = new IntIdentifier(roundedValue, this);
 							addVarParam(RAND_COLS, colsExpr);
 							colsLong = roundedValue; 
 						}
@@ -1627,9 +1550,7 @@ public class DataExpression extends DataIdentifier
 							}
 							// update col expr with new IntIdentifier (rounded down)
 							long roundedValue = Double.valueOf(Math.floor(((DoubleIdentifier)constValue).getValue())).longValue();
-							colsExpr = new IntIdentifier(roundedValue, this.getFilename(), 
-									this.getBeginLine(), this.getBeginColumn(), 
-									this.getEndLine(), this.getEndColumn());
+							colsExpr = new IntIdentifier(roundedValue, this);
 							addVarParam(RAND_COLS, colsExpr);
 							colsLong = roundedValue; 
 							
@@ -1813,23 +1734,21 @@ public class DataExpression extends DataIdentifier
 			}
 			
 			// if the read method parameter is a constant, then verify value matches MTD metadata file
-			if (getVarParam(key.toString()) != null && (getVarParam(key.toString()) instanceof ConstIdentifier) 
-					&& !getVarParam(key.toString()).toString().equalsIgnoreCase(val.toString()) )
-			{
-				raiseValidateError("parameter " + key.toString() + " has conflicting values in read statement definition and metadata. " +
-						"Config file value: " + val.toString() + " from MTD file.  Read statement value: " + getVarParam(key.toString()), conditional);
-			}
-			else 
-			{
+			if (getVarParam(key.toString()) != null && (getVarParam(key.toString()) instanceof ConstIdentifier)
+					&& !getVarParam(key.toString()).toString().equalsIgnoreCase(val.toString())) {
+				raiseValidateError(
+						"Parameter '" + key.toString()
+								+ "' has conflicting values in metadata and read statement. MTD file value: '"
+								+ val.toString() + "'. Read statement value: '" + getVarParam(key.toString()) + "'.",
+						conditional);
+			} else {
 				// if the read method does not specify parameter value, then add MTD metadata file value to parameter list
 				if (getVarParam(key.toString()) == null){
 					if (( !key.toString().equalsIgnoreCase(DESCRIPTIONPARAM) ) &&
 							( !key.toString().equalsIgnoreCase(AUTHORPARAM) ) &&
 							( !key.toString().equalsIgnoreCase(CREATEDPARAM) ) )
 					{
-						StringIdentifier strId = new StringIdentifier(val.toString(),
-								this.getFilename(), this.getBeginLine(), this.getBeginColumn(), 
-								this.getEndLine(), this.getEndColumn());
+						StringIdentifier strId = new StringIdentifier(val.toString(), this);
 						
 						if ( key.toString().equalsIgnoreCase(DELIM_HAS_HEADER_ROW) 
 								|| key.toString().equalsIgnoreCase(DELIM_FILL)
@@ -1837,17 +1756,11 @@ public class DataExpression extends DataIdentifier
 								) {
 							// parse these parameters as boolean values
 							BooleanIdentifier boolId = null; 
-							if ( strId.toString().equalsIgnoreCase("true") ) {
-								boolId = new BooleanIdentifier(true, this.getFilename(), 
-										this.getBeginLine(), this.getBeginColumn(), 
-										this.getEndLine(), this.getEndColumn());
-							}
-							else if ( strId.toString().equalsIgnoreCase("false") ) {
-								boolId = new BooleanIdentifier(false, this.getFilename(), 
-										this.getBeginLine(), this.getBeginColumn(), 
-										this.getEndLine(), this.getEndColumn());
-							}
-							else {
+							if (strId.toString().equalsIgnoreCase("true")) {
+								boolId = new BooleanIdentifier(true, this);
+							} else if (strId.toString().equalsIgnoreCase("false")) {
+								boolId = new BooleanIdentifier(false, this);
+							} else {
 								raiseValidateError("Invalid value provided for '" + DELIM_HAS_HEADER_ROW + "' in metadata file '" + mtdFileName + "'. "
 										+ "Must be either TRUE or FALSE.", conditional);
 							}
@@ -1856,9 +1769,8 @@ public class DataExpression extends DataIdentifier
 						}
 						else if ( key.toString().equalsIgnoreCase(DELIM_FILL_VALUE)) {
 							// parse these parameters as numeric values
-							DoubleIdentifier doubleId = new DoubleIdentifier( Double.parseDouble(strId.toString()),
-									this.getFilename(), this.getBeginLine(), this.getBeginColumn(), 
-									this.getEndLine(), this.getEndColumn());
+							DoubleIdentifier doubleId = new DoubleIdentifier(Double.parseDouble(strId.toString()),
+									this);
 							removeVarParam(key.toString());
 							addVarParam(key.toString(), doubleId);
 						}
@@ -1877,9 +1789,7 @@ public class DataExpression extends DataIdentifier
 								}
 								naStrings = sb.toString();
 							}
-							StringIdentifier sid = new StringIdentifier( naStrings,
-									this.getFilename(), this.getBeginLine(), this.getBeginColumn(), 
-									this.getEndLine(), this.getEndColumn());
+							StringIdentifier sid = new StringIdentifier(naStrings, this);
 							removeVarParam(key.toString());
 							addVarParam(key.toString(), sid);
 						}

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/DataIdentifier.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/DataIdentifier.java b/src/main/java/org/apache/sysml/parser/DataIdentifier.java
index 1cd00d1..5523cec 100644
--- a/src/main/java/org/apache/sysml/parser/DataIdentifier.java
+++ b/src/main/java/org/apache/sysml/parser/DataIdentifier.java
@@ -31,11 +31,7 @@ public class DataIdentifier extends Identifier
 		_valueTypeString = passed.getValueType().toString();	
 		
 		// set location information
-		setFilename(passed.getFilename());
-		setBeginLine(passed.getBeginLine());
-		setBeginColumn(passed.getBeginColumn());
-		setEndLine(passed.getEndLine());
-		setEndColumn(passed.getEndColumn());
+		setParseInfo(passed);
 	}
 	
 	public Expression rewriteExpression(String prefix) throws LanguageException{

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/DoubleIdentifier.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/DoubleIdentifier.java b/src/main/java/org/apache/sysml/parser/DoubleIdentifier.java
index febdbb4..b6c60fb 100644
--- a/src/main/java/org/apache/sysml/parser/DoubleIdentifier.java
+++ b/src/main/java/org/apache/sysml/parser/DoubleIdentifier.java
@@ -19,6 +19,7 @@
 
 package org.apache.sysml.parser;
 
+import org.antlr.v4.runtime.ParserRuleContext;
 import org.apache.sysml.runtime.util.UtilFunctions;
 
 
@@ -27,26 +28,39 @@ public class DoubleIdentifier extends ConstIdentifier
 {
 	
 	private double _val;
-	
-	
-	public DoubleIdentifier(double val, String filename, int blp, int bcp, int elp, int ecp){
+
+	public DoubleIdentifier(double val) {
 		super();
-		 _val = val;
-		setDimensions(0,0);
-        computeDataType();
-        setValueType(ValueType.DOUBLE);
-        setAllPositions(filename, blp, bcp, elp, ecp);
+		setInfo(val);
+		setBeginLine(-1);
+		setBeginColumn(-1);
+		setEndLine(-1);
+		setEndColumn(-1);
+		setText(null);
 	}
-	
-	public DoubleIdentifier(DoubleIdentifier d, String filename, int blp, int bcp, int elp, int ecp){
-		super();
-		 _val = d.getValue();
-		setDimensions(0,0);
-        computeDataType();
-        setValueType(ValueType.DOUBLE);
-        setAllPositions(filename, blp, bcp, elp, ecp);
+
+	public DoubleIdentifier(double val, ParseInfo parseInfo) {
+		this(val);
+		setParseInfo(parseInfo);
 	}
-	
+
+	public DoubleIdentifier(DoubleIdentifier d, ParseInfo parseInfo) {
+		this(d.getValue());
+		setParseInfo(parseInfo);
+	}
+
+	public DoubleIdentifier(ParserRuleContext ctx, double val, String filename) {
+		this(val);
+		setCtxValuesAndFilename(ctx, filename);
+	}
+
+	private void setInfo(double val) {
+		_val = val;
+		setDimensions(0, 0);
+		computeDataType();
+		setValueType(ValueType.DOUBLE);
+	}
+
 	public Expression rewriteExpression(String prefix) throws LanguageException{
 		return this;
 	}

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/Expression.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/Expression.java b/src/main/java/org/apache/sysml/parser/Expression.java
index e61a932..a68f59f 100644
--- a/src/main/java/org/apache/sysml/parser/Expression.java
+++ b/src/main/java/org/apache/sysml/parser/Expression.java
@@ -22,6 +22,8 @@ package org.apache.sysml.parser;
 import java.util.ArrayList;
 import java.util.HashMap;
 
+import org.antlr.v4.runtime.ParserRuleContext;
+import org.antlr.v4.runtime.misc.Interval;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -29,7 +31,7 @@ import org.apache.sysml.hops.Hop.FileFormatTypes;
 import org.apache.sysml.runtime.controlprogram.parfor.util.IDSequence;
 
 
-public abstract class Expression 
+public abstract class Expression implements ParseInfo
 {
 	/**
 	 * Binary operators.
@@ -518,28 +520,19 @@ public abstract class Expression
 	 * @param errorCode optional error code
 	 * @throws LanguageException thrown if conditional is {@code false}.
 	 */
-	public void raiseValidateError( String message, boolean conditional, String errorCode ) 
-		throws LanguageException
-	{
-		if( conditional )  //warning if conditional
-		{
-			String fullMsg = this.printWarningLocation() + message;
-			
-			LOG.warn( fullMsg );
-		}
-		else  //error and exception if unconditional
-		{
-			String fullMsg = this.printErrorLocation() + message;
-			
-			//LOG.error( fullMsg ); //no redundant error			
-			if( errorCode != null )
-				throw new LanguageException( fullMsg, errorCode );
-			else 
-				throw new LanguageException( fullMsg );
+	public void raiseValidateError(String msg, boolean conditional, String errorCode) throws LanguageException {
+		if (conditional) {// warning if conditional
+			String fullMsg = this.printWarningLocation() + msg;
+			LOG.warn(fullMsg);
+		} else {// error and exception if unconditional
+			String fullMsg = this.printErrorLocation() + msg;
+			if (errorCode != null)
+				throw new LanguageException(fullMsg, errorCode);
+			else
+				throw new LanguageException(fullMsg);
 		}
 	}
-	
-	
+
 	/**
 	 * Returns the matrix characteristics for scalar-scalar, scalar-matrix, matrix-scalar, matrix-matrix
 	 * operations. This method is aware of potentially unknowns and matrix-vector (col/row) operations.
@@ -597,6 +590,7 @@ public abstract class Expression
 	private String _filename;
 	private int _beginLine, _beginColumn;
 	private int _endLine, _endColumn;
+	private String _text;
 	private ArrayList<String> _parseExceptionList = new ArrayList<String>();
 	
 	public void setFilename(String passed)  { _filename = passed;   }
@@ -604,50 +598,110 @@ public abstract class Expression
 	public void setBeginColumn(int passed) 	{ _beginColumn = passed; }
 	public void setEndLine(int passed) 		{ _endLine = passed;   }
 	public void setEndColumn(int passed)	{ _endColumn = passed; }
+	public void setText(String text) { _text = text; }
 	public void setParseExceptionList(ArrayList<String> passed) { _parseExceptionList = passed;}
-	
+
 	/**
-	 * Set the filename, the beginning line/column positions, and the ending line/column positions.
-	 * 
-	 * @param filename The DML/PYDML filename (if it exists)
-	 * @param blp Beginning line position
-	 * @param bcp Beginning column position
-	 * @param elp Ending line position
-	 * @param ecp Ending column position
+	 * Set parse information.
+	 *
+	 * @param parseInfo
+	 *            parse information, such as beginning line position, beginning
+	 *            column position, ending line position, ending column position,
+	 *            text, and filename
+	 * @param filename
+	 *            the DML/PYDML filename (if it exists)
+	 */
+	public void setParseInfo(ParseInfo parseInfo) {
+		_beginLine = parseInfo.getBeginLine();
+		_beginColumn = parseInfo.getBeginColumn();
+		_endLine = parseInfo.getEndLine();
+		_endColumn = parseInfo.getEndColumn();
+		_text = parseInfo.getText();
+		_filename = parseInfo.getFilename();
+	}
+
+	/**
+	 * Set ParserRuleContext values (begin line, begin column, end line, end
+	 * column, and text).
+	 *
+	 * @param ctx
+	 *            the antlr ParserRuleContext
+	 */
+	public void setCtxValues(ParserRuleContext ctx) {
+		setBeginLine(ctx.start.getLine());
+		setBeginColumn(ctx.start.getCharPositionInLine());
+		setEndLine(ctx.stop.getLine());
+		setEndColumn(ctx.stop.getCharPositionInLine());
+		// preserve whitespace if possible
+		if ((ctx.start != null) && (ctx.stop != null) && (ctx.start.getStartIndex() != -1)
+				&& (ctx.stop.getStopIndex() != -1) && (ctx.start.getStartIndex() <= ctx.stop.getStopIndex())
+				&& (ctx.start.getInputStream() != null)) {
+			String text = ctx.start.getInputStream()
+					.getText(Interval.of(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
+			if (text != null) {
+				text = text.trim();
+			}
+			setText(text);
+		} else {
+			String text = ctx.getText();
+			if (text != null) {
+				text = text.trim();
+			}
+			setText(text);
+		}
+	}
+
+	/**
+	 * Set ParserRuleContext values (begin line, begin column, end line, end
+	 * column, and text) and file name.
+	 *
+	 * @param ctx
+	 *            the antlr ParserRuleContext
+	 * @param filename
+	 *            the filename (if it exists)
 	 */
-	public void setAllPositions(String filename, int blp, int bcp, int elp, int ecp){
-		_filename    = filename;
-		_beginLine	 = blp; 
-		_beginColumn = bcp; 
-		_endLine 	 = elp;
-		_endColumn 	 = ecp;
+	public void setCtxValuesAndFilename(ParserRuleContext ctx, String filename) {
+		setCtxValues(ctx);
+		setFilename(filename);
 	}
 
+
 	public String getFilename()	{ return _filename;   }
 	public int getBeginLine()	{ return _beginLine;   }
 	public int getBeginColumn() { return _beginColumn; }
 	public int getEndLine() 	{ return _endLine;   }
 	public int getEndColumn()	{ return _endColumn; }
+	public String getText() { return _text; }
 	public ArrayList<String> getParseExceptionList() { return _parseExceptionList; }
-	
-	/**
-	 * Return error message containing the filename, the beginning line position, and the beginning column position.
-	 * 
-	 * @return the error message
-	 */
-	public String printErrorLocation(){
-		return "ERROR: " + _filename + " -- line " + _beginLine + ", column " + _beginColumn + " -- ";
+
+	public String printErrorLocation() {
+		String file = _filename;
+		if (file == null) {
+			file = "";
+		} else {
+			file = file + " ";
+		}
+		if (getText() != null) {
+			return "ERROR: " + file + "[line " + _beginLine + ":" + _beginColumn + "] -> " + getText() + " -- ";
+		} else {
+			return "ERROR: " + file + "[line " + _beginLine + ":" + _beginColumn + "] -- ";
+		}
 	}
-	
-	/**
-	 * Return warning message containing the filename, the beginning line position, and the beginning column position.
-	 * 
-	 * @return the warning message
-	 */
-	public String printWarningLocation(){
-		return "WARNING: " + _filename + " -- line " + _beginLine + ", column " + _beginColumn + " -- ";
+
+	public String printWarningLocation() {
+		String file = _filename;
+		if (file == null) {
+			file = "";
+		} else {
+			file = file + " ";
+		}
+		if (getText() != null) {
+			return "WARNING: " + file + "[line " + _beginLine + ":" + _beginColumn + "] -> " + getText() + " -- ";
+		} else {
+			return "WARNING: " + file + "[line " + _beginLine + ":" + _beginColumn + "] -- ";
+		}
 	}
-	
+
 	/**
 	 * Return info message containing the filename, the beginning line position, and the beginning column position.
 	 * 

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/ForStatementBlock.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/ForStatementBlock.java b/src/main/java/org/apache/sysml/parser/ForStatementBlock.java
index 782b682..29358db 100644
--- a/src/main/java/org/apache/sysml/parser/ForStatementBlock.java
+++ b/src/main/java/org/apache/sysml/parser/ForStatementBlock.java
@@ -376,31 +376,24 @@ public class ForStatementBlock extends StatementBlock
 		if (expr instanceof DataIdentifier && !(expr instanceof IndexedIdentifier)) 
 		{	
 			// check if the DataIdentifier variable is a ConstIdentifier
-			String identifierName = ((DataIdentifier)expr).getName();
-			if (currConstVars.containsKey(identifierName))
-			{
+			String identifierName = ((DataIdentifier) expr).getName();
+			if (currConstVars.containsKey(identifierName)) {
 				ConstIdentifier constValue = currConstVars.get(identifierName);
-				//AUTO CASTING (using runtime operations for consistency)
-				switch( constValue.getValueType() ) 
-				{
-					case DOUBLE: 
-						ret = new IntIdentifier(new DoubleObject(((DoubleIdentifier)constValue).getValue()).getLongValue(),
-								expr.getFilename(), expr.getBeginLine(), expr.getBeginColumn(), 
-								expr.getEndLine(), expr.getEndColumn());
-						break;
-					case INT:    
-						ret = new IntIdentifier((IntIdentifier)constValue,
-								expr.getFilename(), expr.getBeginLine(), expr.getBeginColumn(), 
-								expr.getEndLine(), expr.getEndColumn());
-						break;
-					case BOOLEAN: 
-						ret = new IntIdentifier(new BooleanObject(((BooleanIdentifier)constValue).getValue()).getLongValue(),
-								expr.getFilename(), expr.getBeginLine(), expr.getBeginColumn(), 
-								expr.getEndLine(), expr.getEndColumn());
-						break;
-						
-					default:
-						//do nothing
+				// AUTO CASTING (using runtime operations for consistency)
+				switch (constValue.getValueType()) {
+				case DOUBLE:
+					ret = new IntIdentifier(new DoubleObject(((DoubleIdentifier) constValue).getValue()).getLongValue(),
+							expr);
+					break;
+				case INT:
+					ret = new IntIdentifier((IntIdentifier) constValue, expr);
+					break;
+				case BOOLEAN:
+					ret = new IntIdentifier(
+							new BooleanObject(((BooleanIdentifier) constValue).getValue()).getLongValue(), expr);
+					break;
+				default:
+					// do nothing
 				}
 			}
 		}

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/FunctionCallIdentifier.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/FunctionCallIdentifier.java b/src/main/java/org/apache/sysml/parser/FunctionCallIdentifier.java
index f720840..5993091 100644
--- a/src/main/java/org/apache/sysml/parser/FunctionCallIdentifier.java
+++ b/src/main/java/org/apache/sysml/parser/FunctionCallIdentifier.java
@@ -60,11 +60,7 @@ public class FunctionCallIdentifier extends DataIdentifier
 		
 		// rewrite each output expression
 		FunctionCallIdentifier fci = new FunctionCallIdentifier(newParameterExpressions);
-		
-		fci.setBeginLine(this.getBeginLine());
-		fci.setBeginColumn(this.getBeginColumn());
-		fci.setEndLine(this.getEndLine());
-		fci.setEndColumn(this.getEndColumn());
+		fci.setParseInfo(this);
 			
 		fci._name = this._name;
 		fci._namespace = this._namespace;

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/FunctionStatementBlock.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/FunctionStatementBlock.java b/src/main/java/org/apache/sysml/parser/FunctionStatementBlock.java
index cd2bea7..833ecfa 100644
--- a/src/main/java/org/apache/sysml/parser/FunctionStatementBlock.java
+++ b/src/main/java/org/apache/sysml/parser/FunctionStatementBlock.java
@@ -110,9 +110,8 @@ public class FunctionStatementBlock extends StatementBlock
 							if (curr.getValueType() == ValueType.INT){
 								IntIdentifier currIntValue = (IntIdentifier)constVars.get(curr.getName());
 								if (currIntValue != null){
-									DoubleIdentifier currDoubleValue = new DoubleIdentifier(currIntValue.getValue(), 
-											curr.getFilename(), curr.getBeginLine(), curr.getBeginColumn(), 
-											curr.getEndLine(), curr.getEndColumn());
+									DoubleIdentifier currDoubleValue = new DoubleIdentifier(currIntValue.getValue(),
+											curr);
 									constVars.put(curr.getName(), currDoubleValue);
 								}
 								LOG.warn(curr.printWarningLocation() + "for function " + fstmt.getName() 

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/IndexedIdentifier.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/IndexedIdentifier.java b/src/main/java/org/apache/sysml/parser/IndexedIdentifier.java
index 0fda2f9..cb870af 100644
--- a/src/main/java/org/apache/sysml/parser/IndexedIdentifier.java
+++ b/src/main/java/org/apache/sysml/parser/IndexedIdentifier.java
@@ -146,16 +146,10 @@ public class IndexedIdentifier extends DataIdentifier
 					}	
 					
 					if (validRowLB) {
-						if (constValue instanceof IntIdentifier){
-							_rowLowerBound = new IntIdentifier((IntIdentifier)constValue,
-									constValue.getFilename(), constValue.getBeginLine(), constValue.getBeginColumn(), 
-									constValue.getEndLine(), constValue.getEndColumn());
-							
-						}
-						else{
-							_rowLowerBound = new DoubleIdentifier((DoubleIdentifier)constValue, 
-									constValue.getFilename(), constValue.getBeginLine(), constValue.getBeginColumn(), 
-									constValue.getEndLine(), constValue.getEndColumn());
+						if (constValue instanceof IntIdentifier) {
+							_rowLowerBound = new IntIdentifier((IntIdentifier) constValue, constValue);
+						} else {
+							_rowLowerBound = new DoubleIdentifier((DoubleIdentifier) constValue, constValue);
 						}
 						isConst_rowLowerBound = true;
 					}
@@ -237,19 +231,12 @@ public class IndexedIdentifier extends DataIdentifier
 								+ rowLB_1 + " May cause runtime exception");
 						validRowUB = false;
 					}
-					
+
 					if (validRowUB) {
-						if (constValue instanceof IntIdentifier){
-							_rowUpperBound = new IntIdentifier((IntIdentifier)constValue, 
-									constValue.getFilename(), constValue.getBeginLine(), 
-									constValue.getBeginColumn(), constValue.getEndLine(), 
-									constValue.getEndColumn());
-						}
-						else{
-							_rowUpperBound = new DoubleIdentifier((DoubleIdentifier)constValue, 
-									constValue.getFilename(), constValue.getBeginLine(), 
-									constValue.getBeginColumn(), constValue.getEndLine(), 
-									constValue.getEndColumn());
+						if (constValue instanceof IntIdentifier) {
+							_rowUpperBound = new IntIdentifier((IntIdentifier) constValue, constValue);
+						} else {
+							_rowUpperBound = new DoubleIdentifier((DoubleIdentifier) constValue, constValue);
 						}
 						isConst_rowUpperBound = true;
 					}
@@ -316,19 +303,12 @@ public class IndexedIdentifier extends DataIdentifier
 								+ ": " + this.getOrigDim2() +")");
 						validColLB = false;
 					}	
-					
+
 					if (validColLB) {
-						if (constValue instanceof IntIdentifier){
-							_colLowerBound = new IntIdentifier((IntIdentifier)constValue, 
-									constValue.getFilename(), constValue.getBeginLine(), 
-									constValue.getBeginColumn(), constValue.getEndLine(), 
-									constValue.getEndColumn());
-						}
-						else{
-							_colLowerBound = new DoubleIdentifier((DoubleIdentifier)constValue, 
-									constValue.getFilename(), constValue.getBeginLine(), 
-									constValue.getBeginColumn(), constValue.getEndLine(), 
-									constValue.getEndColumn());
+						if (constValue instanceof IntIdentifier) {
+							_colLowerBound = new IntIdentifier((IntIdentifier) constValue, constValue);
+						} else {
+							_colLowerBound = new DoubleIdentifier((DoubleIdentifier) constValue, constValue);
 						}
 						isConst_colLowerBound = true;
 					}
@@ -420,19 +400,12 @@ public class IndexedIdentifier extends DataIdentifier
 					+ " May cause runtime exception");
 						validColUB = false;
 					}
-					
+
 					if (validColUB) {
-						if (constValue instanceof IntIdentifier){
-							_colUpperBound = new IntIdentifier((IntIdentifier)constValue, 
-									constValue.getFilename(), constValue.getBeginLine(), 
-									constValue.getBeginColumn(), constValue.getEndLine(), 
-									constValue.getEndColumn());
-						}
-						else{
-							_colUpperBound = new DoubleIdentifier((DoubleIdentifier)constValue, 
-									constValue.getFilename(), constValue.getBeginLine(), 
-									constValue.getBeginColumn(), constValue.getEndLine(), 
-									constValue.getEndColumn());
+						if (constValue instanceof IntIdentifier) {
+							_colUpperBound = new IntIdentifier((IntIdentifier) constValue, constValue);
+						} else {
+							_colUpperBound = new DoubleIdentifier((DoubleIdentifier) constValue, constValue);
 						}
 						isConst_colUpperBound = true;
 					}
@@ -557,12 +530,7 @@ public class IndexedIdentifier extends DataIdentifier
 	public Expression rewriteExpression(String prefix) throws LanguageException {
 		
 		IndexedIdentifier newIndexedIdentifier = new IndexedIdentifier(this.getName(), this._rowLowerEqualsUpper, this._colLowerEqualsUpper);
-		
-		newIndexedIdentifier.setFilename(getFilename());
-		newIndexedIdentifier.setBeginLine(this.getBeginLine());
-		newIndexedIdentifier.setBeginColumn(this.getBeginColumn());
-		newIndexedIdentifier.setEndLine(this.getEndLine());
-		newIndexedIdentifier.setEndColumn(this.getEndColumn());
+		newIndexedIdentifier.setParseInfo(this);
 			
 		// set dimensionality information and other Identifier specific properties for new IndexedIdentifier
 		newIndexedIdentifier.setProperties(this);

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/IntIdentifier.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/IntIdentifier.java b/src/main/java/org/apache/sysml/parser/IntIdentifier.java
index 60463e6..d07fbef 100644
--- a/src/main/java/org/apache/sysml/parser/IntIdentifier.java
+++ b/src/main/java/org/apache/sysml/parser/IntIdentifier.java
@@ -19,7 +19,7 @@
 
 package org.apache.sysml.parser;
 
-
+import org.antlr.v4.runtime.ParserRuleContext;
 
 public class IntIdentifier extends ConstIdentifier 
 {
@@ -29,25 +29,39 @@ public class IntIdentifier extends ConstIdentifier
 	public Expression rewriteExpression(String prefix) throws LanguageException{
 		return this;
 	}
-	
-	public IntIdentifier(long val, String filename, int blp, int bcp, int elp, int ecp){
+
+	public IntIdentifier(long val) {
 		super();
-		 _val = val;
-		setDimensions(0,0);
-        computeDataType();
-        setValueType(ValueType.INT);
-        setAllPositions(filename, blp, bcp, elp, ecp);
+		setInfo(val);
+		setBeginLine(-1);
+		setBeginColumn(-1);
+		setEndLine(-1);
+		setEndColumn(-1);
+		setText(null);
 	}
-	
-	public IntIdentifier(IntIdentifier i, String filename, int blp, int bcp, int elp, int ecp){
-		super();
-		 _val = i.getValue();
-		setDimensions(0,0);
-        computeDataType();
-        setValueType(ValueType.INT);
-        setAllPositions(filename, blp, bcp, elp, ecp);
+
+	public IntIdentifier(long val, ParseInfo parseInfo) {
+		this(val);
+		setParseInfo(parseInfo);
 	}
-	
+
+	public IntIdentifier(IntIdentifier i, ParseInfo parseInfo) {
+		this(i.getValue());
+		setParseInfo(parseInfo);
+	}
+
+	public IntIdentifier(ParserRuleContext ctx, long val, String filename) {
+		this(val);
+		setCtxValuesAndFilename(ctx, filename);
+	}
+
+	private void setInfo(long val) {
+		_val = val;
+		setDimensions(0, 0);
+		computeDataType();
+		setValueType(ValueType.INT);
+	}
+
 	// Used only by the parser for unary operation
 	public void multiplyByMinusOne() {
 		_val = -1 * _val;

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/IterablePredicate.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/IterablePredicate.java b/src/main/java/org/apache/sysml/parser/IterablePredicate.java
index 86562fb..19fcc4a 100644
--- a/src/main/java/org/apache/sysml/parser/IterablePredicate.java
+++ b/src/main/java/org/apache/sysml/parser/IterablePredicate.java
@@ -21,6 +21,7 @@ package org.apache.sysml.parser;
 
 import java.util.HashMap;
 
+import org.antlr.v4.runtime.ParserRuleContext;
 import org.apache.sysml.lops.Lop;
 
 
@@ -33,20 +34,17 @@ public class IterablePredicate extends Expression
 	private Expression _incrementExpr;
 	private HashMap<String,String> _parforParams;
 	
-	
-	public IterablePredicate(DataIdentifier iterVar, Expression fromExpr, Expression toExpr, 
-			Expression incrementExpr, HashMap<String,String> parForParamValues,
-			String filename, int blp, int bcp, int elp, int ecp)
-	{
+	public IterablePredicate(ParserRuleContext ctx, DataIdentifier iterVar, Expression fromExpr, Expression toExpr,
+			Expression incrementExpr, HashMap<String, String> parForParamValues, String filename) {
 		_iterVar = iterVar;
 		_fromExpr = fromExpr;
 		_toExpr = toExpr;
 		_incrementExpr = incrementExpr;
-		
+
 		_parforParams = parForParamValues;
-		this.setAllPositions(filename, blp, bcp, elp, ecp);
+		this.setCtxValuesAndFilename(ctx, filename);
 	}
-		
+
 	public String toString()
 	{ 
 		StringBuilder sb = new StringBuilder();
@@ -133,14 +131,12 @@ public class IterablePredicate extends Expression
 		
 		//2) VALIDATE FOR PREDICATE in (from, to, increment)		
 		// handle default increment if unspecified
-		if( _incrementExpr == null && _fromExpr instanceof ConstIdentifier 
-			&& _toExpr instanceof ConstIdentifier ) {
+		if (_incrementExpr == null && _fromExpr instanceof ConstIdentifier && _toExpr instanceof ConstIdentifier) {
 			ConstIdentifier cFrom = (ConstIdentifier) _fromExpr;
 			ConstIdentifier cTo = (ConstIdentifier) _toExpr;
-			_incrementExpr = new IntIdentifier( (cFrom.getLongValue() <= cTo.getLongValue()) ? 1 : -1, 
-					getFilename(), getBeginLine(), getBeginColumn(), getEndLine(), getEndColumn());
+			_incrementExpr = new IntIdentifier((cFrom.getLongValue() <= cTo.getLongValue()) ? 1 : -1, this);
 		}
-		
+
 		//recursively validate the individual expression
 		_fromExpr.validateExpression(ids, constVars, conditional);
 		_toExpr.validateExpression(ids, constVars, conditional);

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/MultiAssignmentStatement.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/MultiAssignmentStatement.java b/src/main/java/org/apache/sysml/parser/MultiAssignmentStatement.java
index c8446f9..1174e27 100644
--- a/src/main/java/org/apache/sysml/parser/MultiAssignmentStatement.java
+++ b/src/main/java/org/apache/sysml/parser/MultiAssignmentStatement.java
@@ -48,10 +48,7 @@ public class MultiAssignmentStatement extends Statement
 		
 		// create rewritten assignment statement (deep copy)
 		MultiAssignmentStatement retVal = new MultiAssignmentStatement(newTargetList, newSource);
-		retVal.setBeginLine(this.getBeginLine());
-		retVal.setBeginColumn(this.getBeginColumn());
-		retVal.setEndLine(this.getEndLine());
-		retVal.setEndColumn(this.getEndColumn());
+		retVal.setParseInfo(this);
 		
 		return retVal;
 	}

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/OutputStatement.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/OutputStatement.java b/src/main/java/org/apache/sysml/parser/OutputStatement.java
index 00859be..a93f508 100644
--- a/src/main/java/org/apache/sysml/parser/OutputStatement.java
+++ b/src/main/java/org/apache/sysml/parser/OutputStatement.java
@@ -21,6 +21,7 @@ package org.apache.sysml.parser;
 
 import java.util.HashMap;
 
+import org.antlr.v4.runtime.ParserRuleContext;
 import org.apache.sysml.api.DMLScript;
 import org.apache.sysml.debug.DMLBreakpointManager;
 import org.apache.sysml.parser.Expression.DataOp;
@@ -49,12 +50,15 @@ public class OutputStatement extends Statement
 	public void setIdentifier(DataIdentifier t) {
 		_id = t;
 	}
-	
-	public OutputStatement(DataIdentifier t, DataOp op, 
-			String filename, int blp, int bcp, int elp, int ecp){
+
+	public OutputStatement(ParserRuleContext ctx, DataIdentifier t, DataOp op, String filename) {
+		_id = t;
+		_paramsExpr = new DataExpression(ctx, op, new HashMap<String, Expression>(), filename);
+	}
+
+	public OutputStatement(DataIdentifier t, DataOp op, ParseInfo parseInfo) {
 		_id = t;
-		_paramsExpr = new DataExpression(op, new HashMap<String,Expression>(),
-				filename, blp, bcp, elp, ecp);
+		_paramsExpr = new DataExpression(op, new HashMap<String, Expression>(), parseInfo);
 	}
 
 	public static boolean isValidParamName(String key){
@@ -78,10 +82,9 @@ public class OutputStatement extends Statement
 	
 	// rewrites statement to support function inlining (create deep copy)
 	public Statement rewriteStatement(String prefix) throws LanguageException{
-		
-		OutputStatement newStatement = new OutputStatement(null,Expression.DataOp.WRITE,
-				this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
-		
+
+		OutputStatement newStatement = new OutputStatement(null, Expression.DataOp.WRITE, this);
+
 		// rewrite outputStatement variable name (creates deep copy)
 		newStatement._id = (DataIdentifier)this._id.rewriteExpression(prefix);
 		
@@ -92,8 +95,7 @@ public class OutputStatement extends Statement
 			Expression newExpr = _paramsExpr.getVarParam(key).rewriteExpression(prefix);
 			newExprParams.put(key, newExpr);
 		}
-		DataExpression newParamerizedExpr = new DataExpression(op, newExprParams,
-				this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
+		DataExpression newParamerizedExpr = new DataExpression(op, newExprParams, this);
 		newStatement.setExprParams(newParamerizedExpr);
 		return newStatement;
 	}

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/ParameterizedBuiltinFunctionExpression.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/ParameterizedBuiltinFunctionExpression.java b/src/main/java/org/apache/sysml/parser/ParameterizedBuiltinFunctionExpression.java
index 2768cc1..1e28aed 100644
--- a/src/main/java/org/apache/sysml/parser/ParameterizedBuiltinFunctionExpression.java
+++ b/src/main/java/org/apache/sysml/parser/ParameterizedBuiltinFunctionExpression.java
@@ -24,6 +24,7 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 
+import org.antlr.v4.runtime.ParserRuleContext;
 import org.apache.sysml.hops.Hop.ParamBuiltinOp;
 import org.apache.sysml.parser.LanguageException.LanguageErrorCodes;
 import org.apache.wink.json4j.JSONObject;
@@ -104,8 +105,8 @@ public class ParameterizedBuiltinFunctionExpression extends DataIdentifier
 		pbHopMap.put(Expression.ParameterizedBuiltinFunctionOp.TOSTRING, ParamBuiltinOp.TOSTRING);
 	}
 	
-	public static ParameterizedBuiltinFunctionExpression getParamBuiltinFunctionExpression(String functionName, 
-			ArrayList<ParameterExpression> paramExprsPassed, String fileName, int blp, int bcp, int elp, int ecp){
+	public static ParameterizedBuiltinFunctionExpression getParamBuiltinFunctionExpression(ParserRuleContext ctx,
+			String functionName, ArrayList<ParameterExpression> paramExprsPassed, String fileName) {
 		if (functionName == null || paramExprsPassed == null)
 			return null;
 		
@@ -118,17 +119,24 @@ public class ParameterizedBuiltinFunctionExpression extends DataIdentifier
 		for (ParameterExpression pexpr : paramExprsPassed)
 			varParams.put(pexpr.getName(), pexpr.getExpr());
 		
-		ParameterizedBuiltinFunctionExpression retVal = new ParameterizedBuiltinFunctionExpression(pbifop,varParams,
-				fileName, blp, bcp, elp, ecp);
+		ParameterizedBuiltinFunctionExpression retVal = new ParameterizedBuiltinFunctionExpression(ctx, pbifop,
+				varParams, fileName);
 		return retVal;
 	}
 	
 			
-	public ParameterizedBuiltinFunctionExpression(ParameterizedBuiltinFunctionOp op, HashMap<String,Expression> varParams,
-			String filename, int blp, int bcp, int elp, int ecp) {
+	public ParameterizedBuiltinFunctionExpression(ParserRuleContext ctx, ParameterizedBuiltinFunctionOp op, HashMap<String,Expression> varParams,
+			String filename) {
 		_opcode = op;
 		_varParams = varParams;
-		setAllPositions(filename, blp, bcp, elp, ecp);
+		setCtxValuesAndFilename(ctx, filename);
+	}
+
+	public ParameterizedBuiltinFunctionExpression(ParameterizedBuiltinFunctionOp op,
+			HashMap<String, Expression> varParams, ParseInfo parseInfo) {
+		_opcode = op;
+		_varParams = varParams;
+		setParseInfo(parseInfo);
 	}
 
 	public Expression rewriteExpression(String prefix) throws LanguageException {
@@ -138,9 +146,9 @@ public class ParameterizedBuiltinFunctionExpression extends DataIdentifier
 			Expression newExpr = _varParams.get(key).rewriteExpression(prefix);
 			newVarParams.put(key, newExpr);
 		}	
-		ParameterizedBuiltinFunctionExpression retVal = new ParameterizedBuiltinFunctionExpression(_opcode, newVarParams,
-				this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
-	
+		ParameterizedBuiltinFunctionExpression retVal = new ParameterizedBuiltinFunctionExpression(_opcode,
+				newVarParams, this);
+
 		return retVal;
 	}
 
@@ -263,7 +271,7 @@ public class ParameterizedBuiltinFunctionExpression extends DataIdentifier
 		int count = 0;
 		for (DataIdentifier outParam: stmt.getTargetList()){
 			DataIdentifier tmp = new DataIdentifier(outParam);
-			tmp.setAllPositions(this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
+			tmp.setParseInfo(this);
 			_outputs[count++] = tmp;
 		}
 		
@@ -412,7 +420,7 @@ public class ParameterizedBuiltinFunctionExpression extends DataIdentifier
 		
 		Expression orderby = getVarParam("by"); //[OPTIONAL] BY
 		if( orderby == null ) { //default first column, good fit for vectors
-			orderby = new IntIdentifier(1, "1", -1, -1, -1, -1);
+			orderby = new IntIdentifier(1);
 			addVarParam("by", orderby);
 		}
 		else if( orderby !=null && orderby.getOutput().getDataType() != DataType.SCALAR ){				
@@ -421,7 +429,7 @@ public class ParameterizedBuiltinFunctionExpression extends DataIdentifier
 		
 		Expression decreasing = getVarParam("decreasing"); //[OPTIONAL] DECREASING
 		if( decreasing == null ) { //default: ascending
-			addVarParam("decreasing", new BooleanIdentifier(false, "false", -1, -1, -1, -1));
+			addVarParam("decreasing", new BooleanIdentifier(false));
 		}
 		else if( decreasing!=null && decreasing.getOutput().getDataType() != DataType.SCALAR ){				
 			raiseValidateError("Ordering 'decreasing' is of type '"+decreasing.getOutput().getDataType()+"', '"+decreasing.getOutput().getValueType()+"'. Please, specify 'decreasing' as a scalar boolean.", conditional, LanguageErrorCodes.INVALID_PARAMETERS);
@@ -429,7 +437,7 @@ public class ParameterizedBuiltinFunctionExpression extends DataIdentifier
 		
 		Expression indexreturn = getVarParam("index.return"); //[OPTIONAL] DECREASING
 		if( indexreturn == null ) { //default: sorted data
-			indexreturn = new BooleanIdentifier(false, "false", -1, -1, -1, -1);
+			indexreturn = new BooleanIdentifier(false);
 			addVarParam("index.return", indexreturn);
 		}
 		else if( indexreturn!=null && indexreturn.getOutput().getDataType() != DataType.SCALAR ){				

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/ParseInfo.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/ParseInfo.java b/src/main/java/org/apache/sysml/parser/ParseInfo.java
new file mode 100644
index 0000000..366624b
--- /dev/null
+++ b/src/main/java/org/apache/sysml/parser/ParseInfo.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysml.parser;
+
+import org.antlr.v4.runtime.ParserRuleContext;
+import org.antlr.v4.runtime.misc.Interval;
+
+public interface ParseInfo {
+
+	public void setBeginLine(int beginLine);
+
+	public void setBeginColumn(int beginColumn);
+
+	public void setEndLine(int endLine);
+
+	public void setEndColumn(int endColumn);
+
+	public void setText(String text);
+	
+	public void setFilename(String filename);
+
+	public int getBeginLine();
+
+	public int getBeginColumn();
+
+	public int getEndLine();
+
+	public int getEndColumn();
+
+	public String getText();
+	
+	public String getFilename();
+
+	public static ParseInfo ctxAndFilenameToParseInfo(ParserRuleContext ctx, String filename) {
+		ParseInfo pi = new ParseInfo() {
+			private int beginLine;
+			private int beginColumn;
+			private int endLine;
+			private int endColumn;
+			private String text;
+			private String filename;
+
+			@Override
+			public void setBeginLine(int beginLine) {
+				this.beginLine = beginLine;
+			}
+
+			@Override
+			public void setBeginColumn(int beginColumn) {
+				this.beginColumn = beginColumn;
+			}
+
+			@Override
+			public void setEndLine(int endLine) {
+				this.endLine = endLine;
+			}
+
+			@Override
+			public void setEndColumn(int endColumn) {
+				this.endColumn = endColumn;
+			}
+
+			@Override
+			public void setText(String text) {
+				this.text = text;
+			}
+
+			@Override
+			public void setFilename(String filename) {
+				this.filename = filename;
+			}
+			@Override
+			public int getBeginLine() {
+				return beginLine;
+			}
+
+			@Override
+			public int getBeginColumn() {
+				return beginColumn;
+			}
+
+			@Override
+			public int getEndLine() {
+				return endLine;
+			}
+
+			@Override
+			public int getEndColumn() {
+				return endColumn;
+			}
+
+			@Override
+			public String getText() {
+				return text;
+			}
+			
+			@Override
+			public String getFilename() {
+				return filename;
+			}
+		};
+		pi.setBeginLine(ctx.start.getLine());
+		pi.setBeginColumn(ctx.start.getCharPositionInLine());
+		pi.setEndLine(ctx.stop.getLine());
+		pi.setEndColumn(ctx.stop.getCharPositionInLine());
+		// preserve whitespace if possible
+		if ((ctx.start != null) && (ctx.stop != null) && (ctx.start.getStartIndex() != -1)
+				&& (ctx.stop.getStopIndex() != -1) && (ctx.start.getStartIndex() <= ctx.stop.getStopIndex())
+				&& (ctx.start.getInputStream() != null)) {
+			String text = ctx.start.getInputStream()
+					.getText(Interval.of(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
+			if (text != null) {
+				text = text.trim();
+			}
+			pi.setText(text);
+		} else {
+			String text = ctx.getText();
+			if (text != null) {
+				text = text.trim();
+			}
+			pi.setText(text);
+		}
+		pi.setFilename(filename);
+		return pi;
+	}
+}

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/PrintStatement.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/PrintStatement.java b/src/main/java/org/apache/sysml/parser/PrintStatement.java
index 0193553..16e9e4a 100644
--- a/src/main/java/org/apache/sysml/parser/PrintStatement.java
+++ b/src/main/java/org/apache/sysml/parser/PrintStatement.java
@@ -22,6 +22,7 @@ package org.apache.sysml.parser;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.antlr.v4.runtime.ParserRuleContext;
 import org.apache.sysml.api.DMLScript;
 import org.apache.sysml.debug.DMLBreakpointManager;
 
@@ -43,7 +44,7 @@ public class PrintStatement extends Statement
 
 	private static PRINTTYPE getPrintType(String type, List<Expression> expressions) throws LanguageException {
 		if(type.equalsIgnoreCase("print")) {
-			if (expressions.size() == 1) {
+			if ((expressions == null) || (expressions.size() == 1)) {
 				return PRINTTYPE.PRINT;
 			} else {
 				return PRINTTYPE.PRINTF;
@@ -56,20 +57,28 @@ public class PrintStatement extends Statement
 			throw new LanguageException("Unknown statement type: " + type);
 	}
 
-	public PrintStatement(String type, List<Expression> expressions, int beginLine, int beginCol,
-			int endLine, int endCol) throws LanguageException {
-		this(getPrintType(type, expressions), expressions);
+	public PrintStatement(ParserRuleContext ctx, String type, String filename)
+			throws LanguageException {
+		this(getPrintType(type, null), null);
+		setCtxValues(ctx);
+		setFilename(filename);
+	}
 
-		setBeginLine(beginLine);
-		setBeginColumn(beginCol);
-		setEndLine(endLine);
-		setEndColumn(endCol);
+	public PrintStatement(ParserRuleContext ctx, String type, List<Expression> expressions, String filename)
+			throws LanguageException {
+		this(getPrintType(type, expressions), expressions);
+		setCtxValues(ctx);
+		setFilename(filename);
 	}
 
 	public PrintStatement(PRINTTYPE type, List<Expression> expressions)
 			throws LanguageException {
 		_type = type;
-		this.expressions = expressions;
+		if (expressions == null) {
+			this.expressions = new ArrayList<Expression>();
+		} else {
+			this.expressions = expressions;
+		}
 	}
 
 	public Statement rewriteStatement(String prefix) throws LanguageException{
@@ -79,11 +88,7 @@ public class PrintStatement extends Statement
 			newExpressions.add(newExpression);
 		}
 		PrintStatement retVal = new PrintStatement(_type, newExpressions);
-		retVal.setBeginLine(this.getBeginLine());
-		retVal.setBeginColumn(this.getBeginColumn());
-		retVal.setEndLine(this.getEndLine());
-		retVal.setEndColumn(this.getEndColumn());
-		
+		retVal.setParseInfo(this);
 		return retVal;
 	}
 	

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/RelationalExpression.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/RelationalExpression.java b/src/main/java/org/apache/sysml/parser/RelationalExpression.java
index 48666d0..8a82b1e 100644
--- a/src/main/java/org/apache/sysml/parser/RelationalExpression.java
+++ b/src/main/java/org/apache/sysml/parser/RelationalExpression.java
@@ -37,26 +37,21 @@ public class RelationalExpression extends Expression
 		setBeginColumn(0);
 		setEndLine(0);
 		setEndColumn(0);
+		setText(null);
 	}
-	
-	public RelationalExpression(RelationalOp bop, String filename, int beginLine, int beginColumn, int endLine, int endColumn) {
+
+	public RelationalExpression(RelationalOp bop, ParseInfo parseInfo) {
 		_opcode = bop;
-		
-		setFilename(filename);
-		setBeginLine(beginLine);
-		setBeginColumn(beginColumn);
-		setEndLine(endLine);
-		setEndColumn(endColumn);
+		setParseInfo(parseInfo);
 	}
-	
-	public Expression rewriteExpression(String prefix) throws LanguageException{
-		
-		RelationalExpression newExpr = new RelationalExpression(this._opcode, getFilename(), getBeginLine(), getBeginColumn(), getEndLine(), getEndColumn());
+
+	public Expression rewriteExpression(String prefix) throws LanguageException {
+		RelationalExpression newExpr = new RelationalExpression(this._opcode, this);
 		newExpr.setLeft(_left.rewriteExpression(prefix));
 		newExpr.setRight(_right.rewriteExpression(prefix));
 		return newExpr;
 	}
-	
+
 	public RelationalOp getOpCode(){
 		return _opcode;
 	}
@@ -65,22 +60,18 @@ public class RelationalExpression extends Expression
 		_left = l;
 		
 		// update script location information --> left expression is BEFORE in script
-		if (_left != null){
-			setFilename(_left.getFilename());
-			setBeginLine(_left.getBeginLine());
-			setBeginColumn(_left.getBeginColumn());
+		if (_left != null) {
+			setParseInfo(_left);
 		}
-		
+
 	}
 	
 	public void setRight(Expression r){
 		_right = r;
 		
 		// update script location information --> right expression is AFTER in script
-		if (_right != null){
-			setFilename(_right.getFilename());
-			setBeginLine(_right.getEndLine());
-			setBeginColumn(_right.getEndColumn());
+		if (_right != null) {
+			setParseInfo(_right);
 		}
 	}
 	
@@ -110,23 +101,24 @@ public class RelationalExpression extends Expression
 		}
 		
 		// handle <NUMERIC> == <BOOLEAN> --> convert <BOOLEAN> to numeric value
-		if ((_left != null && _left instanceof BooleanIdentifier) || (_right != null && _right instanceof BooleanIdentifier)){
-			if ((_left instanceof IntIdentifier || _left instanceof DoubleIdentifier) || _right instanceof IntIdentifier || _right instanceof DoubleIdentifier){
-				if (_left instanceof BooleanIdentifier){
+		if ((_left != null && _left instanceof BooleanIdentifier)
+				|| (_right != null && _right instanceof BooleanIdentifier)) {
+			if ((_left instanceof IntIdentifier || _left instanceof DoubleIdentifier) || _right instanceof IntIdentifier
+					|| _right instanceof DoubleIdentifier) {
+				if (_left instanceof BooleanIdentifier) {
 					if (((BooleanIdentifier) _left).getValue())
-						this.setLeft(new IntIdentifier(1, _left.getFilename(), _left.getBeginLine(), _left.getBeginColumn(), _left.getEndLine(), _left.getEndColumn()));
+						this.setLeft(new IntIdentifier(1, _left));
 					else
-						this.setLeft(new IntIdentifier(0, _left.getFilename(), _left.getBeginLine(), _left.getBeginColumn(), _left.getEndLine(), _left.getEndColumn()));
-				}
-				else if (_right instanceof BooleanIdentifier){
+						this.setLeft(new IntIdentifier(0, _left));
+				} else if (_right instanceof BooleanIdentifier) {
 					if (((BooleanIdentifier) _right).getValue())
-						this.setRight(new IntIdentifier(1, _right.getFilename(), _right.getBeginLine(), _right.getBeginColumn(), _right.getEndLine(),_right.getEndColumn()));
+						this.setRight(new IntIdentifier(1, _right));
 					else
-						this.setRight(new IntIdentifier(0,  _right.getFilename(), _right.getBeginLine(), _right.getBeginColumn(), _right.getEndLine(),_right.getEndColumn()));
+						this.setRight(new IntIdentifier(0, _right));
 				}
 			}
 		}
-		
+
 		//recursive validate
 		_left.validateExpression(ids, constVars, conditional);
 		if( _right !=null )
@@ -140,7 +132,7 @@ public class RelationalExpression extends Expression
 		
 		String outputName = getTempName();
 		DataIdentifier output = new DataIdentifier(outputName);
-		output.setAllPositions(this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
+		output.setParseInfo(this);
 		
 		boolean isLeftMatrix = (_left.getOutput() != null && _left.getOutput().getDataType() == DataType.MATRIX);
 		boolean isRightMatrix = (_right.getOutput() != null && _right.getOutput().getDataType() == DataType.MATRIX); 


[3/3] systemml git commit: [SYSTEMML-1858] Allow parsed text in validation errors

Posted by de...@apache.org.
[SYSTEMML-1858] Allow parsed text in validation errors

Add parsed text from original script into objects such as Statements
and Expressions so that it is available in validation errors.
Improve several validation error messages.

Closes #635.


Project: http://git-wip-us.apache.org/repos/asf/systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/c495533b
Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/c495533b
Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/c495533b

Branch: refs/heads/master
Commit: c495533b6570c27450b34623523c12acb1f86575
Parents: f1d35b7
Author: Deron Eriksson <de...@apache.org>
Authored: Wed Aug 23 16:30:37 2017 -0700
Committer: Deron Eriksson <de...@apache.org>
Committed: Thu Aug 24 16:36:17 2017 -0700

----------------------------------------------------------------------
 .../apache/sysml/api/mlcontext/MLContext.java   |  36 +-
 src/main/java/org/apache/sysml/hops/Hop.java    |  35 +-
 .../sysml/hops/rewrite/HopRewriteUtils.java     |   8 +-
 .../RewriteInjectSparkLoopCheckpointing.java    |   2 +-
 .../RewriteSplitDagDataDependentOperators.java  |   2 +-
 .../rewrite/RewriteSplitDagUnknownCSVRead.java  |   2 +-
 .../sysml/parser/AssignmentStatement.java       |  47 ++-
 .../apache/sysml/parser/BinaryExpression.java   |  55 ++-
 .../apache/sysml/parser/BooleanExpression.java  |  43 +-
 .../apache/sysml/parser/BooleanIdentifier.java  |  36 +-
 .../sysml/parser/BuiltinFunctionExpression.java | 100 ++---
 .../sysml/parser/ConditionalPredicate.java      |   5 +-
 .../org/apache/sysml/parser/DMLTranslator.java  | 155 ++++---
 .../org/apache/sysml/parser/DataExpression.java | 412 ++++++++-----------
 .../org/apache/sysml/parser/DataIdentifier.java |   6 +-
 .../apache/sysml/parser/DoubleIdentifier.java   |  48 ++-
 .../org/apache/sysml/parser/Expression.java     | 158 ++++---
 .../apache/sysml/parser/ForStatementBlock.java  |  41 +-
 .../sysml/parser/FunctionCallIdentifier.java    |   6 +-
 .../sysml/parser/FunctionStatementBlock.java    |   5 +-
 .../apache/sysml/parser/IndexedIdentifier.java  |  72 +---
 .../org/apache/sysml/parser/IntIdentifier.java  |  48 ++-
 .../apache/sysml/parser/IterablePredicate.java  |  22 +-
 .../sysml/parser/MultiAssignmentStatement.java  |   5 +-
 .../apache/sysml/parser/OutputStatement.java    |  24 +-
 .../ParameterizedBuiltinFunctionExpression.java |  36 +-
 .../java/org/apache/sysml/parser/ParseInfo.java | 143 +++++++
 .../org/apache/sysml/parser/PrintStatement.java |  33 +-
 .../sysml/parser/RelationalExpression.java      |  58 ++-
 .../java/org/apache/sysml/parser/Statement.java | 146 +++++--
 .../org/apache/sysml/parser/StatementBlock.java |  95 +++--
 .../apache/sysml/parser/StringIdentifier.java   |  30 +-
 .../parser/common/CommonSyntacticValidator.java | 131 ++----
 .../parser/common/CustomErrorListener.java      |  20 +
 .../sysml/parser/dml/DmlSyntacticValidator.java |  30 +-
 .../parser/pydml/PydmlSyntacticValidator.java   |  92 ++---
 .../runtime/controlprogram/ProgramBlock.java    |  34 +-
 .../controlprogram/parfor/ProgramConverter.java |   8 +-
 .../functions/misc/OuterTableExpandTest.java    |   2 +-
 39 files changed, 1181 insertions(+), 1050 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java b/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java
index f74d593..83eedb3 100644
--- a/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java
+++ b/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java
@@ -534,39 +534,27 @@ public class MLContext {
 				if (datatype.compareToIgnoreCase("frame") != 0) {
 					MatrixObject mo = getMatrixObject(target);
 					if (mo != null) {
-						int blp = source.getBeginLine();
-						int bcp = source.getBeginColumn();
-						int elp = source.getEndLine();
-						int ecp = source.getEndColumn();
-						exp.addVarParam(DataExpression.READROWPARAM,
-								new IntIdentifier(mo.getNumRows(), source.getFilename(), blp, bcp, elp, ecp));
-						exp.addVarParam(DataExpression.READCOLPARAM,
-								new IntIdentifier(mo.getNumColumns(), source.getFilename(), blp, bcp, elp, ecp));
-						exp.addVarParam(DataExpression.READNUMNONZEROPARAM,
-								new IntIdentifier(mo.getNnz(), source.getFilename(), blp, bcp, elp, ecp));
-						exp.addVarParam(DataExpression.DATATYPEPARAM,
-								new StringIdentifier("matrix", source.getFilename(), blp, bcp, elp, ecp));
-						exp.addVarParam(DataExpression.VALUETYPEPARAM,
-								new StringIdentifier("double", source.getFilename(), blp, bcp, elp, ecp));
+						exp.addVarParam(DataExpression.READROWPARAM, new IntIdentifier(mo.getNumRows(), source));
+						exp.addVarParam(DataExpression.READCOLPARAM, new IntIdentifier(mo.getNumColumns(), source));
+						exp.addVarParam(DataExpression.READNUMNONZEROPARAM, new IntIdentifier(mo.getNnz(), source));
+						exp.addVarParam(DataExpression.DATATYPEPARAM, new StringIdentifier("matrix", source));
+						exp.addVarParam(DataExpression.VALUETYPEPARAM, new StringIdentifier("double", source));
 
 						if (mo.getMetaData() instanceof MatrixFormatMetaData) {
 							MatrixFormatMetaData metaData = (MatrixFormatMetaData) mo.getMetaData();
 							if (metaData.getOutputInfo() == OutputInfo.CSVOutputInfo) {
 								exp.addVarParam(DataExpression.FORMAT_TYPE,
-										new StringIdentifier(DataExpression.FORMAT_TYPE_VALUE_CSV, source.getFilename(),
-												blp, bcp, elp, ecp));
+										new StringIdentifier(DataExpression.FORMAT_TYPE_VALUE_CSV, source));
 							} else if (metaData.getOutputInfo() == OutputInfo.TextCellOutputInfo) {
 								exp.addVarParam(DataExpression.FORMAT_TYPE,
-										new StringIdentifier(DataExpression.FORMAT_TYPE_VALUE_TEXT,
-												source.getFilename(), blp, bcp, elp, ecp));
+										new StringIdentifier(DataExpression.FORMAT_TYPE_VALUE_TEXT, source));
 							} else if (metaData.getOutputInfo() == OutputInfo.BinaryBlockOutputInfo) {
-								exp.addVarParam(DataExpression.ROWBLOCKCOUNTPARAM, new IntIdentifier(
-										mo.getNumRowsPerBlock(), source.getFilename(), blp, bcp, elp, ecp));
-								exp.addVarParam(DataExpression.COLUMNBLOCKCOUNTPARAM, new IntIdentifier(
-										mo.getNumColumnsPerBlock(), source.getFilename(), blp, bcp, elp, ecp));
+								exp.addVarParam(DataExpression.ROWBLOCKCOUNTPARAM,
+										new IntIdentifier(mo.getNumRowsPerBlock(), source));
+								exp.addVarParam(DataExpression.COLUMNBLOCKCOUNTPARAM,
+										new IntIdentifier(mo.getNumColumnsPerBlock(), source));
 								exp.addVarParam(DataExpression.FORMAT_TYPE,
-										new StringIdentifier(DataExpression.FORMAT_TYPE_VALUE_BINARY,
-												source.getFilename(), blp, bcp, elp, ecp));
+										new StringIdentifier(DataExpression.FORMAT_TYPE_VALUE_BINARY, source));
 							} else {
 								throw new MLContextException("Unsupported format through MLContext");
 							}

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/hops/Hop.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/Hop.java b/src/main/java/org/apache/sysml/hops/Hop.java
index 2d9b1bf..b48e227 100644
--- a/src/main/java/org/apache/sysml/hops/Hop.java
+++ b/src/main/java/org/apache/sysml/hops/Hop.java
@@ -42,6 +42,7 @@ import org.apache.sysml.lops.ReBlock;
 import org.apache.sysml.lops.UnaryCP;
 import org.apache.sysml.parser.Expression.DataType;
 import org.apache.sysml.parser.Expression.ValueType;
+import org.apache.sysml.parser.ParseInfo;
 import org.apache.sysml.runtime.controlprogram.LocalVariableMap;
 import org.apache.sysml.runtime.controlprogram.caching.MatrixObject.UpdateType;
 import org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext;
@@ -52,7 +53,7 @@ import org.apache.sysml.runtime.matrix.data.MatrixBlock;
 import org.apache.sysml.runtime.util.UtilFunctions;
 
 
-public abstract class Hop 
+public abstract class Hop implements ParseInfo
 {
 	protected static final Log LOG =  LogFactory.getLog(Hop.class.getName());
 	
@@ -1820,26 +1821,21 @@ public abstract class Hop
 	public int _beginLine, _beginColumn;
 	public int _endLine, _endColumn;
 	public String _filename;
+	public String _text;
 	
 	public void setBeginLine(int passed)    { _beginLine = passed;   }
 	public void setBeginColumn(int passed) 	{ _beginColumn = passed; }
 	public void setEndLine(int passed) 		{ _endLine = passed;   }
 	public void setEndColumn(int passed)	{ _endColumn = passed; }
 	public void setFilename(String passed) { _filename = passed; }
-	
-	public void setAllPositions(String filename, int blp, int bcp, int elp, int ecp){
-		_filename = filename;
-		_beginLine	 = blp; 
-		_beginColumn = bcp; 
-		_endLine 	 = elp;
-		_endColumn 	 = ecp;
-	}
+	public void setText(String text) { _text = text; }
 
 	public int getBeginLine()	{ return _beginLine;   }
 	public int getBeginColumn() { return _beginColumn; }
 	public int getEndLine() 	{ return _endLine;   }
 	public int getEndColumn()	{ return _endColumn; }
 	public String getFilename()	{ return _filename; }
+	public String getText() { return _text; }
 	
 	public String printErrorLocation(){
 		if(_filename != null)
@@ -1857,5 +1853,24 @@ public abstract class Hop
 	{
 		lop.setAllPositions(this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
 	}
-	
+
+	/**
+	 * Set parse information.
+	 *
+	 * @param parseInfo
+	 *            parse information, such as beginning line position, beginning
+	 *            column position, ending line position, ending column position,
+	 *            text, and filename
+	 * @param filename
+	 *            the DML/PYDML filename (if it exists)
+	 */
+	public void setParseInfo(ParseInfo parseInfo) {
+		_beginLine = parseInfo.getBeginLine();
+		_beginColumn = parseInfo.getBeginColumn();
+		_endLine = parseInfo.getEndLine();
+		_endColumn = parseInfo.getEndColumn();
+		_text = parseInfo.getText();
+		_filename = parseInfo.getFilename();
+	}
+
 } // end class

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java b/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
index 5a3b9aa..914e0cb 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
@@ -656,11 +656,11 @@ public class HopRewriteUtils
 		hnew.setOutputBlocksizes(hold.getRowsInBlock(), hold.getColsInBlock());
 		hnew.refreshSizeInformation();
 	}
-	
-	public static void copyLineNumbers( Hop src, Hop dest ) {
-		dest.setAllPositions(src.getFilename(), src.getBeginLine(), src.getBeginColumn(), src.getEndLine(), src.getEndColumn());
+
+	public static void copyLineNumbers(Hop src, Hop dest) {
+		dest.setParseInfo(src);
 	}
-	
+
 	public static void updateHopCharacteristics( Hop hop, long brlen, long bclen, Hop src )
 	{
 		updateHopCharacteristics(hop, brlen, bclen, new MemoTable(), src);

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/hops/rewrite/RewriteInjectSparkLoopCheckpointing.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/RewriteInjectSparkLoopCheckpointing.java b/src/main/java/org/apache/sysml/hops/rewrite/RewriteInjectSparkLoopCheckpointing.java
index 1c59e6e..876b162 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/RewriteInjectSparkLoopCheckpointing.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/RewriteInjectSparkLoopCheckpointing.java
@@ -89,7 +89,7 @@ public class RewriteInjectSparkLoopCheckpointing extends StatementBlockRewriteRu
 			{
 				StatementBlock sb0 = new StatementBlock();
 				sb0.setDMLProg(sb.getDMLProg());
-				sb0.setAllPositions(sb.getFilename(), sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
+				sb0.setParseInfo(sb);
 				ArrayList<Hop> hops = new ArrayList<Hop>();
 				VariableSet livein = new VariableSet();
 				VariableSet liveout = new VariableSet();

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagDataDependentOperators.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagDataDependentOperators.java b/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagDataDependentOperators.java
index 351cf87..1f49500 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagDataDependentOperators.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagDataDependentOperators.java
@@ -97,7 +97,7 @@ public class RewriteSplitDagDataDependentOperators extends StatementBlockRewrite
 				//duplicate sb incl live variable sets
 				StatementBlock sb1 = new StatementBlock();
 				sb1.setDMLProg(sb.getDMLProg());
-				sb1.setAllPositions(sb.getFilename(), sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
+				sb1.setParseInfo(sb);
 				sb1.setLiveIn(new VariableSet());
 				sb1.setLiveOut(new VariableSet());
 				

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagUnknownCSVRead.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagUnknownCSVRead.java b/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagUnknownCSVRead.java
index 6d9942f..ef8d9dc 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagUnknownCSVRead.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagUnknownCSVRead.java
@@ -67,7 +67,7 @@ public class RewriteSplitDagUnknownCSVRead extends StatementBlockRewriteRule
 				//duplicate sb incl live variable sets
 				StatementBlock sb1 = new StatementBlock();
 				sb1.setDMLProg(sb.getDMLProg());
-				sb1.setAllPositions(sb.getFilename(), sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
+				sb1.setParseInfo(sb);
 				sb1.setLiveIn(new VariableSet());
 				sb1.setLiveOut(new VariableSet());
 				

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/AssignmentStatement.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/AssignmentStatement.java b/src/main/java/org/apache/sysml/parser/AssignmentStatement.java
index b59887b..2df4ed0 100644
--- a/src/main/java/org/apache/sysml/parser/AssignmentStatement.java
+++ b/src/main/java/org/apache/sysml/parser/AssignmentStatement.java
@@ -21,6 +21,7 @@ package org.apache.sysml.parser;
 
 import java.util.ArrayList;
 
+import org.antlr.v4.runtime.ParserRuleContext;
 import org.apache.sysml.api.DMLScript;
 import org.apache.sysml.debug.DMLBreakpointManager;
 
@@ -32,35 +33,39 @@ public class AssignmentStatement extends Statement
 	private Expression _source;
 	 
 	// rewrites statement to support function inlining (creates deep copy)
-	public Statement rewriteStatement(String prefix) throws LanguageException{
-				
+	public Statement rewriteStatement(String prefix) throws LanguageException {
+
 		// rewrite target (deep copy)
-		DataIdentifier newTarget = (DataIdentifier)_targetList.get(0).rewriteExpression(prefix);
-		
+		DataIdentifier newTarget = (DataIdentifier) _targetList.get(0).rewriteExpression(prefix);
+
 		// rewrite source (deep copy)
 		Expression newSource = _source.rewriteExpression(prefix);
-		
+
 		// create rewritten assignment statement (deep copy)
-		AssignmentStatement retVal = new AssignmentStatement(newTarget, newSource,this.getBeginLine(), 
-											this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
-		
+		AssignmentStatement retVal = new AssignmentStatement(newTarget, newSource, this);
+
 		return retVal;
 	}
-	
-	public AssignmentStatement(DataIdentifier t, Expression s, int beginLine, int beginCol, int endLine, int endCol) 
-		throws LanguageException
-	{	
+
+	public AssignmentStatement(DataIdentifier di, Expression exp, ParseInfo parseInfo) {
 		_targetList = new ArrayList<DataIdentifier>();
-		_targetList.add(t);
-		_source = s;
-	
-		setBeginLine(beginLine);
-		setBeginColumn(beginCol);
-		setEndLine(endLine);
-		setEndColumn(endCol);
-		
+		_targetList.add(di);
+		_source = exp;
+		setParseInfo(parseInfo);
 	}
-	
+
+	public AssignmentStatement(ParserRuleContext ctx, DataIdentifier di, Expression exp) throws LanguageException {
+		_targetList = new ArrayList<DataIdentifier>();
+		_targetList.add(di);
+		_source = exp;
+		setCtxValues(ctx);
+	}
+
+	public AssignmentStatement(ParserRuleContext ctx, DataIdentifier di, Expression exp, String filename) throws LanguageException {
+		this(ctx, di, exp);
+		setFilename(filename);
+	}
+
 	public DataIdentifier getTarget(){
 		return _targetList.get(0);
 	}

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/BinaryExpression.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/BinaryExpression.java b/src/main/java/org/apache/sysml/parser/BinaryExpression.java
index 121e488..68678e7 100644
--- a/src/main/java/org/apache/sysml/parser/BinaryExpression.java
+++ b/src/main/java/org/apache/sysml/parser/BinaryExpression.java
@@ -29,8 +29,7 @@ public class BinaryExpression extends Expression
 	private BinaryOp _opcode;
 	
 	public Expression rewriteExpression(String prefix) throws LanguageException{
-		BinaryExpression newExpr = new BinaryExpression(this._opcode,
-				this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
+		BinaryExpression newExpr = new BinaryExpression(this._opcode, this);
 		newExpr.setLeft(_left.rewriteExpression(prefix));
 		newExpr.setRight(_right.rewriteExpression(prefix));
 		return newExpr;
@@ -44,18 +43,13 @@ public class BinaryExpression extends Expression
 		setBeginColumn(0);
 		setEndLine(0);
 		setEndColumn(0);
+		setText(null);
 	}
-	
-	public BinaryExpression(BinaryOp bop, String filename, int beginLine, int beginColumn, int endLine, int endColumn) {
+
+	public BinaryExpression(BinaryOp bop, ParseInfo parseInfo) {
 		_opcode = bop;
-		
-		setFilename(filename);
-		setBeginLine(beginLine);
-		setBeginColumn(beginColumn);
-		setEndLine(endLine);
-		setEndColumn(endColumn);
+		setParseInfo(parseInfo);
 	}
-	
 
 	public BinaryOp getOpCode() {
 		return _opcode;
@@ -66,9 +60,7 @@ public class BinaryExpression extends Expression
 		
 		// update script location information --> left expression is BEFORE in script
 		if (_left != null){
-			setFilename(_left.getFilename());
-			setBeginLine(_left.getBeginLine());
-			setBeginColumn(_left.getBeginColumn());
+			setParseInfo(_left);
 		}
 		
 	}
@@ -78,9 +70,7 @@ public class BinaryExpression extends Expression
 		
 		// update script location information --> right expression is AFTER in script
 		if (_right != null){
-			setFilename(_right.getFilename());
-			setBeginLine(_right.getEndLine());
-			setBeginColumn(_right.getEndColumn());
+			setParseInfo(_right);
 		}
 	}
 
@@ -103,11 +93,11 @@ public class BinaryExpression extends Expression
 			throws LanguageException 
 	{	
 		//recursive validate
-		if (_left instanceof FunctionCallIdentifier || _right instanceof FunctionCallIdentifier){
-			raiseValidateError("user-defined function calls not supported in binary expressions", 
-		            false, LanguageException.LanguageErrorCodes.UNSUPPORTED_EXPRESSION);
+		if (_left instanceof FunctionCallIdentifier || _right instanceof FunctionCallIdentifier) {
+			raiseValidateError("User-defined function calls not supported in binary expressions.", false,
+					LanguageException.LanguageErrorCodes.UNSUPPORTED_EXPRESSION);
 		}
-			
+
 		_left.validateExpression(ids, constVars, conditional);
 		_right.validateExpression(ids, constVars, conditional);
 		
@@ -120,7 +110,7 @@ public class BinaryExpression extends Expression
 		
 		String outputName = getTempName();
 		DataIdentifier output = new DataIdentifier(outputName);
-		output.setAllPositions(this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());		
+		output.setParseInfo(this);
 		output.setDataType(computeDataType(this.getLeft(), this.getRight(), true));
 		ValueType resultVT = computeValueType(this.getLeft(), this.getRight(), true);
 
@@ -171,16 +161,17 @@ public class BinaryExpression extends Expression
 			pivot = right;
 		}
 
-		if ((pivot != null) && (aux != null)) 
-		{
-			//check dimensions binary operations (if dims known)
-			if (isSameDimensionBinaryOp(this.getOpCode()) && pivot.dimsKnown() && aux.dimsKnown() )
-			{
-				if(   (pivot.getDim1() != aux.getDim1() && aux.getDim1()>1)  //number of rows must always be equivalent if not row vector
-				   || (pivot.getDim2() != aux.getDim2() && aux.getDim2()>1)) //number of cols must be equivalent if not col vector
-				{
-					raiseValidateError("Mismatch in dimensions for operation "+ this.toString(), conditional, LanguageException.LanguageErrorCodes.INVALID_PARAMETERS);
-				} 
+		if ((pivot != null) && (aux != null)) {
+			// check dimensions binary operations (if dims known)
+			if (isSameDimensionBinaryOp(this.getOpCode()) && pivot.dimsKnown() && aux.dimsKnown()) {
+				// number of rows must always be equivalent if not row vector
+				// number of cols must be equivalent if not col vector
+				if ((pivot.getDim1() != aux.getDim1() && aux.getDim1() > 1)
+						|| (pivot.getDim2() != aux.getDim2() && aux.getDim2() > 1)) {
+					raiseValidateError("Mismatch in dimensions for operation '" + this.getText() + "'. " + pivot
+							+ " is " + pivot.getDim1() + "x" + pivot.getDim2() + " and " + aux + " is " + aux.getDim1()
+							+ "x" + aux.getDim2() + ".", conditional);
+				}
 			}
 		}
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/BooleanExpression.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/BooleanExpression.java b/src/main/java/org/apache/sysml/parser/BooleanExpression.java
index 2996da5..2069c06 100644
--- a/src/main/java/org/apache/sysml/parser/BooleanExpression.java
+++ b/src/main/java/org/apache/sysml/parser/BooleanExpression.java
@@ -37,18 +37,14 @@ public class BooleanExpression extends Expression
 		setBeginColumn(0);
 		setEndLine(0);
 		setEndColumn(0);
+		setText(null);
 	}
-	
-	public BooleanExpression(BooleanOp bop, String filename, int beginLine, int beginColumn, int endLine, int endColumn){
+
+	public BooleanExpression(BooleanOp bop, ParseInfo parseInfo) {
 		_opcode = bop;
-		
-		setFilename(filename);
-		setBeginLine(beginLine);
-		setBeginColumn(beginColumn);
-		setEndLine(endLine);
-		setEndColumn(endColumn);
+		setParseInfo(parseInfo);
 	}
-	
+
 	public BooleanOp getOpCode(){
 		return _opcode;
 	}
@@ -58,9 +54,7 @@ public class BooleanExpression extends Expression
 		
 		// update script location information --> left expression is BEFORE in script
 		if (_left != null){
-			this.setFilename(_left.getFilename());
-			this.setBeginLine(_left.getBeginLine());
-			this.setBeginColumn(_left.getBeginColumn());
+			this.setParseInfo(_left);
 		}
 	}
 	
@@ -69,9 +63,7 @@ public class BooleanExpression extends Expression
 		
 		// update script location information --> right expression is AFTER in script
 		if (_right != null){
-			this.setFilename(_right.getFilename());
-			this.setBeginLine(_right.getBeginLine());
-			this.setBeginColumn(_right.getBeginColumn());
+			this.setParseInfo(_right);
 		}
 	}
 	
@@ -84,9 +76,7 @@ public class BooleanExpression extends Expression
 	}
 
 	public Expression rewriteExpression(String prefix) throws LanguageException{
-		
-		
-		BooleanExpression newExpr = new BooleanExpression(this._opcode, this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
+		BooleanExpression newExpr = new BooleanExpression(this._opcode, this);
 		newExpr.setLeft(_left.rewriteExpression(prefix));
 		if (_right != null)
 			newExpr.setRight(_right.rewriteExpression(prefix));
@@ -118,17 +108,20 @@ public class BooleanExpression extends Expression
 		}
 		String outputName = getTempName();
 		DataIdentifier output = new DataIdentifier(outputName);
-		output.setAllPositions(this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
+		output.setParseInfo(this);
 		
 		output.setBooleanProperties();
 		this.setOutput(output);
-		if ((_opcode == Expression.BooleanOp.CONDITIONALAND) ||
-				(_opcode == Expression.BooleanOp.CONDITIONALOR)) 
-		{   //always unconditional (because unsupported operation)
-			raiseValidateError("Unsupported boolean operation " + _opcode.toString(), false, LanguageException.LanguageErrorCodes.UNSUPPORTED_PARAMETERS);
+		if ((_opcode == Expression.BooleanOp.CONDITIONALAND) || (_opcode == Expression.BooleanOp.CONDITIONALOR)) {
+			// always unconditional (because unsupported operation)
+			if (_opcode == Expression.BooleanOp.CONDITIONALAND) {
+				raiseValidateError("Conditional AND (&&) not supported.", false);
+			} else if (_opcode == Expression.BooleanOp.CONDITIONALOR) {
+				raiseValidateError("Conditional OR (||) not supported.", false);
+			}
 		}
-	}		
-	
+	}
+
 	public String toString(){
 		if (_opcode == BooleanOp.NOT) {
 			return "(" + _opcode.toString() + " " + _left.toString() + ")";

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/BooleanIdentifier.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/BooleanIdentifier.java b/src/main/java/org/apache/sysml/parser/BooleanIdentifier.java
index 501926c..6ca2b9f 100644
--- a/src/main/java/org/apache/sysml/parser/BooleanIdentifier.java
+++ b/src/main/java/org/apache/sysml/parser/BooleanIdentifier.java
@@ -19,21 +19,39 @@
 
 package org.apache.sysml.parser;
 
-
+import org.antlr.v4.runtime.ParserRuleContext;
 
 public class BooleanIdentifier extends ConstIdentifier 
 {
 	private boolean _val;
-	
-	public BooleanIdentifier(boolean val, String filename, int blp, int bcp, int elp, int ecp){
+
+	public BooleanIdentifier(boolean val) {
 		super();
-		 _val = val;
-		setDimensions(0,0);
-        computeDataType();
-        setValueType(ValueType.BOOLEAN);
-        setAllPositions(filename, blp, bcp, elp, ecp);
+		setInfo(val);
+		setBeginLine(-1);
+		setBeginColumn(-1);
+		setEndLine(-1);
+		setEndColumn(-1);
+		setText(null);
 	}
-	
+
+	public BooleanIdentifier(boolean val, ParseInfo parseInfo) {
+		this(val);
+		setParseInfo(parseInfo);
+	}
+
+	public BooleanIdentifier(ParserRuleContext ctx, boolean val, String filename) {
+		this(val);
+		setCtxValuesAndFilename(ctx, filename);
+	}
+
+	private void setInfo(boolean val) {
+		_val = val;
+		setDimensions(0, 0);
+		computeDataType();
+		setValueType(ValueType.BOOLEAN);
+	}
+
 	public Expression rewriteExpression(String prefix) throws LanguageException{
 		return this;
 	}

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java b/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java
index 5d3ae93..e03add3 100644
--- a/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java
+++ b/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 
+import org.antlr.v4.runtime.ParserRuleContext;
 import org.apache.sysml.parser.LanguageException.LanguageErrorCodes;
 import org.apache.sysml.runtime.util.ConvolutionUtils;
 import org.apache.sysml.runtime.util.UtilFunctions;
@@ -32,9 +33,9 @@ public class BuiltinFunctionExpression extends DataIdentifier
 	protected Expression[] 	  _args = null;
 	private BuiltinFunctionOp _opcode;
 
-	public BuiltinFunctionExpression(BuiltinFunctionOp bifop, ArrayList<ParameterExpression> args, String fname, int blp, int bcp, int elp, int ecp) {
+	public BuiltinFunctionExpression(ParserRuleContext ctx, BuiltinFunctionOp bifop, ArrayList<ParameterExpression> args, String fname) {
 		_opcode = bifop;
-		setAllPositions(fname, blp, bcp, elp, ecp);
+		setCtxValuesAndFilename(ctx, fname);
 		args = expandConvolutionArguments(args);
 		_args = new Expression[args.size()];
 		for(int i=0; i < args.size(); i++) {
@@ -42,25 +43,31 @@ public class BuiltinFunctionExpression extends DataIdentifier
 		}
 	}
 
-	public BuiltinFunctionExpression(BuiltinFunctionOp bifop, Expression[] args, String fname, int blp, int bcp, int elp, int ecp) {
+	public BuiltinFunctionExpression(BuiltinFunctionOp bifop, Expression[] args, ParseInfo parseInfo) {
+		_opcode = bifop;
+		_args = new Expression[args.length];
+		for (int i = 0; i < args.length; i++) {
+			_args[i] = args[i];
+		}
+		setParseInfo(parseInfo);
+	}
+
+	public BuiltinFunctionExpression(ParserRuleContext ctx, BuiltinFunctionOp bifop, Expression[] args, String fname) {
 		_opcode = bifop;
 		_args = new Expression[args.length];
 		for(int i=0; i < args.length; i++) {
 			_args[i] = args[i];
 		}
-		this.setAllPositions(fname, blp, bcp, elp, ecp);
+		setCtxValuesAndFilename(ctx, fname);
 	}
 
 	public Expression rewriteExpression(String prefix) throws LanguageException {
-
 		Expression[] newArgs = new Expression[_args.length];
-		for(int i=0; i < _args.length; i++) {
+		for (int i = 0; i < _args.length; i++) {
 			newArgs[i] = _args[i].rewriteExpression(prefix);
 		}
-		BuiltinFunctionExpression retVal = new BuiltinFunctionExpression(this._opcode, newArgs, 
-				this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
+		BuiltinFunctionExpression retVal = new BuiltinFunctionExpression(this._opcode, newArgs, this);
 		return retVal;
-	
 	}
 
 	public BuiltinFunctionOp getOpCode() {
@@ -108,7 +115,7 @@ public class BuiltinFunctionExpression extends DataIdentifier
 		int count = 0;
 		for (DataIdentifier outParam: stmt.getTargetList()){
 			DataIdentifier tmp = new DataIdentifier(outParam);
-			tmp.setAllPositions(this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
+			tmp.setParseInfo(this);
 			_outputs[count++] = tmp;
 		}
 		
@@ -149,11 +156,12 @@ public class BuiltinFunctionExpression extends DataIdentifier
 			
 			long inrows = getFirstExpr().getOutput().getDim1();
 			long incols = getFirstExpr().getOutput().getDim2();
-			
-			if ( inrows != incols ) {
-				raiseValidateError("LU Decomposition can only be done on a square matrix. Input matrix is rectangular (rows=" + inrows + ", cols="+incols+")", conditional);
+
+			if (inrows != incols) {
+				raiseValidateError("LU Decomposition requires a square matrix. Matrix " + getFirstExpr() + " is "
+						+ inrows + "x" + incols + ".", conditional);
 			}
-			
+
 			// Output1 - P
 			luOut1.setDataType(DataType.MATRIX);
 			luOut1.setValueType(ValueType.DOUBLE);
@@ -318,10 +326,8 @@ public class BuiltinFunctionExpression extends DataIdentifier
 				HashSet<String> expand = new HashSet<String>();
 				expand.add("input_shape"); expand.add("pool_size"); expand.add("stride"); expand.add("padding");
 				paramExpression = expandListParams(paramExpression, expand);
-				paramExpression.add(new ParameterExpression("filter_shape1", 
-						new IntIdentifier(1, getFilename(), getBeginLine(), getBeginColumn(), getEndLine(), getEndColumn())));
-				paramExpression.add(new ParameterExpression("filter_shape2", 
-						new IntIdentifier(1, getFilename(), getBeginLine(), getBeginColumn(), getEndLine(), getEndColumn())));
+				paramExpression.add(new ParameterExpression("filter_shape1", new IntIdentifier(1, this)));
+				paramExpression.add(new ParameterExpression("filter_shape2", new IntIdentifier(1, this)));
 				paramExpression = replaceListParams(paramExpression, "pool_size", "filter_shape", 3);
 				if(_opcode == BuiltinFunctionOp.MAX_POOL_BACKWARD)
 					paramExpression = orderConvolutionParams(paramExpression, 2);
@@ -357,7 +363,7 @@ public class BuiltinFunctionExpression extends DataIdentifier
 		// checkIdentifierParams();
 		String outputName = getTempName();
 		DataIdentifier output = new DataIdentifier(outputName);
-		output.setAllPositions(this.getFilename(), this.getBeginLine(), this.getBeginColumn(), this.getEndLine(), this.getEndColumn());
+		output.setParseInfo(this);
 		
 		if (this.getFirstExpr() == null) {
 			raiseValidateError("Function " + this + " has no arguments.", false);
@@ -680,11 +686,12 @@ public class BuiltinFunctionExpression extends DataIdentifier
 			
 			// First input: is always of type MATRIX
 			checkMatrixParam(getFirstExpr());
-			
-			if ( getSecondExpr() == null )
-				raiseValidateError("Invalid number of arguments to table(): " 
-						+ this.toString(), conditional, LanguageErrorCodes.INVALID_PARAMETERS);
-			
+
+			if (getSecondExpr() == null)
+				raiseValidateError(
+						"Invalid number of arguments to table(). The table() function requires 2, 3, 4, or 5 arguments.",
+						conditional);
+
 			// Second input: can be MATRIX or SCALAR
 			// cases: table(A,B) or table(A,1)
 			if ( getSecondExpr().getOutput().getDataType() == DataType.MATRIX)
@@ -1021,9 +1028,7 @@ public class BuiltinFunctionExpression extends DataIdentifier
 					// default value: 1 if from <= to; -1 if from > to
 					if(getThirdExpr() == null) {
 						expandArguments();
-						_args[2] = new DoubleIdentifier(((from > to) ? -1.0 : 1.0),
-								this.getFilename(), this.getBeginLine(), this.getBeginColumn(), 
-								this.getEndLine(), this.getEndColumn());
+						_args[2] = new DoubleIdentifier(((from > to) ? -1.0 : 1.0), this);
 					}
 					incr = getDoubleValue(getThirdExpr()); 
 					
@@ -1400,28 +1405,30 @@ public class BuiltinFunctionExpression extends DataIdentifier
 	protected void checkNumParameters(int count) //always unconditional
 		throws LanguageException 
 	{
-		if (getFirstExpr() == null){
-			raiseValidateError("Missing parameter for function "+ this.getOpCode(), false, LanguageErrorCodes.INVALID_PARAMETERS);
+		if (getFirstExpr() == null) {
+			raiseValidateError("Missing argument for function " + this.getOpCode(), false,
+					LanguageErrorCodes.INVALID_PARAMETERS);
+		}
+
+		if (((count == 1) && (getSecondExpr() != null || getThirdExpr() != null))
+				|| ((count == 2) && (getThirdExpr() != null))) {
+			raiseValidateError("Invalid number of arguments for function " + this.getOpCode().toString().toLowerCase()
+					+ "(). This function only takes 1 or 2 arguments.", false);
+		} else if (((count == 2) && (getSecondExpr() == null))
+				|| ((count == 3) && (getSecondExpr() == null || getThirdExpr() == null))) {
+			raiseValidateError("Missing argument for function " + this.getOpCode(), false,
+					LanguageErrorCodes.INVALID_PARAMETERS);
 		}
-		
-       	if (((count == 1) && (getSecondExpr()!= null || getThirdExpr() != null)) || 
-        		((count == 2) && (getThirdExpr() != null))){ 
-       		raiseValidateError("Invalid number of parameters for function "+ this.getOpCode(), false, LanguageErrorCodes.INVALID_PARAMETERS);
-       	}
-       	else if (((count == 2) && (getSecondExpr() == null)) || 
-		             ((count == 3) && (getSecondExpr() == null || getThirdExpr() == null))){
-       		raiseValidateError( "Missing parameter for function "+this.getOpCode(), false, LanguageErrorCodes.INVALID_PARAMETERS);
-       	}
 	}
 
-	protected void checkMatrixParam(Expression e) //always unconditional
-		throws LanguageException 
-	{
+	protected void checkMatrixParam(Expression e) throws LanguageException {
 		if (e.getOutput().getDataType() != DataType.MATRIX) {
-			raiseValidateError("Expecting matrix parameter for function "+ this.getOpCode(), false, LanguageErrorCodes.UNSUPPORTED_PARAMETERS);
+			raiseValidateError(
+					"Expecting matrix argument for function " + this.getOpCode().toString().toLowerCase() + "().",
+					false);
 		}
 	}
-	
+
 	protected void checkMatrixFrameParam(Expression e) //always unconditional
 		throws LanguageException 
 	{
@@ -1520,9 +1527,9 @@ public class BuiltinFunctionExpression extends DataIdentifier
 		}
 	}
 
-	public static BuiltinFunctionExpression getBuiltinFunctionExpression(
+	public static BuiltinFunctionExpression getBuiltinFunctionExpression(ParserRuleContext ctx, 
 			String functionName, ArrayList<ParameterExpression> paramExprsPassed,
-			String filename, int blp, int bcp, int elp, int ecp) {
+			String filename) {
 		
 		if (functionName == null || paramExprsPassed == null)
 			return null;
@@ -1708,8 +1715,7 @@ public class BuiltinFunctionExpression extends DataIdentifier
 		else
 			return null;
 		
-		BuiltinFunctionExpression retVal = new BuiltinFunctionExpression(bifop, paramExprsPassed,
-				filename, blp, bcp, elp, ecp);
+		BuiltinFunctionExpression retVal = new BuiltinFunctionExpression(ctx, bifop, paramExprsPassed, filename);
 	
 		return retVal;
 	} // end method getBuiltinFunctionExpression

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/ConditionalPredicate.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/ConditionalPredicate.java b/src/main/java/org/apache/sysml/parser/ConditionalPredicate.java
index 25f1fa9..1253391 100644
--- a/src/main/java/org/apache/sysml/parser/ConditionalPredicate.java
+++ b/src/main/java/org/apache/sysml/parser/ConditionalPredicate.java
@@ -19,7 +19,7 @@
 
 package org.apache.sysml.parser;
 
-public class ConditionalPredicate 
+public class ConditionalPredicate implements ParseInfo
 {
 
 	
@@ -61,17 +61,20 @@ public class ConditionalPredicate
 	private String _filename;
 	private int _beginLine, _beginColumn;
 	private int _endLine, _endColumn;
+	private String _text;
 	
 	public void setFilename(String fname)   { _filename = fname;   }
 	public void setBeginLine(int passed)    { _beginLine = passed;   }
 	public void setBeginColumn(int passed) 	{ _beginColumn = passed; }
 	public void setEndLine(int passed) 		{ _endLine = passed;   }
 	public void setEndColumn(int passed)	{ _endColumn = passed; }
+	public void setText(String text) { _text = text; }
 
 	public String getFilename()	{ return _filename;   }
 	public int getBeginLine()	{ return _beginLine;   }
 	public int getBeginColumn() { return _beginColumn; }
 	public int getEndLine() 	{ return _endLine;   }
 	public int getEndColumn()	{ return _endColumn; }
+	public String getText() { return _text; }
 
 }

http://git-wip-us.apache.org/repos/asf/systemml/blob/c495533b/src/main/java/org/apache/sysml/parser/DMLTranslator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/DMLTranslator.java b/src/main/java/org/apache/sysml/parser/DMLTranslator.java
index 28202dc..1dbdfdc 100644
--- a/src/main/java/org/apache/sysml/parser/DMLTranslator.java
+++ b/src/main/java/org/apache/sysml/parser/DMLTranslator.java
@@ -548,7 +548,7 @@ public class DMLTranslator
 			retPB.setStatementBlock(sb);
 			
 			// add location information
-			retPB.setAllPositions(sb.getFilename(), sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
+			retPB.setParseInfo(sb);
 		}
 		
 		// process If Statement - add runtime program blocks to program
@@ -615,7 +615,7 @@ public class DMLTranslator
 			retPB.setStatementBlock(sb);
 			
 			// add location information
-			retPB.setAllPositions(sb.getFilename(), sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
+			retPB.setParseInfo(sb);
 		}
 		
 		// process For Statement - add runtime program blocks to program
@@ -693,7 +693,7 @@ public class DMLTranslator
 			retPB.setStatementBlock(sb);
 			
 			// add location information
-			retPB.setAllPositions(sb.getFilename(), sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
+			retPB.setParseInfo(sb);
 		}
 		
 		// process function statement block - add runtime program blocks to program
@@ -775,7 +775,7 @@ public class DMLTranslator
 			retPB = rtpb;
 			
 			// add location information
-			retPB.setAllPositions(sb.getFilename(), sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
+			retPB.setParseInfo(sb);
 		}
 		else {
 	
@@ -806,7 +806,7 @@ public class DMLTranslator
 			retPB.setStatementBlock(sb);
 			
 			// add location information
-			retPB.setAllPositions(sb.getFilename(), sb.getBeginLine(), sb.getBeginColumn(), sb.getEndLine(), sb.getEndColumn());
+			retPB.setParseInfo(sb);
 		}
 		
 		return retPB;
@@ -1270,7 +1270,7 @@ public class DMLTranslator
 					long actualDim1 = (var instanceof IndexedIdentifier) ? ((IndexedIdentifier)var).getOrigDim1() : var.getDim1();
 					long actualDim2 = (var instanceof IndexedIdentifier) ? ((IndexedIdentifier)var).getOrigDim2() : var.getDim2();
 					DataOp read = new DataOp(var.getName(), var.getDataType(), var.getValueType(), DataOpTypes.TRANSIENTREAD, null, actualDim1, actualDim2, var.getNnz(), var.getRowsInBlock(), var.getColumnsInBlock());
-					read.setAllPositions(var.getFilename(), var.getBeginLine(), var.getBeginColumn(), var.getEndLine(), var.getEndColumn());
+					read.setParseInfo(var);
 					ids.put(varName, read);
 				}
 			}
@@ -1326,8 +1326,7 @@ public class DMLTranslator
 				DataIdentifier target = createTarget();
 				target.setDataType(DataType.SCALAR);
 				target.setValueType(ValueType.STRING);
-				target.setAllPositions(current.getFilename(), current.getBeginLine(), target.getBeginColumn(),
-						current.getEndLine(), current.getEndColumn());
+				target.setParseInfo(current);
 
 				PrintStatement ps = (PrintStatement) current;
 				PRINTTYPE ptype = ps.getType();
@@ -1338,16 +1337,14 @@ public class DMLTranslator
 						Expression source = ps.getExpressions().get(0);
 						Hop ae = processExpression(source, target, ids);
 						Hop printHop = new UnaryOp(target.getName(), target.getDataType(), target.getValueType(), op, ae);
-						printHop.setAllPositions(current.getFilename(), current.getBeginLine(), current.getBeginColumn(), current.getEndLine(),
-								current.getEndColumn());
+						printHop.setParseInfo(current);
 						output.add(printHop);
 					} else if (ptype == PRINTTYPE.STOP) {
 						Hop.OpOp1 op = Hop.OpOp1.STOP;
 						Expression source = ps.getExpressions().get(0);
 						Hop ae = processExpression(source, target, ids);
 						Hop stopHop = new UnaryOp(target.getName(), target.getDataType(), target.getValueType(), op, ae);
-						stopHop.setAllPositions(current.getFilename(), current.getBeginLine(), current.getBeginColumn(), current.getEndLine(),
-								current.getEndColumn());
+						stopHop.setParseInfo(current);
 						output.add(stopHop);
 						sb.setSplitDag(true); //avoid merge
 					} else if (ptype == PRINTTYPE.PRINTF) {
@@ -1392,7 +1389,7 @@ public class DMLTranslator
 						if ((statementId != null) && (statementId.intValue() == i)) {
 							DataOp transientwrite = new DataOp(target.getName(), target.getDataType(), target.getValueType(), ae, DataOpTypes.TRANSIENTWRITE, null);
 							transientwrite.setOutputParams(ae.getDim1(), ae.getDim2(), ae.getNnz(), ae.getUpdateType(), ae.getRowsInBlock(), ae.getColsInBlock());
-							transientwrite.setAllPositions(target.getFilename(), target.getBeginLine(), target.getBeginColumn(), target.getEndLine(), target.getEndLine());
+							transientwrite.setParseInfo(target);
 							updatedLiveOut.addVariable(target.getName(), target);
 							output.add(transientwrite);
 						}
@@ -1423,7 +1420,7 @@ public class DMLTranslator
 						if ((statementId != null) && (statementId.intValue() == i)) {
 							DataOp transientwrite = new DataOp(target.getName(), target.getDataType(), target.getValueType(), ae, DataOpTypes.TRANSIENTWRITE, null);
 							transientwrite.setOutputParams(origDim1, origDim2, ae.getNnz(), ae.getUpdateType(), ae.getRowsInBlock(), ae.getColsInBlock());
-							transientwrite.setAllPositions(target.getFilename(), target.getBeginLine(), target.getBeginColumn(), target.getEndLine(), target.getEndColumn());
+							transientwrite.setParseInfo(target);
 							updatedLiveOut.addVariable(target.getName(), target);
 							output.add(transientwrite);
 						}
@@ -1633,7 +1630,7 @@ public class DMLTranslator
 				
 				read = new DataOp(var.getName(), var.getDataType(), var.getValueType(), DataOpTypes.TRANSIENTREAD,
 						null, actualDim1, actualDim2, var.getNnz(), var.getRowsInBlock(), var.getColumnsInBlock());
-				read.setAllPositions(var.getFilename(), var.getBeginLine(), var.getBeginColumn(), var.getEndLine(), var.getEndColumn());
+				read.setParseInfo(var);
 			}
 			_ids.put(varName, read);
 		}
@@ -1641,7 +1638,7 @@ public class DMLTranslator
 		DataIdentifier target = new DataIdentifier(Expression.getTempName());
 		target.setDataType(DataType.SCALAR);
 		target.setValueType(ValueType.BOOLEAN);
-		target.setAllPositions(passedSB.getFilename(), passedSB.getBeginLine(), passedSB.getBeginColumn(), passedSB.getEndLine(), passedSB.getEndColumn());
+		target.setParseInfo(passedSB);
 		Hop predicateHops = null;
 		Expression predicate = cp.getPredicate();
 		
@@ -1656,30 +1653,21 @@ public class DMLTranslator
 			// handle constant identifier
 			//  a) translate 0 --> FALSE; translate 1 --> TRUE
 			//	b) disallow string values
-			if ( (predicate instanceof IntIdentifier && ((IntIdentifier)predicate).getValue() == 0) || (predicate instanceof DoubleIdentifier && ((DoubleIdentifier)predicate).getValue() == 0.0)) {
-				cp.setPredicate(new BooleanIdentifier(false, 
-						predicate.getFilename(),
-						predicate.getBeginLine(), predicate.getBeginColumn(),
-						predicate.getEndLine(), predicate.getEndColumn()));
-				
-			}
-			else if ( (predicate instanceof IntIdentifier && ((IntIdentifier)predicate).getValue() == 1) || (predicate instanceof DoubleIdentifier && ((DoubleIdentifier)predicate).getValue() == 1.0)) {
-				cp.setPredicate(new BooleanIdentifier(true,
-						predicate.getFilename(),
-						predicate.getBeginLine(), predicate.getBeginColumn(),
-						predicate.getEndLine(), predicate.getEndColumn()));
-			}
-			else if (predicate instanceof IntIdentifier || predicate instanceof DoubleIdentifier){
-				cp.setPredicate(new BooleanIdentifier(true,
-						predicate.getFilename(),
-						predicate.getBeginLine(), predicate.getBeginColumn(),
-						predicate.getEndLine(), predicate.getEndColumn()));
-				LOG.warn(predicate.printWarningLocation() + "Numerical value '" + predicate.toString() + "' (!= 0/1) is converted to boolean TRUE by DML");
-			}
-			else if (predicate instanceof StringIdentifier) {
-				LOG.error(predicate.printErrorLocation() + "String value '" + predicate.toString() + "' is not allowed for iterable predicate");
-				throw new ParseException(predicate.printErrorLocation() + "String value '" + predicate.toString() + "' is not allowed for iterable predicate");
-
+			if ((predicate instanceof IntIdentifier && ((IntIdentifier) predicate).getValue() == 0)
+					|| (predicate instanceof DoubleIdentifier && ((DoubleIdentifier) predicate).getValue() == 0.0)) {
+				cp.setPredicate(new BooleanIdentifier(false, predicate));
+			} else if ((predicate instanceof IntIdentifier && ((IntIdentifier) predicate).getValue() == 1)
+					|| (predicate instanceof DoubleIdentifier && ((DoubleIdentifier) predicate).getValue() == 1.0)) {
+				cp.setPredicate(new BooleanIdentifier(true, predicate));
+			} else if (predicate instanceof IntIdentifier || predicate instanceof DoubleIdentifier) {
+				cp.setPredicate(new BooleanIdentifier(true, predicate));
+				LOG.warn(predicate.printWarningLocation() + "Numerical value '" + predicate.toString()
+						+ "' (!= 0/1) is converted to boolean TRUE by DML");
+			} else if (predicate instanceof StringIdentifier) {
+				LOG.error(predicate.printErrorLocation() + "String value '" + predicate.toString()
+						+ "' is not allowed for iterable predicate");
+				throw new ParseException(predicate.printErrorLocation() + "String value '" + predicate.toString()
+						+ "' is not allowed for iterable predicate");
 			}
 			predicateHops = processExpression(cp.getPredicate(), null, _ids);
 		}
@@ -1731,7 +1719,7 @@ public class DMLTranslator
 						long actualDim2 = (var instanceof IndexedIdentifier) ? ((IndexedIdentifier)var).getOrigDim2() : var.getDim2();
 						read = new DataOp(var.getName(), var.getDataType(), var.getValueType(), DataOpTypes.TRANSIENTREAD,
 								null, actualDim1, actualDim2,  var.getNnz(), var.getRowsInBlock(),  var.getColumnsInBlock());
-						read.setAllPositions(var.getFilename(), var.getBeginLine(), var.getBeginColumn(), var.getEndLine(), var.getEndColumn());
+						read.setParseInfo(var);
 					}
 					_ids.put(varName, read);
 				}
@@ -1809,28 +1797,28 @@ public class DMLTranslator
 			else if (source instanceof IntIdentifier) {
 				IntIdentifier sourceInt = (IntIdentifier) source;
 				LiteralOp litop = new LiteralOp(sourceInt.getValue());
-				litop.setAllPositions(sourceInt.getFilename(), sourceInt.getBeginLine(), sourceInt.getBeginColumn(), sourceInt.getEndLine(), sourceInt.getEndColumn());
+				litop.setParseInfo(sourceInt);
 				setIdentifierParams(litop, sourceInt);
 				return litop;
 			} 
 			else if (source instanceof DoubleIdentifier) {
 				DoubleIdentifier sourceDouble = (DoubleIdentifier) source;
 				LiteralOp litop = new LiteralOp(sourceDouble.getValue());
-				litop.setAllPositions(source.getFilename(), sourceDouble.getBeginLine(), sourceDouble.getBeginColumn(), sourceDouble.getEndLine(), sourceDouble.getEndColumn());
+				litop.setParseInfo(sourceDouble);
 				setIdentifierParams(litop, sourceDouble);
 				return litop;
 			}
 			else if (source instanceof BooleanIdentifier) {
 				BooleanIdentifier sourceBoolean = (BooleanIdentifier) source;
 				LiteralOp litop = new LiteralOp(sourceBoolean.getValue());
-				litop.setAllPositions(sourceBoolean.getFilename(), sourceBoolean.getBeginLine(), sourceBoolean.getBeginColumn(), sourceBoolean.getEndLine(), sourceBoolean.getEndColumn());
+				litop.setParseInfo(sourceBoolean);
 				setIdentifierParams(litop, sourceBoolean);
 				return litop;
 			} 
 			else if (source instanceof StringIdentifier) {
 				StringIdentifier sourceString = (StringIdentifier) source;
 				LiteralOp litop = new LiteralOp(sourceString.getValue());
-				litop.setAllPositions(sourceString.getFilename(), sourceString.getBeginLine(), sourceString.getBeginColumn(), sourceString.getEndLine(), sourceString.getEndColumn());
+				litop.setParseInfo(sourceString);
 				setIdentifierParams(litop, sourceString);
 				return litop;
 			} 
@@ -1897,7 +1885,7 @@ public class DMLTranslator
 				rowUpperHops = new LiteralOp(target.getOrigDim1());
 			else {
 				rowUpperHops = new UnaryOp(target.getName(), DataType.SCALAR, ValueType.INT, Hop.OpOp1.NROW, hops.get(target.getName()));
-				rowUpperHops.setAllPositions(target.getFilename(), target.getBeginLine(), target.getBeginColumn(), target.getEndLine(), target.getEndColumn());
+				rowUpperHops.setParseInfo(target);
 			}
 		}
 		if (target.getColLowerBound() != null)
@@ -1934,7 +1922,7 @@ public class DMLTranslator
 		
 		setIdentifierParams(leftIndexOp, target);
 	
-		leftIndexOp.setAllPositions(target.getFilename(), target.getBeginLine(), target.getBeginColumn(), target.getEndLine(), target.getEndColumn());
+		leftIndexOp.setParseInfo(target);
 		leftIndexOp.setDim1(target.getOrigDim1());
 		leftIndexOp.setDim2(target.getOrigDim2());
 	
@@ -1961,7 +1949,7 @@ public class DMLTranslator
 				rowUpperHops = new LiteralOp(source.getOrigDim1());
 			else {
 				rowUpperHops = new UnaryOp(source.getName(), DataType.SCALAR, ValueType.INT, Hop.OpOp1.NROW, hops.get(source.getName()));
-				rowUpperHops.setAllPositions(source.getFilename(), source.getBeginLine(),source.getBeginColumn(), source.getEndLine(), source.getEndColumn());
+				rowUpperHops.setParseInfo(source);
 			}
 		}
 		if (source.getColLowerBound() != null)
@@ -1990,7 +1978,7 @@ public class DMLTranslator
 				hops.get(source.getName()), rowLowerHops, rowUpperHops, colLowerHops, colUpperHops,
 				source.getRowLowerEqualsUpper(), source.getColLowerEqualsUpper());
 	
-		indexOp.setAllPositions(target.getFilename(), target.getBeginLine(), target.getBeginColumn(), target.getEndLine(), target.getEndColumn());
+		indexOp.setParseInfo(target);
 		setIdentifierParams(indexOp, target);
 		
 		return indexOp;
@@ -2048,7 +2036,7 @@ public class DMLTranslator
 			throw new ParseException("Unsupported parsing of binary expression: "+source.getOpCode());
 		}
 		setIdentifierParams(currBop, source.getOutput());
-		currBop.setAllPositions(source.getFilename(), source.getBeginLine(), source.getBeginColumn(), source.getEndLine(), source.getEndColumn());
+		currBop.setParseInfo(source);
 		return currBop;
 		
 	}
@@ -2092,7 +2080,7 @@ public class DMLTranslator
 			op = OpOp2.NOTEQUAL;
 		}
 		currBop = new BinaryOp(target.getName(), target.getDataType(), target.getValueType(), op, left, right);
-		currBop.setAllPositions(source.getFilename(), source.getBeginLine(), source.getBeginColumn(), source.getEndLine(), source.getEndColumn());
+		currBop.setParseInfo(source);
 		return currBop;
 	}
 
@@ -2126,7 +2114,7 @@ public class DMLTranslator
 		
 		if (source.getRight() == null) {
 			Hop currUop = new UnaryOp(target.getName(), target.getDataType(), target.getValueType(), Hop.OpOp1.NOT, left);
-			currUop.setAllPositions(source.getFilename(), source.getBeginLine(), source.getBeginColumn(), source.getEndLine(), source.getEndColumn());
+			currUop.setParseInfo(source);
 			return currUop;
 		} 
 		else {
@@ -2142,7 +2130,7 @@ public class DMLTranslator
 				throw new RuntimeException(source.printErrorLocation() + "Unknown boolean operation " + source.getOpCode());
 			}
 			currBop = new BinaryOp(target.getName(), target.getDataType(), target.getValueType(), op, left, right);
-			currBop.setAllPositions(source.getFilename(), source.getBeginLine(), source.getBeginColumn(), source.getEndLine(), source.getEndColumn());
+			currBop.setParseInfo(source);
 			// setIdentifierParams(currBop,source.getOutput());
 			return currBop;
 		}
@@ -2221,9 +2209,9 @@ public class DMLTranslator
 		// set properties for created hops based on outputs of source expression
 		for ( int i=0; i < source.getOutputs().length; i++ ) {
 			setIdentifierParams( outputs.get(i), source.getOutputs()[i]);
-			outputs.get(i).setAllPositions(source.getFilename(), source.getBeginLine(), source.getBeginColumn(), source.getEndLine(), source.getEndColumn());
+			outputs.get(i).setParseInfo(source);
 		}
-		currBuiltinOp.setAllPositions(source.getFilename(), source.getBeginLine(), source.getBeginColumn(), source.getEndLine(), source.getEndColumn());
+		currBuiltinOp.setParseInfo(source);
 
 		return currBuiltinOp;
 	}
@@ -2342,9 +2330,7 @@ public class DMLTranslator
 		}
 		
 		setIdentifierParams(currBuiltinOp, source.getOutput());
-		
-		currBuiltinOp.setAllPositions(source.getFilename(), source.getBeginLine(), source.getBeginColumn(), source.getEndLine(), source.getEndColumn());
-		
+		currBuiltinOp.setParseInfo(source);
 		return currBuiltinOp;
 	}
 	
@@ -2431,7 +2417,7 @@ public class DMLTranslator
 		setIdentifierParams(currBuiltinOp, source.getOutput());
 		if( source.getOpCode()==DataExpression.DataOp.READ )
 			((DataOp)currBuiltinOp).setInputBlockSizes(target.getRowsInBlock(), target.getColumnsInBlock());
-		currBuiltinOp.setAllPositions(source.getFilename(), source.getBeginLine(), source.getBeginColumn(), source.getEndLine(), source.getEndColumn());
+		currBuiltinOp.setParseInfo(source);
 		
 		return currBuiltinOp;
 	}
@@ -2494,9 +2480,9 @@ public class DMLTranslator
 		// set properties for created hops based on outputs of source expression
 		for ( int i=0; i < source.getOutputs().length; i++ ) {
 			setIdentifierParams( outputs.get(i), source.getOutputs()[i]);
-			outputs.get(i).setAllPositions(source.getFilename(), source.getBeginLine(), source.getBeginColumn(), source.getEndLine(), source.getEndColumn());
+			outputs.get(i).setParseInfo(source);
 		}
-		currBuiltinOp.setAllPositions(source.getFilename(), source.getBeginLine(), source.getBeginColumn(), source.getEndLine(), source.getEndColumn());
+		currBuiltinOp.setParseInfo(source);
 
 		return currBuiltinOp;
 	}
@@ -3169,7 +3155,7 @@ public class DMLTranslator
 			// Since the dimension of output doesnot match that of input variable for these operations
 			setIdentifierParams(currBuiltinOp, source.getOutput());
 		}
-		currBuiltinOp.setAllPositions(source.getFilename(), source.getBeginLine(), source.getBeginColumn(), source.getEndLine(), source.getEndColumn());
+		currBuiltinOp.setParseInfo(source);
 		return currBuiltinOp;
 	}
 	
@@ -3230,20 +3216,17 @@ public class DMLTranslator
 			throw new ParseException("Unsupported skip");
 		}
 
-		for(int i = skip; i < allExpr.length; i++) {
-			if(i == numImgIndex) { // skip=1 ==> i==5  and skip=2 => i==6
+		for (int i = skip; i < allExpr.length; i++) {
+			if (i == numImgIndex) { // skip=1 ==> i==5 and skip=2 => i==6
 				Expression numImg = allExpr[numImgIndex];
-				Expression numChannels = allExpr[numImgIndex+1];
-				BinaryExpression tmp = new BinaryExpression(org.apache.sysml.parser.Expression.BinaryOp.MULT, 
-						numImg.getFilename(), numImg.getBeginLine(), numImg.getBeginColumn(), numImg.getEndLine(), numImg.getEndColumn());
+				Expression numChannels = allExpr[numImgIndex + 1];
+				BinaryExpression tmp = new BinaryExpression(org.apache.sysml.parser.Expression.BinaryOp.MULT, numImg);
 				tmp.setLeft(numImg);
 				tmp.setRight(numChannels);
 				ret.add(processTempIntExpression(tmp, hops));
-				ret.add(processExpression(new IntIdentifier(1, numImg.getFilename(), numImg.getBeginLine(), numImg.getBeginColumn(), 
-						numImg.getEndLine(), numImg.getEndColumn()), null, hops));
+				ret.add(processExpression(new IntIdentifier(1, numImg), null, hops));
 				i++;
-			}
-			else
+			} else
 				ret.add(processExpression(allExpr[i], null, hops));
 		}
 		return ret;
@@ -3339,22 +3322,24 @@ public class DMLTranslator
 						&& ((AssignmentStatement)s).getSource() instanceof DataExpression )
 				{
 					DataExpression dexpr = (DataExpression) ((AssignmentStatement)s).getSource();
-					if( dexpr.isRead() ){
+					if (dexpr.isRead()) {
 						String pfname = dexpr.getVarParam(DataExpression.IO_FILENAME).toString();
-						if( pWrites.containsKey(pfname) && !pfname.trim().isEmpty() ) //found read-after-write
-						{
-							//update read with essential write meta data
+						// found read-after-write
+						if (pWrites.containsKey(pfname) && !pfname.trim().isEmpty()) {
+							// update read with essential write meta data
 							DataIdentifier di = pWrites.get(pfname);
-							FormatType ft = (di.getFormatType()!=null) ? di.getFormatType() : FormatType.TEXT;
-							dexpr.addVarParam(DataExpression.FORMAT_TYPE, new StringIdentifier(ft.toString(),di.getFilename(),di.getBeginLine(),di.getBeginColumn(),di.getEndLine(),di.getEndColumn()));							
-							if( di.getDim1()>=0 )
-								dexpr.addVarParam(DataExpression.READROWPARAM, new IntIdentifier(di.getDim1(),di.getFilename(),di.getBeginLine(),di.getBeginColumn(),di.getEndLine(),di.getEndColumn()));
-							if( di.getDim2()>=0 )
-								dexpr.addVarParam(DataExpression.READCOLPARAM, new IntIdentifier(di.getDim2(),di.getFilename(),di.getBeginLine(),di.getBeginColumn(),di.getEndLine(),di.getEndColumn()));
-							if( di.getValueType()!=ValueType.UNKNOWN )
-								dexpr.addVarParam(DataExpression.VALUETYPEPARAM, new StringIdentifier(di.getValueType().toString(),di.getFilename(),di.getBeginLine(),di.getBeginColumn(),di.getEndLine(),di.getEndColumn()));
-							if( di.getDataType()!=DataType.UNKNOWN )
-								dexpr.addVarParam(DataExpression.DATATYPEPARAM, new StringIdentifier(di.getDataType().toString(),di.getFilename(),di.getBeginLine(),di.getBeginColumn(),di.getEndLine(),di.getEndColumn()));
+							FormatType ft = (di.getFormatType() != null) ? di.getFormatType() : FormatType.TEXT;
+							dexpr.addVarParam(DataExpression.FORMAT_TYPE, new StringIdentifier(ft.toString(), di));
+							if (di.getDim1() >= 0)
+								dexpr.addVarParam(DataExpression.READROWPARAM, new IntIdentifier(di.getDim1(), di));
+							if (di.getDim2() >= 0)
+								dexpr.addVarParam(DataExpression.READCOLPARAM, new IntIdentifier(di.getDim2(), di));
+							if (di.getValueType() != ValueType.UNKNOWN)
+								dexpr.addVarParam(DataExpression.VALUETYPEPARAM,
+										new StringIdentifier(di.getValueType().toString(), di));
+							if (di.getDataType() != DataType.UNKNOWN)
+								dexpr.addVarParam(DataExpression.DATATYPEPARAM,
+										new StringIdentifier(di.getDataType().toString(), di));
 							ret = true;
 						}
 					}