Ignore:
Timestamp:
Jan 16, 2018, 10:38:33 AM (7 years ago)
Author:
chronos
Message:
  • Modified: General definition of functions. Static functions are now dynamic predefined.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/easy compiler/UCompiler.pas

    r139 r140  
    159159  Instruction: TSourceInstruction;
    160160  NewReference: TSourceReference;
     161  Funct: TSourceFunction;
     162  Param: TSourceFunctionParameter;
    161163
    162164function ParseReference: TSourceReference;
     
    171173    NewReference := TSourceReferenceVariable.Create;
    172174    TSourceReferenceVariable(NewReference).Variable :=
    173       Code.Variables.Find(Token.Text);
     175      Code.Variables.Search(Token.Text);
    174176    if TSourceReferenceVariable(NewReference).Variable = nil then
    175177      raise Exception.Create('Variable not found: ' + Token.Text);
     
    184186    NewReference := TSourceReferenceVariable.Create;
    185187    TSourceReferenceVariable(NewReference).Variable :=
    186       Code.Variables.Find(Token.Text);
     188      Code.Variables.Search(Token.Text);
    187189    if TSourceReferenceVariable(NewReference).Variable = nil then begin
    188190      if Initialize then
     
    201203    if Token.Kind = stIdentifier then begin
    202204      Keyword := LowerCase(Token.Text);
    203       if Keyword = 'print' then begin
     205      Funct := Code.Functions.Search(Keyword);
     206      if Assigned(Funct) then begin
    204207        Instruction := TSourceInstructionFunction.Create;
    205         TSourceInstructionFunction(Instruction).Name := 'print';
    206         TSourceInstructionFunction(Instruction).AddParameter(ParseReference);
    207         Code.Instructions.Add(Instruction);
    208       end else
    209       if Keyword = 'println' then begin
    210         Instruction := TSourceInstructionFunction.Create;
    211         TSourceInstructionFunction(Instruction).Name := 'println';
    212         TSourceInstructionFunction(Instruction).AddParameter(ParseReference);
    213         Code.Instructions.Add(Instruction);
    214       end else
    215       if Keyword = 'assign' then begin
    216         Instruction := TSourceInstructionFunction.Create;
    217         TSourceInstructionFunction(Instruction).Name := 'assign';
    218         TSourceInstructionFunction(Instruction).AddParameter(ParseReferenceVariable(True));
    219         TSourceInstructionFunction(Instruction).AddParameter(ParseReference);
     208        TSourceInstructionFunction(Instruction).Name := Keyword;
     209        for Param in Funct.Parameters do
     210        if Param.Kind = pkString then begin
     211          TSourceInstructionFunction(Instruction).AddParameter(ParseReference)
     212        end else
     213        if Param.Kind = pkVariable then begin
     214          TSourceInstructionFunction(Instruction).AddParameter(ParseReferenceVariable(True));
     215        end else
     216        raise Exception.Create('Unsupported parameter type.');
    220217        Code.Instructions.Add(Instruction);
    221218      end else raise Exception.Create('Unsupported keyword: ' + Token.Text);
Note: See TracChangeset for help on using the changeset viewer.