Changeset 202 for branches/interpreter2/UTokenizer.pas
- Timestamp:
- Apr 17, 2020, 12:09:15 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/interpreter2/UTokenizer.pas
r200 r202 30 30 31 31 TTokenizerState = (tsNone, tsIdentifier, tsString, tsStringEnd, tsNumber, 32 tsSpecialSymbol );32 tsSpecialSymbol, tsLineComment); 33 33 34 34 { TTokenizer } … … 48 48 function IsSpecialSymbol2(Text: string): Boolean; 49 49 function IsIdentifier(Text: string): Boolean; 50 function IsOperator(Text: string): Boolean; 50 51 function IsKeyword(Text: string): Boolean; 51 52 procedure Init; 52 53 function GetNext: TToken; 53 function CheckNext(Text: string; Kind: TTokenKind = tkUnknown): Boolean;54 function CheckNext(Text: string; Kind: TTokenKind): Boolean; 54 55 function CheckNextKind(Kind: TTokenKind): Boolean; 55 procedure Expect(Text: string; Kind: TTokenKind = tkUnknown);56 procedure Expect(Text: string; Kind: TTokenKind); 56 57 procedure Error(Text: string); 57 58 property OnError: TErrorEvent read FOnError write FOnError; … … 109 110 begin 110 111 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 = '>'); 112 114 end; 113 115 114 116 function TTokenizer.IsSpecialSymbol2(Text: string): Boolean; 115 117 begin 116 Result := (Text = ':=') ;118 Result := (Text = ':=') or (Text = '//') or (Text = '<>'); 117 119 end; 118 120 … … 137 139 end; 138 140 141 function TTokenizer.IsOperator(Text: string): Boolean; 142 begin 143 Result := (Text = '+') or (Text = '-') or (Text = '=') or (Text = '<>'); 144 end; 145 139 146 function TTokenizer.IsKeyword(Text: string): Boolean; 140 147 begin 141 148 Result := (Text = 'begin') or (Text = 'end') or (Text = 'program') or 142 149 (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'); 144 152 end; 145 153 … … 229 237 end; 230 238 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 231 244 if State = tsSpecialSymbol then begin 232 245 if IsSpecialSymbol2(Result.Text + C) then begin 233 246 Result.Text := Result.Text + C; 234 247 Pos.Increment; 235 Break; 248 if Result.Text = '//' then begin 249 Result.Text := ''; 250 State := tsLineComment; 251 end else Break; 236 252 end else begin 237 253 Break; … … 242 258 end; 243 259 244 function TTokenizer.CheckNext(Text: string; Kind: TTokenKind = tkUnknown): Boolean;260 function TTokenizer.CheckNext(Text: string; Kind: TTokenKind): Boolean; 245 261 var 246 262 LastPos: TTokenizerPos; … … 264 280 end; 265 281 266 procedure TTokenizer.Expect(Text: string; Kind: TTokenKind = tkUnknown);282 procedure TTokenizer.Expect(Text: string; Kind: TTokenKind); 267 283 var 268 284 Token: TToken;
Note:
See TracChangeset
for help on using the changeset viewer.