Changeset 101 for branches/interpreter/Parser3.pas
- Timestamp:
- Feb 11, 2017, 4:35:08 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/interpreter/Parser3.pas
r100 r101 90 90 N := N * 10; 91 91 I := I - 1; 92 end; 93 end; 94 95 function IntToStr(Value: Integer): string; 96 begin 97 Result := ''; 98 while Value > 0 do begin 99 Result := Chr(Ord('0') + Value mod 10) + Result; 100 Value := Value div 10; 92 101 end; 93 102 end; … … 292 301 if CheckNext('(') then begin 293 302 Expect('('); 303 SetLength(SubExpression.Items, 0); 294 304 if ParseExpression(@SubExpression) then begin 295 305 SetLength(Expression^.Items, Length(Expression^.Items) + 1); … … 316 326 // Build expression tree using operator precedence 317 327 for II := 0 to Length(OperatorPrecedence) - 1 do begin 318 I := 1;328 I := 0; 319 329 while (I < Length(Expression^.Items) - 1) do begin 320 330 if (TExpression(Expression^.Items[I]).NodeType = ntOperator) and … … 338 348 end; 339 349 end; 350 351 if Length(Expression^.Items) = 1 then begin 352 Expression^.NodeType := Expression^.Items[0].NodeType; 353 Expression^.OperatorType := Expression^.Items[0].OperatorType; 354 Expression^.Value := Expression^.Items[0].Value; 355 // Move subtitem one node up 356 SetLength(Expression^.Items, Length(Expression^.Items[0].Items)); 357 I := Length(Expression^.Items) - 1; 358 while I >= 0 do begin 359 Expression^.Items[I] := Expression^.Items[0].Items[I]; 360 I := I - 1; 361 end; 362 end else ShowError('Expression error ' + IntToStr(Length(Expression^.Items))); 340 363 end; 341 364 end; … … 362 385 Value: TConstant; 363 386 begin 387 FillChar(Expression, SizeOf(TExpression), 0); 388 FillChar(FunctionCall, SizeOf(TFunctionCall), 0); 389 FillChar(Value, SizeOf(TConstant), 0); 390 364 391 Result := True; 365 392 if not NoExpression and ParseExpression(@Expression) then begin … … 443 470 Assignment: TAssignment; 444 471 begin 472 FillChar(IfThenElse, SizeOf(TIfThenElse), 0); 473 FillChar(WhileDo, SizeOf(TWhileDo), 0); 474 FillChar(BeginEnd, SizeOf(TBeginEnd), 0); 475 FillChar(Execution, SizeOf(TExecution), 0); 476 FillChar(Assignment, SizeOf(TAssignment), 0); 477 445 478 Result := True; 446 479 if ParseBeginEnd(@BeginEnd) then begin … … 632 665 begin 633 666 SetLength(ProgramCode^.Types.Items, 0); 634 ProgramCode^.Types.Add(TypeCreate('string', bt Integer));667 ProgramCode^.Types.Add(TypeCreate('string', btShortString)); 635 668 TypeString := ProgramCode^.Types.GetLast; 636 669 ProgramCode^.Types.Add(TypeCreate('Boolean', btBoolean)); … … 650 683 FuncWriteLn := ProgramCode^.Functions.GetLast; 651 684 FuncWriteLn^.Parameters.Add(FunctionParameterCreate('Text', TypeString)); 685 FuncWriteLn^.Variables.Add(VariableCreate('Text', TypeString)); 652 686 ProgramCode^.Functions.Add(FunctionCreate('Read', nil)); 653 687 FuncRead := ProgramCode^.Functions.GetLast; … … 657 691 FuncLength := ProgramCode^.Functions.GetLast; 658 692 FuncLength^.Parameters.Add(FunctionParameterCreate('Array', TypeArray)); 693 FuncLength^.Variables.Add(VariableCreate('Array', TypeArray)); 659 694 ProgramCode^.Functions.Add(FunctionCreate('SetLength', nil)); 660 695 FuncSetLength := ProgramCode^.Functions.GetLast; 661 696 FuncSetLength^.Parameters.Add(FunctionParameterCreate('Array', TypeArray)); 697 FuncSetLength^.Variables.Add(VariableCreate('Array', TypeArray)); 662 698 FuncSetLength^.Parameters.Add(FunctionParameterCreate('Count', TypeInteger)); 699 FuncSetLength^.Variables.Add(VariableCreate('Count', TypeInteger)); 663 700 end; 664 701
Note:
See TracChangeset
for help on using the changeset viewer.