|
@@ -25,8 +25,8 @@ uses
|
|
|
Type
|
|
|
// tokens
|
|
|
TTokenType = (ttPlus, ttMinus, ttLessThan, ttLargerThan, ttEqual, ttDiv,
|
|
|
- ttMul, ttLeft, ttRight, ttLessThanEqual, ttLargerThanEqual,
|
|
|
- ttunequal, ttNumber, ttString, ttIdentifier,
|
|
|
+ ttMod, ttMul, ttLeft, ttRight, ttLessThanEqual,
|
|
|
+ ttLargerThanEqual, ttunequal, ttNumber, ttString, ttIdentifier,
|
|
|
ttComma, ttAnd, ttOr, ttXor, ttTrue, ttFalse, ttNot, ttif,
|
|
|
ttCase, ttPower, ttEOF); // keep ttEOF last
|
|
|
|
|
@@ -329,6 +329,17 @@ Type
|
|
|
Procedure GetNodeValue(var Result : TFPExpressionResult); override;
|
|
|
end;
|
|
|
|
|
|
+ { TFPModuloOperation }
|
|
|
+
|
|
|
+ TFPModuloOperation = Class(TMathOperation)
|
|
|
+ Public
|
|
|
+ Procedure Check; override;
|
|
|
+ Function AsString : string ; override;
|
|
|
+ Function NodeType : TResultType; override;
|
|
|
+ Procedure GetNodeValue(var Result : TFPExpressionResult); override;
|
|
|
+ end;
|
|
|
+
|
|
|
+
|
|
|
{ TFPPowerOperation }
|
|
|
TFPPowerOperation = class(TMathOperation)
|
|
|
public
|
|
@@ -876,6 +887,37 @@ begin
|
|
|
FreeAndNil(Builtins);
|
|
|
end;
|
|
|
|
|
|
+{ TFPModuloOperation }
|
|
|
+
|
|
|
+procedure TFPModuloOperation.Check;
|
|
|
+begin
|
|
|
+ CheckNodeType(Left,[rtInteger]);
|
|
|
+ CheckNodeType(Right,[rtInteger]);
|
|
|
+ inherited Check;
|
|
|
+end;
|
|
|
+
|
|
|
+function TFPModuloOperation.AsString: string;
|
|
|
+begin
|
|
|
+ Result:=Left.AsString+' mod '+Right.asString;
|
|
|
+end;
|
|
|
+
|
|
|
+function TFPModuloOperation.NodeType: TResultType;
|
|
|
+begin
|
|
|
+ Result:=rtInteger;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TFPModuloOperation.GetNodeValue(var Result: TFPExpressionResult);
|
|
|
+
|
|
|
+Var
|
|
|
+ RRes : TFPExpressionResult;
|
|
|
+
|
|
|
+begin
|
|
|
+ Left.GetNodeValue(Result);
|
|
|
+ Right.GetNodeValue(RRes);
|
|
|
+ Result.ResInteger:=Result.ResInteger mod RRes.ResInteger;
|
|
|
+ Result.ResultType:=rtInteger;
|
|
|
+end;
|
|
|
+
|
|
|
{ TAggregateMax }
|
|
|
|
|
|
procedure TAggregateMax.InitAggregate;
|
|
@@ -1243,6 +1285,8 @@ begin
|
|
|
Result:=ttif
|
|
|
else if (S='case') then
|
|
|
Result:=ttcase
|
|
|
+ else if (S='mod') then
|
|
|
+ Result:=ttMod
|
|
|
else
|
|
|
Result:=ttIdentifier;
|
|
|
end;
|
|
@@ -1623,7 +1667,7 @@ begin
|
|
|
{$ifdef debugexpr} Writeln('Level 4 ',TokenName(TokenType),': ',CurrentToken);{$endif debugexpr}
|
|
|
Result:=Level5;
|
|
|
try
|
|
|
- while (TokenType in [ttMul,ttDiv]) do
|
|
|
+ while (TokenType in [ttMul,ttDiv,ttMod]) do
|
|
|
begin
|
|
|
tt:=TokenType;
|
|
|
GetToken;
|
|
@@ -1632,6 +1676,7 @@ begin
|
|
|
Case tt of
|
|
|
ttMul : Result:=TFPMultiplyOperation.Create(Result,Right);
|
|
|
ttDiv : Result:=TFPDivideOperation.Create(Result,Right);
|
|
|
+ ttMod : Result:=TFPModuloOperation.Create(Result,Right);
|
|
|
end;
|
|
|
end;
|
|
|
Except
|