This commit is contained in:
Wizjany
2011-10-26 16:50:46 -04:00
parent 8797d8ac3c
commit 699807665d
19 changed files with 175 additions and 110 deletions

View File

@ -140,8 +140,7 @@ public class Lexer {
if (!numberPart.isEmpty()) {
try {
tokens.add(new NumberToken(position, Double.parseDouble(numberPart)));
}
catch (NumberFormatException e) {
} catch (NumberFormatException e) {
throw new LexerException(position, "Number parsing failed", e);
}
@ -156,8 +155,7 @@ public class Lexer {
if (!identifierPart.isEmpty()) {
if (keywords.contains(identifierPart)) {
tokens.add(new KeywordToken(position, identifierPart));
}
else {
} else {
tokens.add(new IdentifierToken(position, identifierPart));
}
@ -167,8 +165,7 @@ public class Lexer {
}
throw new LexerException(position, "Unknown character '" + ch + "'");
}
while (position < expression.length());
} while (position < expression.length());
return tokens;
}

View File

@ -100,8 +100,7 @@ public class Parser {
final Token next = peek();
if (next.id() == '(') {
halfProcessed.add(parseFunctionCall(identifierToken));
}
else {
} else {
RValue variable = variables.get(identifierToken.value);
if (variable == null) {
throw new ParserException(current.getPosition(), "Variable '" + identifierToken.value + "' not found");
@ -130,8 +129,7 @@ public class Parser {
case 'o':
if (expressionStart) {
halfProcessed.add(new PrefixOperator((OperatorToken) current));
}
else {
} else {
halfProcessed.add(current);
}
++position;
@ -148,8 +146,7 @@ public class Parser {
if (isStatement) {
return ParserProcessors.processStatement(halfProcessed);
}
else {
} else {
return ParserProcessors.processExpression(halfProcessed);
}
}
@ -195,8 +192,7 @@ public class Parser {
}
return Functions.getFunction(identifierToken.getPosition(), identifierToken.value, args.toArray(new RValue[args.size()]));
}
catch (NoSuchMethodException e) {
} catch (NoSuchMethodException e) {
throw new ParserException(identifierToken.getPosition(), "Function not found", e);
}
}

View File

@ -134,12 +134,10 @@ public final class ParserProcessors {
for (Identifiable identifiable : input) {
if (semicolonFound) {
rhs.addLast(identifiable);
}
else {
} else {
if (identifiable.id() == ';') {
semicolonFound = true;
}
else {
} else {
lhs.addLast(identifiable);
}
}
@ -151,12 +149,10 @@ public final class ParserProcessors {
}
return processExpression(lhs);
}
else if (lhs.isEmpty()) {
} else if (lhs.isEmpty()) {
return processStatement(rhs);
}
else {
assert(semicolonFound);
} else {
assert (semicolonFound);
RValue lhsInvokable = processExpression(lhs);
RValue rhsInvokable = processStatement(rhs);
@ -193,8 +189,7 @@ public final class ParserProcessors {
}
rhs.removeFirst();
}
else {
} else {
lhs.addFirst(identifiable);
}
}
@ -206,8 +201,7 @@ public final class ParserProcessors {
try {
return Operators.getOperator(input.get(0).getPosition(), operator, lhsInvokable, rhsInvokable);
}
catch (NoSuchMethodException e) {
} catch (NoSuchMethodException e) {
final Token operatorToken = (Token) input.get(lhs.size());
throw new ParserException(operatorToken.getPosition(), "Couldn't find operator '" + operator + "'");
}
@ -236,8 +230,7 @@ public final class ParserProcessors {
}
lhs.removeLast();
}
else {
} else {
rhs.addLast(identifiable);
}
}
@ -249,8 +242,7 @@ public final class ParserProcessors {
try {
return Operators.getOperator(input.get(0).getPosition(), operator, lhsInvokable, rhsInvokable);
}
catch (NoSuchMethodException e) {
} catch (NoSuchMethodException e) {
final Token operatorToken = (Token) input.get(lhs.size());
throw new ParserException(operatorToken.getPosition(), "Couldn't find operator '" + operator + "'");
}
@ -280,19 +272,16 @@ public final class ParserProcessors {
try {
ret = Operators.getOperator(lastPosition, opName, ret);
continue;
}
catch (NoSuchMethodException e) {
} catch (NoSuchMethodException e) {
throw new ParserException(lastPosition, "No such prefix operator: " + operator);
}
}
}
if (last instanceof Token) {
throw new ParserException(lastPosition, "Extra token found in expression: " + last);
}
else if (last instanceof RValue) {
} else if (last instanceof RValue) {
throw new ParserException(lastPosition, "Extra expression found: " + last);
}
else {
} else {
throw new ParserException(lastPosition, "Extra element found: " + last);
}
}

View File

@ -49,14 +49,12 @@ public class Function extends RValue {
public final double getValue() throws EvaluationException {
try {
return (Double) method.invoke(null, (Object[]) args);
}
catch (InvocationTargetException e) {
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof EvaluationException) {
throw (EvaluationException) e.getTargetException();
}
throw new EvaluationException(-1, "Exception caught while evaluating expression", e.getTargetException());
}
catch (IllegalAccessException e) {
} catch (IllegalAccessException e) {
throw new EvaluationException(-1, "Internal error while evaluating expression", e);
}
}
@ -99,8 +97,7 @@ public class Function extends RValue {
if (optimizable) {
return new Constant(position, getValue());
}
else {
} else {
return new Function(position, method, optimizedArgs);
}
}

View File

@ -29,8 +29,8 @@ public final class Operators {
if (lhs instanceof LValue) {
try {
return new Function(position, Operators.class.getMethod(name, LValue.class, RValue.class), lhs, rhs);
} catch (NoSuchMethodException e) {
}
catch (NoSuchMethodException e) {}
}
return new Function(position, Operators.class.getMethod(name, RValue.class, RValue.class), lhs, rhs);
}
@ -39,8 +39,8 @@ public final class Operators {
if (argument instanceof LValue) {
try {
return new Function(position, Operators.class.getMethod(name, LValue.class), argument);
} catch (NoSuchMethodException e) {
}
catch (NoSuchMethodException e) {}
}
return new Function(position, Operators.class.getMethod(name, RValue.class), argument);
}

View File

@ -75,8 +75,7 @@ public class Sequence extends RValue {
for (RValue subInvokable : ((Sequence) invokable).sequence) {
newSequence.add(subInvokable);
}
}
else {
} else {
newSequence.add(invokable);
}
}