Ignore:
Timestamp:
Apr 17, 2020, 12:09:15 AM (5 years ago)
Author:
chronos
Message:
  • Added: Support for String, Integer and Boolean types.
  • Added: Support for more system defined functions..
  • Added: Support for line comments.
  • Added: For-To-Do construction.
  • Added: Defined function parameters and and parsing function calls with parameters.
  • Modified: Improved handling of expressions.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/interpreter2/UTokenizer.pas

    r200 r202  
    3030
    3131  TTokenizerState = (tsNone, tsIdentifier, tsString, tsStringEnd, tsNumber,
    32     tsSpecialSymbol);
     32    tsSpecialSymbol, tsLineComment);
    3333
    3434  { TTokenizer }
     
    4848    function IsSpecialSymbol2(Text: string): Boolean;
    4949    function IsIdentifier(Text: string): Boolean;
     50    function IsOperator(Text: string): Boolean;
    5051    function IsKeyword(Text: string): Boolean;
    5152    procedure Init;
    5253    function GetNext: TToken;
    53     function CheckNext(Text: string; Kind: TTokenKind = tkUnknown): Boolean;
     54    function CheckNext(Text: string; Kind: TTokenKind): Boolean;
    5455    function CheckNextKind(Kind: TTokenKind): Boolean;
    55     procedure Expect(Text: string; Kind: TTokenKind = tkUnknown);
     56    procedure Expect(Text: string; Kind: TTokenKind);
    5657    procedure Error(Text: string);
    5758    property OnError: TErrorEvent read FOnError write FOnError;
     
    109110begin
    110111  Result := (C = ';') or (C = '.') or (C = '(') or (C = ')') or (C = '=') or
    111     (C = ':');
     112    (C = ':') or (C = '+') or (C = '-') or (C = ',') or (C = '/') or
     113    (C = '<') or (C = '>');
    112114end;
    113115
    114116function TTokenizer.IsSpecialSymbol2(Text: string): Boolean;
    115117begin
    116   Result := (Text = ':=');
     118  Result := (Text = ':=') or (Text = '//') or (Text = '<>');
    117119end;
    118120
     
    137139end;
    138140
     141function TTokenizer.IsOperator(Text: string): Boolean;
     142begin
     143  Result := (Text = '+') or (Text = '-') or (Text = '=') or (Text = '<>');
     144end;
     145
    139146function TTokenizer.IsKeyword(Text: string): Boolean;
    140147begin
    141148  Result := (Text = 'begin') or (Text = 'end') or (Text = 'program') or
    142149  (Text = 'var') or (Text = 'const') or (Text = 'if') or (Text = 'then') or
    143   (Text = 'else') or (Text = 'while') or (Text = 'do');
     150  (Text = 'else') or (Text = 'while') or (Text = 'do') or (Text = 'for') or
     151  (Text = 'to');
    144152end;
    145153
     
    229237      end;
    230238    end else
     239    if State = tsLineComment then begin
     240      if C = #10 then begin
     241        State := tsNone;
     242      end else Pos.Increment;
     243    end else
    231244    if State = tsSpecialSymbol then begin
    232245      if IsSpecialSymbol2(Result.Text + C) then begin
    233246        Result.Text := Result.Text + C;
    234247        Pos.Increment;
    235         Break;
     248        if Result.Text = '//' then begin
     249          Result.Text := '';
     250          State := tsLineComment;
     251        end else Break;
    236252      end else begin
    237253        Break;
     
    242258end;
    243259
    244 function TTokenizer.CheckNext(Text: string; Kind: TTokenKind = tkUnknown): Boolean;
     260function TTokenizer.CheckNext(Text: string; Kind: TTokenKind): Boolean;
    245261var
    246262  LastPos: TTokenizerPos;
     
    264280end;
    265281
    266 procedure TTokenizer.Expect(Text: string; Kind: TTokenKind = tkUnknown);
     282procedure TTokenizer.Expect(Text: string; Kind: TTokenKind);
    267283var
    268284  Token: TToken;
Note: See TracChangeset for help on using the changeset viewer.