diff options
author | Maël Gassmann <mael.gassmann@students.bfh.ch> | 2021-06-11 11:17:45 +0200 |
---|---|---|
committer | Maël Gassmann <mael.gassmann@students.bfh.ch> | 2021-06-11 11:17:45 +0200 |
commit | 403c6a951e890d3e1914779ee35576859a38d33e (patch) | |
tree | ff2d5182ad4e72b335624c61a7d48364de61807c /calculator-java/src/main/java/ch/bfh/parser | |
parent | 126a6c85b60ad07fa29ab48315f0f195fb45d854 (diff) |
[+] implemented the 'shell' UI, [~] Small corrections had to be made in the parser
Diffstat (limited to 'calculator-java/src/main/java/ch/bfh/parser')
-rw-r--r-- | calculator-java/src/main/java/ch/bfh/parser/ExpressionParser.java | 8 | ||||
-rw-r--r-- | calculator-java/src/main/java/ch/bfh/parser/Parser.java | 4 |
2 files changed, 7 insertions, 5 deletions
diff --git a/calculator-java/src/main/java/ch/bfh/parser/ExpressionParser.java b/calculator-java/src/main/java/ch/bfh/parser/ExpressionParser.java index 229e700..f96353e 100644 --- a/calculator-java/src/main/java/ch/bfh/parser/ExpressionParser.java +++ b/calculator-java/src/main/java/ch/bfh/parser/ExpressionParser.java @@ -49,6 +49,7 @@ public class ExpressionParser extends Parser { case Token.SUB: if (l != null && op == null) { // if the '-' sign is between two term (op) op = token; + this.ops.add(op); break; } else if (l != null && r != null) { // if we already found a 'l op r' we roll l = r; @@ -69,7 +70,7 @@ public class ExpressionParser extends Parser { } continue loop; case Token.PAR: - if (lastToken.type == Token.PAL) { // if equal to '(' it means it was created by a Factor + if (lastToken != null && lastToken.type == Token.PAL) { // if equal to '(' it means it was created by a Factor lastToken = token; break loop; } else @@ -260,7 +261,10 @@ public class ExpressionParser extends Parser { @Override public double getValue(){ if (expression != null) - return expression.getValue(); + if (isNegative) + return expression.getValue()*(-1); + else + return expression.getValue(); if (isNegative) return value*(-1); return value; diff --git a/calculator-java/src/main/java/ch/bfh/parser/Parser.java b/calculator-java/src/main/java/ch/bfh/parser/Parser.java index 755313a..9e048a6 100644 --- a/calculator-java/src/main/java/ch/bfh/parser/Parser.java +++ b/calculator-java/src/main/java/ch/bfh/parser/Parser.java @@ -9,8 +9,6 @@ abstract class Parser{ protected double value; protected abstract void parse(); - public double getValue(){ - return value; - } + public abstract double getValue(); } |