@Override
public ParserVal eliminateConst() {
if(inner.size()==1){
if(inner.get(0).isConstant())
return new Number(-Double.parseDouble(inner.get(0).getText()));
// make unary minus a binary minus if not constant - makes evaluation simpler
inner.add(inner.get(0));
inner.set(0, new Number("0"));
return this;
}
if(inner.size()<1||inner.size()>2)
throw new InternalError("\"-\" requires at least one and at most two arguments");
if(inner.get(0).isConstant()&&inner.get(1).isConstant()){
if(inner.get(0).getType()==SCParser.NUMBER&&inner.get(1).getType()==SCParser.NUMBER){
try{
ParserVal ret=new Number(inner.get(0).asDouble()-inner.get(1).asDouble());
ret.setFilename(filename);
ret.setLine(line);
return ret;
}catch(NumberFormatException ex){
throw new IllegalArgumentException("should not happen: number format error", ex);
}
}