this.lookahead++;
positive = false;
}
if (this.lookahead >= tokens.size()) {
throw new ParsingException("unexpected token at " + tk.getInitIndex());
}
tk = tokens.get(this.lookahead);
BigDecimal value = null;
// Parses the value, depending on terminal type
if (tk.getType() == TypeEnum.NUMBER) {
this.lookahead++;
value = new BigDecimal(tk.getText());
if (!positive) {
value = value.negate();
}
return value;
} else if (tk.getType() == TypeEnum.IDENTIFIER) {
this.lookahead++;
value = values.get(tk.getText());
if (!positive) {
value = value.negate();
}
return value;
} else
// Parses subexpressions
if (tk.getType() == TypeEnum.OPEN_BRACK) {
this.lookahead++;
value = this.exp(tokens, values);
tk = tokens.get(this.lookahead);
if (tk.getType() == TypeEnum.CLOSE_BRACK) {
this.lookahead++;
return value;
}
}
}
// Throws an error when an unexpected token is found
throw new ParsingException("unexpected token at " + tk.getInitIndex());
}