Changeset 102 for branches/interpreter/Parser3.pas
- Timestamp:
- Feb 11, 2017, 6:55:42 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/interpreter/Parser3.pas
r101 r102 10 10 procedure ParseProgram(ProgramCode: PProgramCode); 11 11 12 13 var 14 InnerText: string; 15 InnerTextPos: Integer; 12 16 13 17 implementation … … 61 65 procedure ReadInputAll; 62 66 var 67 LastC: Char; 63 68 C: Char; 64 begin 69 Inner: Boolean; 70 begin 71 LastC := #0; 65 72 InputTextPos := 1; 66 73 InputText := ''; 74 InnerTextPos := 1; 75 InnerText := ''; 76 Inner := False; 67 77 while not Eof do begin 68 78 Read(C); 69 InputText := InputText + C; 79 if ((LastC = #0) or (LastC = #13) or (LastC = #10)) and (C = '|') then begin 80 Inner := True; 81 LastC := C; 82 Continue; 83 end else 84 if ((LastC = #0) or (LastC = #13) or (LastC = #10)) and (C <> '|') then begin 85 Inner := False; 86 end; 87 if Inner then InnerText := InnerText + C 88 else InputText := InputText + C; 89 LastC := C; 70 90 end; 71 91 end; … … 296 316 I: Integer; 297 317 II: Integer; 298 begin 318 FoundOperator: Boolean; 319 OldPos: Integer; 320 begin 321 OldPos := InputTextPos; 299 322 Result := True; 323 FoundOperator := False; 300 324 repeat 301 325 if CheckNext('(') then begin … … 312 336 Expression^.Items[Length(Expression^.Items) - 1].NodeType := ntOperator; 313 337 Expression^.Items[Length(Expression^.Items) - 1].OperatorType := ExpOperator; 338 FoundOperator := True; 314 339 end else 315 340 if ParseGetValue(@GetValue, True) then begin … … 322 347 end; 323 348 until False; 349 if not FoundOperator then begin 350 Result := False; 351 InputTextPos := OldPos; 352 Exit; 353 end; 324 354 325 355 if Length(Expression^.Items) > 0 then begin … … 340 370 Expression^.Items[I].Associated := True; 341 371 SetLength(Expression^.Items[I].Items, 2); 342 Expression^.Items[I].Items[ 1] := Expression^.Items[I - 1];343 Expression^.Items[I].Items[ 0] := Expression^.Items[I + 1];372 Expression^.Items[I].Items[0] := Expression^.Items[I - 1]; 373 Expression^.Items[I].Items[1] := Expression^.Items[I + 1]; 344 374 DeleteExpressionItem(Expression, I + 1); 345 375 DeleteExpressionItem(Expression, I - 1); … … 686 716 ProgramCode^.Functions.Add(FunctionCreate('Read', nil)); 687 717 FuncRead := ProgramCode^.Functions.GetLast; 688 FuncRead^.Parameters.Add(FunctionParameterCreate('Output', TypeChar)); 718 FuncRead^.Parameters.Add(FunctionParameterCreate('Output', TypeChar, True)); 719 FuncRead^.Variables.Add(VariableCreate('Output', TypeChar)); 689 720 ProgramCode^.Functions.Add(FunctionCreate('Eof', TypeBoolean)); 690 721 ProgramCode^.Functions.Add(FunctionCreate('Length', TypeInteger));
Note:
See TracChangeset
for help on using the changeset viewer.