Ignore:
Timestamp:
Nov 25, 2020, 12:18:45 AM (4 years ago)
Author:
chronos
Message:
  • Added: Support for more expression operators.
  • Added: Support for brackets in expressions.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/interpreter2/UTokenizer.pas

    r212 r222  
    5353    function GetNext: TToken;
    5454    function CheckNext(Text: string; Kind: TTokenKind): Boolean;
     55    function CheckNextAndRead(Text: string; Kind: TTokenKind): Boolean;
    5556    function CheckNextKind(Kind: TTokenKind): Boolean;
     57    function CheckNextKindAndRead(Kind: TTokenKind): Boolean;
    5658    procedure Expect(Text: string; Kind: TTokenKind);
    5759    procedure Error(Text: string);
     
    111113  Result := (C = ';') or (C = '.') or (C = '(') or (C = ')') or (C = '=') or
    112114    (C = ':') or (C = '+') or (C = '-') or (C = ',') or (C = '/') or
    113     (C = '<') or (C = '>');
     115    (C = '<') or (C = '>') or (C = '*');
    114116end;
    115117
    116118function TTokenizer.IsSpecialSymbol2(Text: string): Boolean;
    117119begin
    118   Result := (Text = ':=') or (Text = '//') or (Text = '<>');
     120  Result := (Text = ':=') or (Text = '//') or (Text = '<>') or (Text = '<=') or
     121    (Text = '>=');
    119122end;
    120123
     
    141144function TTokenizer.IsOperator(Text: string): Boolean;
    142145begin
    143   Result := (Text = '+') or (Text = '-') or (Text = '=') or (Text = '<>');
     146  Result := (Text = '+') or (Text = '-') or (Text = '=') or (Text = '<>') or
     147    (Text = '*') or (Text = '/') or (Text = 'div') or (Text = '<=') or
     148    (Text = '>=') or (Text = 'mod') or (Text = 'shl') or (Text = 'shr') or
     149    (Text = 'and') or (Text = 'or') or (Text = 'xor') or (Text = 'not') or
     150    (Text = '>') or (Text = '<');
    144151end;
    145152
     
    270277end;
    271278
     279function TTokenizer.CheckNextAndRead(Text: string; Kind: TTokenKind): Boolean;
     280var
     281  LastPos: TTokenizerPos;
     282  Token: TToken;
     283begin
     284  LastPos := Pos;
     285  Token := GetNext;
     286  Result := (Token.Text = Text) and (Token.Kind = Kind);
     287  if not Result then Pos := LastPos;
     288end;
     289
    272290function TTokenizer.CheckNextKind(Kind: TTokenKind): Boolean;
    273291var
     
    281299end;
    282300
     301function TTokenizer.CheckNextKindAndRead(Kind: TTokenKind): Boolean;
     302var
     303  LastPos: TTokenizerPos;
     304  Token: TToken;
     305begin
     306  LastPos := Pos;
     307  Token := GetNext;
     308  Result := Token.Kind = Kind;
     309  if not Result then Pos := LastPos;
     310end;
     311
    283312procedure TTokenizer.Expect(Text: string; Kind: TTokenKind);
    284313var
Note: See TracChangeset for help on using the changeset viewer.