summaryrefslogtreecommitdiff
path: root/calc1.pas
diff options
context:
space:
mode:
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);