summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--calc1.pas26
-rw-r--r--tests/calc1.txt6
2 files changed, 27 insertions, 5 deletions
diff --git a/calc1.pas b/calc1.pas
index c77b427..541ae15 100644
--- a/calc1.pas
+++ b/calc1.pas
@@ -187,11 +187,27 @@ begin
Op := Current;
- if Op.TokenType = TT_Plus then
- Eat(TT_Plus)
- else if Op.TokenType = TT_Minus then
- Eat(TT_Minus)
- else if Op.TokenType = TT_Asterisk then
+ while (Op.TokenType = TT_Plus) or (Op.TokenType = TT_Minus) do
+ begin
+ Eat(Op.TokenType);
+
+ Right := Current;
+ Eat(TT_Integer);
+
+ if Op.TokenType = TT_Plus then
+ Result := TokenInteger(Left).Val + TokenInteger(Right).Val
+ else
+ Result := TokenInteger(Left).Val - TokenInteger(Right).Val;
+
+ TokenInteger(Left).Val := Result;
+
+ Op := Current;
+
+ if Op.TokenType = TT_Eof then
+ Exit;
+ end;
+
+ if Op.TokenType = TT_Asterisk then
Eat(TT_Asterisk)
else
Eat(TT_Slash);
diff --git a/tests/calc1.txt b/tests/calc1.txt
index ad30e6e..127a498 100644
--- a/tests/calc1.txt
+++ b/tests/calc1.txt
@@ -31,3 +31,9 @@ Simple calculations
10/2 5
3*4 12
+
+Multiple Runs Of Plus And Minus
+ [Template] The result of ${calculations} should be ${expected}
+ 1+1+1 3
+ 1-1-1 -1
+ 5+1-2 4