mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 02:46:41 +00:00
Cleanup
This commit is contained in:
@ -100,8 +100,7 @@ public class Expression {
|
||||
|
||||
try {
|
||||
return root.getValue();
|
||||
}
|
||||
catch (ReturnException e) {
|
||||
} catch (ReturnException e) {
|
||||
return e.getValue();
|
||||
}
|
||||
}
|
||||
|
@ -51,50 +51,50 @@ public class Lexer {
|
||||
}
|
||||
|
||||
private final DecisionTree operatorTree = new DecisionTree(null,
|
||||
'+', new DecisionTree("+",
|
||||
'=', new DecisionTree("+="),
|
||||
'+', new DecisionTree("++")
|
||||
),
|
||||
'-', new DecisionTree("-",
|
||||
'=', new DecisionTree("-="),
|
||||
'-', new DecisionTree("--")
|
||||
),
|
||||
'*', new DecisionTree("*",
|
||||
'=', new DecisionTree("*="),
|
||||
'*', new DecisionTree("**")
|
||||
),
|
||||
'/', new DecisionTree("/",
|
||||
'=', new DecisionTree("/=")
|
||||
),
|
||||
'%', new DecisionTree("%",
|
||||
'=', new DecisionTree("%=")
|
||||
),
|
||||
'^', new DecisionTree("^",
|
||||
'=', new DecisionTree("^=")
|
||||
),
|
||||
'=', new DecisionTree("=",
|
||||
'=', new DecisionTree("==")
|
||||
),
|
||||
'!', new DecisionTree("!",
|
||||
'=', new DecisionTree("!=")
|
||||
),
|
||||
'<', new DecisionTree("<",
|
||||
'<', new DecisionTree("<<"),
|
||||
'=', new DecisionTree("<=")
|
||||
),
|
||||
'>', new DecisionTree(">",
|
||||
'>', new DecisionTree(">>"),
|
||||
'=', new DecisionTree(">=")
|
||||
),
|
||||
'&', new DecisionTree(null, // not implemented
|
||||
'&', new DecisionTree("&&")
|
||||
),
|
||||
'|', new DecisionTree(null, // not implemented
|
||||
'|', new DecisionTree("||")
|
||||
),
|
||||
'~', new DecisionTree("~",
|
||||
'=', new DecisionTree("~=")
|
||||
)
|
||||
'+', new DecisionTree("+",
|
||||
'=', new DecisionTree("+="),
|
||||
'+', new DecisionTree("++")
|
||||
),
|
||||
'-', new DecisionTree("-",
|
||||
'=', new DecisionTree("-="),
|
||||
'-', new DecisionTree("--")
|
||||
),
|
||||
'*', new DecisionTree("*",
|
||||
'=', new DecisionTree("*="),
|
||||
'*', new DecisionTree("**")
|
||||
),
|
||||
'/', new DecisionTree("/",
|
||||
'=', new DecisionTree("/=")
|
||||
),
|
||||
'%', new DecisionTree("%",
|
||||
'=', new DecisionTree("%=")
|
||||
),
|
||||
'^', new DecisionTree("^",
|
||||
'=', new DecisionTree("^=")
|
||||
),
|
||||
'=', new DecisionTree("=",
|
||||
'=', new DecisionTree("==")
|
||||
),
|
||||
'!', new DecisionTree("!",
|
||||
'=', new DecisionTree("!=")
|
||||
),
|
||||
'<', new DecisionTree("<",
|
||||
'<', new DecisionTree("<<"),
|
||||
'=', new DecisionTree("<=")
|
||||
),
|
||||
'>', new DecisionTree(">",
|
||||
'>', new DecisionTree(">>"),
|
||||
'=', new DecisionTree(">=")
|
||||
),
|
||||
'&', new DecisionTree(null, // not implemented
|
||||
'&', new DecisionTree("&&")
|
||||
),
|
||||
'|', new DecisionTree(null, // not implemented
|
||||
'|', new DecisionTree("||")
|
||||
),
|
||||
'~', new DecisionTree("~",
|
||||
'=', new DecisionTree("~=")
|
||||
)
|
||||
);
|
||||
|
||||
private static final Set<Character> characterTokens = new HashSet<Character>();
|
||||
|
@ -182,8 +182,7 @@ public class Parser {
|
||||
if (peek().id() == ';') {
|
||||
++position;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
break loop;
|
||||
}
|
||||
|
||||
@ -205,8 +204,7 @@ public class Parser {
|
||||
break loop;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
break loop;
|
||||
}
|
||||
}
|
||||
@ -253,7 +251,7 @@ public class Parser {
|
||||
} else {
|
||||
RValue variable = variables.get(identifierToken.value);
|
||||
if (variable == null) {
|
||||
if (next instanceof OperatorToken && ((OperatorToken)next).operator.equals("=")) {
|
||||
if (next instanceof OperatorToken && ((OperatorToken) next).operator.equals("=")) {
|
||||
// Ugly hack to make temporary variables work while not sacrificing error reporting.
|
||||
variables.put(identifierToken.value, variable = new Variable(0));
|
||||
} else {
|
||||
|
@ -35,32 +35,32 @@ public final class ParserProcessors {
|
||||
|
||||
final Object[][][] binaryOpsLA = {
|
||||
{
|
||||
{ "^", "pow" },
|
||||
{ "**", "pow" },
|
||||
{ "^", "pow" },
|
||||
{ "**", "pow" },
|
||||
},
|
||||
{
|
||||
{ "*", "mul" },
|
||||
{ "/", "div" },
|
||||
{ "%", "mod" },
|
||||
{ "*", "mul" },
|
||||
{ "/", "div" },
|
||||
{ "%", "mod" },
|
||||
},
|
||||
{
|
||||
{ "+", "add" },
|
||||
{ "-", "sub" },
|
||||
{ "+", "add" },
|
||||
{ "-", "sub" },
|
||||
},
|
||||
{
|
||||
{ "<<", "shl" },
|
||||
{ ">>", "shr" },
|
||||
{ "<<", "shl" },
|
||||
{ ">>", "shr" },
|
||||
},
|
||||
{
|
||||
{ "<", "lth" },
|
||||
{ ">", "gth" },
|
||||
{ "<=", "leq" },
|
||||
{ ">=", "geq" },
|
||||
{ "<", "lth" },
|
||||
{ ">", "gth" },
|
||||
{ "<=", "leq" },
|
||||
{ ">=", "geq" },
|
||||
},
|
||||
{
|
||||
{ "==", "equ" },
|
||||
{ "!=", "neq" },
|
||||
{ "~=", "near" },
|
||||
{ "==", "equ" },
|
||||
{ "!=", "neq" },
|
||||
{ "~=", "near" },
|
||||
},
|
||||
{
|
||||
{ "&&", "and" },
|
||||
@ -71,13 +71,13 @@ public final class ParserProcessors {
|
||||
};
|
||||
final Object[][][] binaryOpsRA = {
|
||||
{
|
||||
{ "=", "ass" },
|
||||
{ "+=", "aadd" },
|
||||
{ "-=", "asub" },
|
||||
{ "*=", "amul" },
|
||||
{ "/=", "adiv" },
|
||||
{ "%=", "amod" },
|
||||
{ "^=", "aexp" },
|
||||
{ "=", "ass" },
|
||||
{ "+=", "aadd" },
|
||||
{ "-=", "asub" },
|
||||
{ "*=", "amul" },
|
||||
{ "/=", "adiv" },
|
||||
{ "%=", "amod" },
|
||||
{ "^=", "aexp" },
|
||||
},
|
||||
};
|
||||
|
||||
@ -230,19 +230,17 @@ public final class ParserProcessors {
|
||||
|
||||
final Identifiable last = input.removeLast();
|
||||
if (last instanceof OperatorToken) {
|
||||
postfixes.addLast(new UnaryOperator(last.getPosition(), "x"+((OperatorToken)last).operator));
|
||||
}
|
||||
else if (last instanceof UnaryOperator) {
|
||||
postfixes.addLast(new UnaryOperator(last.getPosition(), "x"+((UnaryOperator)last).operator));
|
||||
}
|
||||
else {
|
||||
postfixes.addLast(new UnaryOperator(last.getPosition(), "x" + ((OperatorToken) last).operator));
|
||||
} else if (last instanceof UnaryOperator) {
|
||||
postfixes.addLast(new UnaryOperator(last.getPosition(), "x" + ((UnaryOperator) last).operator));
|
||||
} else {
|
||||
center = last;
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
|
||||
if (!(center instanceof RValue)) {
|
||||
throw new ParserException(center.getPosition(), "Expected expression, found "+center);
|
||||
throw new ParserException(center.getPosition(), "Expected expression, found " + center);
|
||||
}
|
||||
|
||||
input.addAll(postfixes);
|
||||
|
@ -13,7 +13,7 @@ public class UnaryOperator extends PseudoToken {
|
||||
public UnaryOperator(OperatorToken operatorToken) {
|
||||
this(operatorToken.getPosition(), operatorToken.operator);
|
||||
}
|
||||
|
||||
|
||||
public UnaryOperator(int position, String operator) {
|
||||
super(position);
|
||||
this.operator = operator;
|
||||
|
@ -17,8 +17,7 @@ public class Conditional extends Node {
|
||||
public double getValue() throws EvaluationException {
|
||||
if (condition.getValue() > 0.0) {
|
||||
return truePart.getValue();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return falsePart == null ? 0 : falsePart.getValue();
|
||||
}
|
||||
}
|
||||
@ -31,9 +30,9 @@ public class Conditional extends Node {
|
||||
@Override
|
||||
public String toString() {
|
||||
if (falsePart == null) {
|
||||
return "if ("+condition+") { "+truePart+" }";
|
||||
return "if (" + condition + ") { " + truePart + " }";
|
||||
} else {
|
||||
return "if ("+condition+") { "+truePart+" } else { "+falsePart+" }";
|
||||
return "if (" + condition + ") { " + truePart + " } else { " + falsePart + " }";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,7 @@ public class For extends Node {
|
||||
|
||||
try {
|
||||
ret = body.getValue();
|
||||
}
|
||||
catch (BreakException e) {
|
||||
} catch (BreakException e) {
|
||||
if (e.doContinue) {
|
||||
continue;
|
||||
} else {
|
||||
@ -48,7 +47,7 @@ public class For extends Node {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "for ("+init+"; "+condition+"; "+increment+") { "+body+" }";
|
||||
return "for (" + init + "; " + condition + "; " + increment + ") { " + body + " }";
|
||||
}
|
||||
|
||||
//TODO: optimizer
|
||||
|
@ -34,7 +34,7 @@ import com.sk89q.worldedit.expression.runtime.Function.Dynamic;
|
||||
*/
|
||||
public final class Functions {
|
||||
private static class Overload {
|
||||
private final Method method;
|
||||
private final Method method;
|
||||
private final int mask;
|
||||
private final boolean isSetter;
|
||||
|
||||
@ -90,14 +90,12 @@ public final class Functions {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static final Function getFunction(int position, String name, RValue... args) throws NoSuchMethodException {
|
||||
final Method getter = getMethod(name, false, args);
|
||||
try {
|
||||
Method setter = getMethod(name, true, args);
|
||||
return new LValueFunction(position, getter, setter, args);
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
} catch (NoSuchMethodException e) {
|
||||
return new Function(position, getter, args);
|
||||
}
|
||||
}
|
||||
|
@ -28,5 +28,6 @@ import com.sk89q.worldedit.expression.Identifiable;
|
||||
*/
|
||||
public interface RValue extends Identifiable {
|
||||
public double getValue() throws EvaluationException;
|
||||
|
||||
public Node optimize() throws EvaluationException;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public class Return extends Node {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "return "+value;
|
||||
return "return " + value;
|
||||
}
|
||||
|
||||
//TODO: optimizer
|
||||
|
@ -27,8 +27,7 @@ public class While extends Node {
|
||||
|
||||
try {
|
||||
ret = body.getValue();
|
||||
}
|
||||
catch (BreakException e) {
|
||||
} catch (BreakException e) {
|
||||
if (e.doContinue) {
|
||||
continue;
|
||||
} else {
|
||||
@ -45,8 +44,7 @@ public class While extends Node {
|
||||
|
||||
try {
|
||||
ret = body.getValue();
|
||||
}
|
||||
catch (BreakException e) {
|
||||
} catch (BreakException e) {
|
||||
if (e.doContinue) {
|
||||
continue;
|
||||
} else {
|
||||
@ -67,9 +65,9 @@ public class While extends Node {
|
||||
@Override
|
||||
public String toString() {
|
||||
if (footChecked) {
|
||||
return "do { "+body+" } while ("+condition+")";
|
||||
return "do { " + body + " } while (" + condition + ")";
|
||||
} else {
|
||||
return "while ("+condition+") { "+body+" }";
|
||||
return "while (" + condition + ") { " + body + " }";
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user