Changeset 56 for trunk/Compiler/Target/Interpretter/UTargetInterpretter.pas
- Timestamp:
- Jul 13, 2012, 2:10:18 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Compiler/Target/Interpretter/UTargetInterpretter.pas
r52 r56 32 32 procedure RunAssignment(Assignment: TAssignment); 33 33 procedure RunCaseOfEnd(CaseOfEnd: TCaseOfEnd); 34 procedure RunFunction(FunctionCall: TFunctionCall);34 function RunFunction(FunctionCall: TFunctionCall): TValue; 35 35 procedure RunForToDo(ForToDo: TForToDo); 36 function Evaluate(Expression: TExpression): Boolean;36 function Evaluate(Expression: TExpression): TValue; 37 37 public 38 38 Variables: TListObject; … … 50 50 resourcestring 51 51 SUnknownCommandType = 'Unknown command type'; 52 SUnknownOperator = 'Unknown operator "%s"'; 52 53 53 54 { TExecutorInterpretter } … … 94 95 procedure TExecutorInterpretter.RunAssignment(Assignment: TAssignment); 95 96 begin 96 //Assignment.Target := Assignment.Source;97 Assignment.Target.Value := Evaluate(Assignment.Source); 97 98 end; 98 99 … … 111 112 end; 112 113 113 procedure TExecutorInterpretter.RunFunction(FunctionCall: TFunctionCall);114 function TExecutorInterpretter.RunFunction(FunctionCall: TFunctionCall): TValue; 114 115 begin 115 116 RunBeginEnd(FunctionCall.FunctionRef.Code); … … 126 127 end; 127 128 128 function TExecutorInterpretter.Evaluate(Expression: TExpression): Boolean;129 function TExecutorInterpretter.Evaluate(Expression: TExpression): TValue; 129 130 begin 130 // case Expression.NodeType of 131 // ntConstant: ; 132 // end; 131 with Expression do 132 case NodeType of 133 ntConstant: Result := Constant.Value; 134 ntFunction: Result := RunFunction(FunctionCall); 135 ntOperator: begin 136 if OperatorName = '>' then 137 Result := Evaluate(TExpression(SubItems.First)) > Evaluate(TExpression(SubItems.Last)) 138 else if OperatorName = '<' then 139 Result := Evaluate(TExpression(SubItems.First)) < Evaluate(TExpression(SubItems.Last)) 140 else if OperatorName = '+' then 141 Result := Evaluate(TExpression(SubItems.First)) + Evaluate(TExpression(SubItems.Last)) 142 else if OperatorName = '-' then 143 Result := Evaluate(TExpression(SubItems.First)) - Evaluate(TExpression(SubItems.Last)) 144 else if OperatorName = '*' then 145 Result := Evaluate(TExpression(SubItems.First)) * Evaluate(TExpression(SubItems.Last)) 146 else if OperatorName = 'div' then 147 Result := Evaluate(TExpression(SubItems.First)) div Evaluate(TExpression(SubItems.Last)) 148 else raise Exception.CreateFmt(SUnknownOperator, [OperatorName]); 149 end; 150 ntVariable: Result := Variable.Value; 151 end; 133 152 end; 134 153
Note:
See TracChangeset
for help on using the changeset viewer.