summaryrefslogtreecommitdiff
path: root/calc1.pas
diff options
context:
space:
mode:
authorOskari Timperi <oskari.timperi@iki.fi>2015-12-08 22:45:16 +0200
committerOskari Timperi <oskari.timperi@iki.fi>2015-12-08 22:45:16 +0200
commit34758ebd78d39075dc58f88d33a28c700612121c (patch)
tree0e7edc6e525196bdc6e7dbb88fb0111c222b3a8b /calc1.pas
parent266012d2beb4bfb0e4b342fb697a2472cba7d25d (diff)
downloadlbasi-34758ebd78d39075dc58f88d33a28c700612121c.tar.gz
lbasi-34758ebd78d39075dc58f88d33a28c700612121c.zip
handle multiple +/- operations at the beginning of expression
Diffstat (limited to 'calc1.pas')
-rw-r--r--calc1.pas26
1 files changed, 21 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);