mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-05 07:16:10 +00:00
allow grouping binary operations
This commit is contained in:
@@ -102,8 +102,10 @@ public class Parser {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Returnable<?> parseExpression(List<Token> tokens, boolean full) throws ParseException {
|
||||
System.out.println(tokens.get(0));
|
||||
Token first = tokens.get(0);
|
||||
|
||||
if(first.getType().equals(Token.Type.GROUP_BEGIN)) return parseGroup(tokens);
|
||||
|
||||
checkType(first, Token.Type.IDENTIFIER, Token.Type.BOOLEAN, Token.Type.STRING, Token.Type.NUMBER, Token.Type.BOOLEAN_NOT, Token.Type.GROUP_BEGIN);
|
||||
|
||||
boolean not = false;
|
||||
@@ -143,6 +145,13 @@ public class Parser {
|
||||
return expression;
|
||||
}
|
||||
|
||||
private Returnable<?> parseGroup(List<Token> tokens) throws ParseException {
|
||||
checkType(tokens.remove(0), Token.Type.GROUP_BEGIN);
|
||||
Returnable<?> expression = parseExpression(tokens, true);
|
||||
checkType(tokens.remove(0), Token.Type.GROUP_END);
|
||||
return expression;
|
||||
}
|
||||
|
||||
|
||||
private BinaryOperation<?, ?> parseBinaryOperation(Returnable<?> left, List<Token> tokens) throws ParseException {
|
||||
Token binaryOperator = tokens.remove(0);
|
||||
@@ -187,8 +196,6 @@ public class Parser {
|
||||
return new GreaterOrEqualsThanStatement((Returnable<Number>) left, (Returnable<Number>) right, binaryOperator.getPosition());
|
||||
case LESS_THAN_OR_EQUALS_OPERATOR:
|
||||
return new LessThanOrEqualsStatement((Returnable<Number>) left, (Returnable<Number>) right, binaryOperator.getPosition());
|
||||
|
||||
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unsupported binary operator: " + binaryOperator.getType());
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
test("hello" + 3 + "gdfg", 2);
|
||||
test("hello" + 3 + "gdfg", (2 * (3+1)));
|
||||
|
||||
if(true == test("hello" + 3 + "gdfg", 3 + 8*2 - 1)) {
|
||||
test("fdsgdf" + 2, 3.4);
|
||||
|
||||
Reference in New Issue
Block a user