use of org.matheclipse.parser.client.ast.SymbolNode in project symja_android_library by axkr.
the class Parser method parseInequality.
/**
* Rewrite a chain of different comparator operators to an <code>Inequality(...)</code>
* expression.
*
* @param ast the ast which should be rewritten
* @param infixOperator
* @return
*/
private ASTNode parseInequality(final FunctionNode ast, final InfixOperator infixOperator) {
// rewrite to Inequality
SymbolNode head = (SymbolNode) ast.get(0);
final FunctionNode result = fFactory.createFunction(fFactory.createSymbol(IConstantOperators.Inequality));
for (int i = 1; i < ast.size(); i++) {
result.add(ast.get(i));
result.add(head);
}
InfixOperator compareOperator = determineBinaryOperator();
result.set(result.size() - 1, fFactory.createSymbol(compareOperator.getFunctionName()));
getNextToken();
while (fToken == TT_NEWLINE) {
getNextToken();
}
int precedence = infixOperator.getPrecedence();
result.add(parseLookaheadOperator(precedence));
while (fToken == TT_OPERATOR && isComparatorOperator(fOperatorString)) {
compareOperator = determineBinaryOperator();
result.add(fFactory.createSymbol(compareOperator.getFunctionName()));
getNextToken();
while (fToken == TT_NEWLINE) {
getNextToken();
}
result.add(parseLookaheadOperator(precedence));
}
return result;
}
use of org.matheclipse.parser.client.ast.SymbolNode in project symja_android_library by axkr.
the class Parser method getSymbol.
/**
* Read the current identifier from the expression factories table
*
* @return
* @see
*/
private SymbolNode getSymbol() throws SyntaxError {
String[] identifierContext = getIdentifier();
if (!fFactory.isValidIdentifier(identifierContext[0])) {
throwSyntaxError("Invalid identifier: " + identifierContext[0] + " detected.");
}
final SymbolNode symbol = fFactory.createSymbol(identifierContext[0], identifierContext[1]);
getNextToken();
return symbol;
}
use of org.matheclipse.parser.client.ast.SymbolNode in project symja_android_library by axkr.
the class Parser method getNumber.
/**
* Method Declaration.
*
* @return
* @see
*/
private ASTNode getNumber(final boolean negative) throws SyntaxError {
ASTNode temp = null;
String numberStr = "";
try {
final Object[] result = getNumberString();
numberStr = (String) result[0];
final int numFormat = ((Integer) result[1]);
String exponentStr = (String) result[2];
if (negative) {
numberStr = '-' + numberStr;
}
if (numFormat < 0) {
if (fCurrentChar == '`' && isValidPosition()) {
fCurrentPosition++;
if (isValidPosition() && fInputString[fCurrentPosition] == '*') {
fCurrentPosition++;
if (isValidPosition() && fInputString[fCurrentPosition] == '^') {
fCurrentPosition += 2;
long exponent = getJavaLong();
// Double d = Double.valueOf(number + "E" + exponent);
return fFactory.createDouble(numberStr + "E" + exponent);
}
} else if (isValidPosition() && fInputString[fCurrentPosition] == '`') {
fCurrentPosition += 2;
long precision = getJavaLong();
if (precision < ParserConfig.MACHINE_PRECISION) {
precision = ParserConfig.MACHINE_PRECISION;
}
return fFactory.createDouble(numberStr);
} else {
if (isValidPosition() && Character.isDigit(fInputString[fCurrentPosition])) {
fCurrentPosition++;
long precision = getJavaLong();
if (precision < ParserConfig.MACHINE_PRECISION) {
precision = ParserConfig.MACHINE_PRECISION;
}
return fFactory.createDouble(numberStr);
} else {
getNextToken();
return fFactory.createDouble(numberStr);
}
}
throwSyntaxError("Number format error: " + numberStr, numberStr.length());
}
temp = fFactory.createDouble(numberStr);
} else {
if (exponentStr == null || exponentStr.equals("1")) {
temp = fFactory.createInteger(numberStr, numFormat);
} else {
if (numFormat == 10) {
try {
int exponent = Integer.parseInt(exponentStr, 10);
if (exponent < 0) {
exponent = -exponent;
StringBuilder buf = createPowersOf10(exponent);
temp = fFactory.createFunction(new SymbolNode("Times"), fFactory.createInteger(numberStr, numFormat), fFactory.createFunction(new SymbolNode("Power"), fFactory.createInteger(buf.toString(), numFormat), IntegerNode.CN1));
} else {
StringBuilder buf = createPowersOf10(exponent);
temp = fFactory.createFunction(new SymbolNode("Times"), fFactory.createInteger(numberStr, numFormat), fFactory.createInteger(buf.toString(), numFormat));
}
} catch (final NumberFormatException e) {
throwSyntaxError("Number format error (not an int type): " + exponentStr, exponentStr.length());
}
} else {
throwSyntaxError("Number format error: " + numberStr, numberStr.length());
}
}
}
} catch (final SyntaxError e) {
throwSyntaxError("Number format error: " + numberStr, numberStr.length());
}
getNextToken();
return temp;
}
Aggregations