Changeset 98
- Timestamp:
- Feb 3, 2017, 10:48:19 PM (8 years ago)
- Location:
- branches/interpreter
- Files:
-
- 3 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/interpreter/Execute3.pas
r97 r98 21 21 end; 22 22 23 function ExecuteExpression (Expression: PExpression): Boolean;23 function ExecuteExpressionBoolean(Expression: PExpression): Boolean; 24 24 begin 25 25 … … 28 28 procedure ExecuteWhileDo(WhileDo: PWhileDo); 29 29 begin 30 if ExecuteExpression(@WhileDo^.Condition) then30 while ExecuteExpressionBoolean(@WhileDo^.Condition) do 31 31 ExecuteCommand(@WhileDo^.Command); 32 32 end; … … 34 34 procedure ExecuteIfThenElse(IfThenElse: PIfThenElse); 35 35 begin 36 if ExecuteExpression (@IfThenElse^.Condition) then36 if ExecuteExpressionBoolean(@IfThenElse^.Condition) then 37 37 ExecuteCommand(@IfThenElse^.DoThen) 38 38 else ExecuteCommand(@IfThenElse^.DoElse); … … 40 40 41 41 procedure ExecuteExecution(Execution: PExecution); 42 var 43 I: Integer; 42 44 begin 43 // Set parameters 45 { Execution^.Func^.Variables.Add(VariableCreate('Result', Execution^.Func^.ReturnType)); 46 for I := 0 to Length(Execution^.Func^.Parameters.Items) - 1 do begin 47 Execution^.Func^.Variables.Add(VariableCreate(Execution^.Func^.Parameters.Items[I].Name, 48 Execution^.Func^.Parameters.Items[I].DataType)); 49 case Assignment^.Destination^.DataType^.BaseType of 50 Execution^.Func^.Variables.Items[Length(Execution^.Func^.Variables.Items) - 1].V 51 end; 52 end; 53 } 44 54 ExecuteBeginEnd(@Execution^.Func^.BeginEnd); 45 55 end; … … 47 57 procedure ExecuteAssignment(Assignment: PAssignment); 48 58 begin 49 59 case Assignment^.Destination^.DataType^.BaseType of 60 btBoolean: Assignment^.Destination.ValueBoolean := ExecuteExpressionBoolean(@Assignment^.Source); 61 //btChar: Assignment^.Destination.ValueBoolean := ExecuteExpressionChar(@Assignment^.Source); 62 //btString: Assignment^.Destination.ValueBoolean := ExecuteExpressionString(@Assignment^.Source); 63 //btInteger: Assignment^.Destination.ValueBoolean := ExecuteExpressionInteger(@Assignment^.Source); 64 end; 50 65 end; 51 66 -
branches/interpreter/Parser3.pas
r97 r98 409 409 begin 410 410 SetLength(ProgramCode^.Types.Items, 0); 411 ProgramCode^.Types.Add(TypeCreate('string' ));411 ProgramCode^.Types.Add(TypeCreate('string', btInteger)); 412 412 TypeString := ProgramCode^.Types.GetLast; 413 ProgramCode^.Types.Add(TypeCreate('Boolean' ));413 ProgramCode^.Types.Add(TypeCreate('Boolean', btBoolean)); 414 414 TypeBoolean := ProgramCode^.Types.GetLast; 415 ProgramCode^.Types.Add(TypeCreate('Integer' ));415 ProgramCode^.Types.Add(TypeCreate('Integer', btInteger)); 416 416 TypeInteger := ProgramCode^.Types.GetLast; 417 ProgramCode^.Types.Add(TypeCreate('Char' ));417 ProgramCode^.Types.Add(TypeCreate('Char', btChar)); 418 418 TypeChar := ProgramCode^.Types.GetLast; 419 ProgramCode^.Types.Add(TypeCreate('Array' ));419 ProgramCode^.Types.Add(TypeCreate('Array', btArray)); 420 420 TypeArray := ProgramCode^.Types.GetLast; 421 421 -
branches/interpreter/Source3.pas
r97 r98 6 6 7 7 type 8 TBaseType = (btBoolean, btInteger, btChar, btShortString, btArray); 9 8 10 TType = record 9 11 Name: string; 12 BaseType: TBaseType; 10 13 end; 11 14 PType = ^TType; … … 23 26 Name: string; 24 27 DataType: PType; 28 case Integer of 29 0: (ValueChar: Char); 30 1: (ValueInteger: Integer); 31 2: (ValueString: ShortString); 32 3: (ValueBoolean: Boolean); 25 33 end; 26 34 PVariable = ^TVariable; … … 33 41 function GetByName(Name: string): PVariable; 34 42 end; 43 44 TConstant = record 45 Name: string; 46 DataType: PType; 47 case Integer of 48 0: (ValueChar: Char); 49 1: (ValueInteger: Integer); 50 2: (ValueString: ShortString); 51 3: (ValueBoolean: Boolean); 52 end; 53 PConstant = ^TConstant; 35 54 36 55 TFunctionParameter = record … … 59 78 3: (Assignment: TAssignment); 60 79 4: (Execution: TExecution); 61 end;62 80 } end; 63 81 PCommand = ^TCommand; … … 98 116 ReturnType: PType; 99 117 BeginEnd: TBeginEnd; 118 Variables: TVariables; 100 119 end; 101 120 PFunction = ^TFunction; … … 131 150 function VariableCreate(Name: string; DataType: PType): TVariable; 132 151 function FunctionCreate(Name: string; DataType: PType): TFunction; 133 function TypeCreate(Name: string ): TType;152 function TypeCreate(Name: string; BaseType: TBaseType): TType; 134 153 function FunctionParameterCreate(Name: string; DataType: PType): TFunctionParameter; 135 154 … … 149 168 end; 150 169 151 function TypeCreate(Name: string): TType; 152 begin 153 Result.Name := Name; 170 function TypeCreate(Name: string; BaseType:TBaseType): TType; 171 begin 172 Result.Name := Name; 173 Result.BaseType := BaseType; 154 174 end; 155 175
Note:
See TracChangeset
for help on using the changeset viewer.