From 4d18d279ad449d2e748d88e31beeaa85f1e42a8c Mon Sep 17 00:00:00 2001 From: Maƫl Gassmann Date: Sat, 12 Jun 2021 18:03:33 +0200 Subject: [~] Bug fix --- calculator-java/src/main/java/ch/bfh/parser/StatementParser.java | 9 ++++++--- calculator-java/src/main/java/ch/bfh/parser/TermParser.java | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'calculator-java/src/main') 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 -- cgit v1.2.3