Changeset 98 for branches/interpreter


Ignore:
Timestamp:
Feb 3, 2017, 10:48:19 PM (8 years ago)
Author:
chronos
Message:
  • Modified: Handling of constant and variables values with different type.
Location:
branches/interpreter
Files:
3 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • branches/interpreter/Execute3.pas

    r97 r98  
    2121end;
    2222
    23 function ExecuteExpression(Expression: PExpression): Boolean;
     23function ExecuteExpressionBoolean(Expression: PExpression): Boolean;
    2424begin
    2525
     
    2828procedure ExecuteWhileDo(WhileDo: PWhileDo);
    2929begin
    30   if ExecuteExpression(@WhileDo^.Condition) then
     30  while ExecuteExpressionBoolean(@WhileDo^.Condition) do
    3131    ExecuteCommand(@WhileDo^.Command);
    3232end;
     
    3434procedure ExecuteIfThenElse(IfThenElse: PIfThenElse);
    3535begin
    36   if ExecuteExpression(@IfThenElse^.Condition) then
     36  if ExecuteExpressionBoolean(@IfThenElse^.Condition) then
    3737    ExecuteCommand(@IfThenElse^.DoThen)
    3838    else ExecuteCommand(@IfThenElse^.DoElse);
     
    4040
    4141procedure ExecuteExecution(Execution: PExecution);
     42var
     43  I: Integer;
    4244begin
    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}
    4454  ExecuteBeginEnd(@Execution^.Func^.BeginEnd);
    4555end;
     
    4757procedure ExecuteAssignment(Assignment: PAssignment);
    4858begin
    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;
    5065end;
    5166
  • branches/interpreter/Parser3.pas

    r97 r98  
    409409begin
    410410  SetLength(ProgramCode^.Types.Items, 0);
    411   ProgramCode^.Types.Add(TypeCreate('string'));
     411  ProgramCode^.Types.Add(TypeCreate('string', btInteger));
    412412  TypeString := ProgramCode^.Types.GetLast;
    413   ProgramCode^.Types.Add(TypeCreate('Boolean'));
     413  ProgramCode^.Types.Add(TypeCreate('Boolean', btBoolean));
    414414  TypeBoolean := ProgramCode^.Types.GetLast;
    415   ProgramCode^.Types.Add(TypeCreate('Integer'));
     415  ProgramCode^.Types.Add(TypeCreate('Integer', btInteger));
    416416  TypeInteger := ProgramCode^.Types.GetLast;
    417   ProgramCode^.Types.Add(TypeCreate('Char'));
     417  ProgramCode^.Types.Add(TypeCreate('Char', btChar));
    418418  TypeChar := ProgramCode^.Types.GetLast;
    419   ProgramCode^.Types.Add(TypeCreate('Array'));
     419  ProgramCode^.Types.Add(TypeCreate('Array', btArray));
    420420  TypeArray := ProgramCode^.Types.GetLast;
    421421
  • branches/interpreter/Source3.pas

    r97 r98  
    66
    77type
     8  TBaseType = (btBoolean, btInteger, btChar, btShortString, btArray);
     9
    810  TType = record
    911    Name: string;
     12    BaseType: TBaseType;
    1013  end;
    1114  PType = ^TType;
     
    2326    Name: string;
    2427    DataType: PType;
     28    case Integer of
     29      0: (ValueChar: Char);
     30      1: (ValueInteger: Integer);
     31      2: (ValueString: ShortString);
     32      3: (ValueBoolean: Boolean);
    2533  end;
    2634  PVariable = ^TVariable;
     
    3341    function GetByName(Name: string): PVariable;
    3442  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;
    3554
    3655  TFunctionParameter = record
     
    5978      3: (Assignment: TAssignment);
    6079      4: (Execution: TExecution);
    61     end;
    6280 } end;
    6381  PCommand = ^TCommand;
     
    98116    ReturnType: PType;
    99117    BeginEnd: TBeginEnd;
     118    Variables: TVariables;
    100119  end;
    101120  PFunction = ^TFunction;
     
    131150function VariableCreate(Name: string; DataType: PType): TVariable;
    132151function FunctionCreate(Name: string; DataType: PType): TFunction;
    133 function TypeCreate(Name: string): TType;
     152function TypeCreate(Name: string; BaseType: TBaseType): TType;
    134153function FunctionParameterCreate(Name: string; DataType: PType): TFunctionParameter;
    135154
     
    149168end;
    150169
    151 function TypeCreate(Name: string): TType;
    152 begin
    153   Result.Name := Name;
     170function TypeCreate(Name: string; BaseType:TBaseType): TType;
     171begin
     172  Result.Name := Name;
     173  Result.BaseType := BaseType;
    154174end;
    155175
Note: See TracChangeset for help on using the changeset viewer.