final private ASTNode Primary() throws ParseException, NumberFormatException {
Token t;
double d;
int i;
ASTNode node = new ASTNode();
ASTNode child, furtherChild;
String s;
String vals [ ];
ArrayList < ASTNode > arguments = new ArrayList < ASTNode > ();
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case INTEGER:
t = jj_consume_token(INTEGER);
i = Integer.parseInt(t.image); // Could use StringTools.parseXXX methods here but not doing so allow to support different locale ??
node.setValue(i);
{if (true) return node;}
break;
case NUMBER:
t = jj_consume_token(NUMBER);
d = Double.parseDouble(t.image);
node.setValue(d);
{if (true) return node;}
break;
case EXPNUMBER:
t = jj_consume_token(EXPNUMBER);
s = t.image;
vals = s.toLowerCase().split("e");
if (vals [ 1 ].startsWith("+"))
{
i = Integer.parseInt(vals [ 1 ].substring(1));
}
else
{
i = Integer.parseInt(vals [ 1 ]);
}
node.setValue(Double.parseDouble(vals [ 0 ]), i);
{if (true) return node;}
break;
default:
jj_la1[8] = jj_gen;
if (jj_2_1(2)) {
t = string();
jj_consume_token(OPEN_PAR);
child = TermLvl1();
label_4:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case SLPITTER:
;
break;
default:
jj_la1[7] = jj_gen;
break label_4;
}
jj_consume_token(SLPITTER);
furtherChild = TermLvl1();
arguments.add(furtherChild);
}
jj_consume_token(CLOSE_PAR);
s = t.image;
Type type = null;
if (stringToType.containsKey(s.toLowerCase()))
{
type = ASTNode.Type.valueOf(stringToType.getProperty(s.toLowerCase()).toUpperCase());
}
if (s.equalsIgnoreCase("pow") || s.equalsIgnoreCase("power"))
{
checkSize(arguments, 1);
node.addChild(child);
}
else if (s.equalsIgnoreCase("sqr"))
{
checkSize(arguments, 0);
node.addChild(child);
node.addChild(new ASTNode(2));
}
else if (s.equalsIgnoreCase("sqrt"))
{
checkSize(arguments, 0);
node.addChild(new ASTNode(2));
node.addChild(child);
}
else if (s.equalsIgnoreCase("not"))
{
checkSize(arguments, 0);
node.addChild(child);
type = Type.LOGICAL_NOT;
}
else if (s.equalsIgnoreCase("ln"))
{
checkSize(arguments, 0);
node.addChild(child);
type = Type.FUNCTION_LN;
}
else if (s.equalsIgnoreCase("lambda"))
{
node.addChild(child);
type = Type.LAMBDA;
}
else if (s.equalsIgnoreCase("piecewise"))
{
node.addChild(child);
type = Type.FUNCTION_PIECEWISE;
}
else if (s.equalsIgnoreCase("modulo") || s.equalsIgnoreCase("mod"))
{
checkSize(arguments, 1);
ASTNode rightChild = arguments.get(0);
arguments.clear();
node = createModulo(child, rightChild);
{if (true) return node;}
}
else
{
node.addChild(child);
}
if (type != null)
{
node.setType(type);
}
else
{
node.setName(s);
}
for (ASTNode argument : arguments)
{
node.addChild(argument);
}
{if (true) return node;}
} else {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case OPEN_PAR:
jj_consume_token(OPEN_PAR);
node = TermLvl1();
jj_consume_token(CLOSE_PAR);
{if (true) return node;}
break;
case MINUS:
jj_consume_token(MINUS);
node = Primary();
ASTNode uiMinus = new ASTNode('-');
uiMinus.addChild(node);
{if (true) return uiMinus;}
break;
case NOT:
jj_consume_token(NOT);
node = TermLvl1();
ASTNode not = new ASTNode(Type.LOGICAL_NOT);
not.addChild(node);
{if (true) return not;}
break;
case LOG:
jj_consume_token(LOG);
child = Primary();
node = new ASTNode(Type.FUNCTION_LN);
node.addChild(child);
{if (true) return node;}
break;
case STRING:
t = jj_consume_token(STRING);
s = t.image;
if (s.equalsIgnoreCase("true"))
{
node = new ASTNode(Type.CONSTANT_TRUE);
}
else if (s.equalsIgnoreCase("false"))
{
node = new ASTNode(Type.CONSTANT_FALSE);
}
else if (s.equalsIgnoreCase("pi"))
{
node = new ASTNode(Type.CONSTANT_PI);
}
else if (s.equalsIgnoreCase("avogadro"))
{
node = new ASTNode(Type.NAME_AVOGADRO);
}
else if (s.equalsIgnoreCase("time"))
{
node = new ASTNode(Type.NAME_TIME);
}
else if (s.equalsIgnoreCase("exponentiale"))
{
node = new ASTNode(Type.CONSTANT_E);
}
else if (s.equalsIgnoreCase("-infinity") || s.equalsIgnoreCase("-INF"))
{
node = new ASTNode(Double.NEGATIVE_INFINITY);
}
else if (s.equalsIgnoreCase("infinity") || s.equalsIgnoreCase("INF"))
{
node = new ASTNode(Double.POSITIVE_INFINITY);
}
else if (s.equalsIgnoreCase("NotANumber") || s.equalsIgnoreCase("NaN"))
{
node = new ASTNode(Double.NaN);
}
else
{
node = new ASTNode(s);
}
{if (true) return node;}
break;
default:
jj_la1[9] = jj_gen;