| @@ -22,7 +22,6 @@ Der Parser nimmt einen String mit dem Quelltext entgegen und erzeugt daraus ein | |||||
| package parser; | package parser; | ||||
| import expression.*; | import expression.*; | ||||
| import expression.Identifier; | |||||
| import expression.Int; | import expression.Int; | ||||
| import program.*; | import program.*; | ||||
| @@ -86,25 +85,12 @@ des Quelltextes geparsed wurden. | |||||
| statement = conditional(); | statement = conditional(); | ||||
| } catch (SyntaxException se2) { | } catch (SyntaxException se2) { | ||||
| position = start; | position = start; | ||||
| try { | |||||
| statement = loop(); | |||||
| } catch (SyntaxException se3) { | |||||
| position = start; | |||||
| statement = call(); | |||||
| } | |||||
| statement = loop(); | |||||
| } | } | ||||
| } | } | ||||
| return statement; | return statement; | ||||
| } | } | ||||
| Program call() { | |||||
| Identifier name = identifier(); | |||||
| consume("("); | |||||
| Expression argument = expression(); | |||||
| consume(")"); | |||||
| return new Call(name, argument); | |||||
| } | |||||
| Program loop() { | Program loop() { | ||||
| consume("while"); | consume("while"); | ||||
| consume("("); | consume("("); | ||||
| @@ -1,38 +0,0 @@ | |||||
| package program; | |||||
| import expression.Expression; | |||||
| import expression.Identifier; | |||||
| public class Call extends Program { | |||||
| final Identifier name; | |||||
| final Expression argument; | |||||
| @Override | |||||
| public boolean equals(Object o) { | |||||
| if (this == o) return true; | |||||
| if (o == null || getClass() != o.getClass()) return false; | |||||
| Call that = (Call) o; | |||||
| if (!name.equals(that.name)) return false; | |||||
| return argument.equals(that.argument); | |||||
| } | |||||
| @Override | |||||
| public String toString() { | |||||
| return name + "(" + argument + ")"; | |||||
| } | |||||
| @Override | |||||
| public int hashCode() { | |||||
| int result = name.hashCode(); | |||||
| result = 31 * result + argument.hashCode(); | |||||
| return result; | |||||
| } | |||||
| public Call(Identifier name, Expression argument) { | |||||
| this.name = name; | |||||
| this.argument = argument; | |||||
| } | |||||
| } | |||||
| @@ -52,15 +52,6 @@ public class ParserTest { | |||||
| assertEquals(loop, parser.statement()); | assertEquals(loop, parser.statement()); | ||||
| } | } | ||||
| final String callCode = "print(x + 36)"; | |||||
| final Call call = new Call(new Identifier("print"), new Addition(new Identifier("x"), new Int(36))); | |||||
| @Test | |||||
| public void testStatementCall() { | |||||
| Parser parser = new Parser(callCode); | |||||
| assertEquals(call, parser.statement()); | |||||
| } | |||||
| @Test | @Test | ||||
| public void testAssignment() { | public void testAssignment() { | ||||
| Parser parser = new Parser(assignmentCode); | Parser parser = new Parser(assignmentCode); | ||||
| @@ -79,12 +70,6 @@ public class ParserTest { | |||||
| assertEquals(loop, parser.loop()); | assertEquals(loop, parser.loop()); | ||||
| } | } | ||||
| @Test | |||||
| public void testCall() { | |||||
| Parser parser = new Parser(callCode); | |||||
| assertEquals(call, parser.call()); | |||||
| } | |||||
| final String expressionCode = "a+b - (c - 56) + -47"; | final String expressionCode = "a+b - (c - 56) + -47"; | ||||
| final Expression expression = new Addition(new Subtraction(new Addition(new Identifier("a"), new Identifier("b")), new Subtraction(new Identifier("c"), new Int(56))), new Int(-47)); | final Expression expression = new Addition(new Subtraction(new Addition(new Identifier("a"), new Identifier("b")), new Subtraction(new Identifier("c"), new Int(56))), new Int(-47)); | ||||