aboutsummaryrefslogtreecommitdiff
path: root/calculator-java
diff options
context:
space:
mode:
Diffstat (limited to 'calculator-java')
-rw-r--r--calculator-java/src/main/java/ch/bfh/parser/StatementParser.java9
-rw-r--r--calculator-java/src/main/java/ch/bfh/parser/TermParser.java2
2 files changed, 7 insertions, 4 deletions
diff --git a/calculator-java/src/main/java/ch/bfh/parser/StatementParser.java b/calculator-java/src/main/java/ch/bfh/parser/StatementParser.java
index 482ef34..7bd0d14 100644
--- a/calculator-java/src/main/java/ch/bfh/parser/StatementParser.java
+++ b/calculator-java/src/main/java/ch/bfh/parser/StatementParser.java
@@ -46,9 +46,12 @@ public class StatementParser extends Parser{
throw new ParserException("Two consecutive variables ('"+variableName+"' and '"+token.str+"') were found in the declaration context.");
// the expression started with a variable -> no definition -> meaning it is an expression
default:
- parsedExpression = new ExpressionParser(cl, token, false);
- if (lastToken != null && lastToken.type == Token.EQU) // this still need to be put in the variables list
- variables.put(variableName, parsedExpression);
+ if (lastToken == null || lastToken.type == Token.EQU) {
+ parsedExpression = new ExpressionParser(cl, token, false);
+ if (lastToken != null && lastToken.type == Token.EQU) // this still need to be put in the variables list
+ variables.put(variableName, parsedExpression);
+ }else
+ throw new ParserException("Incomplete variable declaration. Expected: let var = Expression.");
break;
}
lastToken = token;
diff --git a/calculator-java/src/main/java/ch/bfh/parser/TermParser.java b/calculator-java/src/main/java/ch/bfh/parser/TermParser.java
index 9e49fa8..5ead591 100644
--- a/calculator-java/src/main/java/ch/bfh/parser/TermParser.java
+++ b/calculator-java/src/main/java/ch/bfh/parser/TermParser.java
@@ -69,7 +69,7 @@ class TermParser extends ExpressionParser {
token = cl.nextToken();
}
if (op != null && r == null)
- throw new ParserException("Missing expression after last operation '" + op.str + "'");
+ throw new ParserException("Missing expression after last operator '" + op.str + "'");
}
@Override