diff options
author | Maël Gassmann <mael.gassmann@students.bfh.ch> | 2021-06-12 18:03:33 +0200 |
---|---|---|
committer | Maël Gassmann <mael.gassmann@students.bfh.ch> | 2021-06-12 18:03:33 +0200 |
commit | 4d18d279ad449d2e748d88e31beeaa85f1e42a8c (patch) | |
tree | d6055114e6023b9bd9f6c062cddb31caa1d7748f /calculator-java/src/main | |
parent | a434b8818cb6a437a575aae7b31dc4dfb61477b8 (diff) |
[~] Bug fix
Diffstat (limited to 'calculator-java/src/main')
-rw-r--r-- | calculator-java/src/main/java/ch/bfh/parser/StatementParser.java | 9 | ||||
-rw-r--r-- | calculator-java/src/main/java/ch/bfh/parser/TermParser.java | 2 |
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 |