use of org.apache.sysml.parser.DoubleIdentifier in project systemml by apache.
the class PydmlSyntacticValidator method incrementByOne.
/**
* Increment lower indices by 1 when translating from PyDML
* (0-based indexing) to DML (1-based indexing).
*
* @param expr expression
* @param ctx antlr rule context
* @return expression
*/
private Expression incrementByOne(Expression expr, ParserRuleContext ctx) {
// Addition and subtraction operator same as DML
Expression.BinaryOp bop = Expression.getBinaryOp("+");
Expression retVal = new BinaryExpression(bop);
((BinaryExpression) retVal).setLeft(expr);
((BinaryExpression) retVal).setRight(new DoubleIdentifier(ctx, 1.0, currentFile));
setFileLineColumn(retVal, ctx);
return retVal;
}
use of org.apache.sysml.parser.DoubleIdentifier in project incubator-systemml by apache.
the class CommonSyntacticValidator method getConstIdFromString.
protected ConstIdentifier getConstIdFromString(String varValue, Token start) {
int linePosition = start.getLine();
int charPosition = start.getCharPositionInLine();
// Compare to "True/TRUE"
if (varValue.equals(trueStringLiteral()))
return new BooleanIdentifier(true, currentFile, linePosition, charPosition, linePosition, charPosition);
// Compare to "False/FALSE"
if (varValue.equals(falseStringLiteral()))
return new BooleanIdentifier(false, currentFile, linePosition, charPosition, linePosition, charPosition);
// 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);
} catch (Exception ex) {
//continue
}
// 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);
} catch (Exception ex) {
//continue
}
// Otherwise it is a string literal (optionally enclosed within single or double quotes)
String val = "";
String text = varValue;
if ((text.startsWith("\"") && text.endsWith("\"")) || (text.startsWith("\'") && text.endsWith("\'"))) {
if (text.length() > 2) {
val = extractStringInQuotes(text, true);
}
} else {
// the commandline parameters can be passed without any quotes
val = extractStringInQuotes(text, false);
}
return new StringIdentifier(val, currentFile, linePosition, charPosition, linePosition, charPosition);
}
use of org.apache.sysml.parser.DoubleIdentifier in project incubator-systemml by apache.
the class CommonSyntacticValidator method constDoubleIdExpressionHelper.
protected void constDoubleIdExpressionHelper(ParserRuleContext ctx, ExpressionInfo me) {
try {
double val = Double.parseDouble(ctx.getText());
me.expr = new DoubleIdentifier(ctx, val, currentFile);
} catch (Exception e) {
notifyErrorListeners("cannot parse the float value: \'" + ctx.getText() + "\'", ctx.getStart());
return;
}
}
Aggregations