Changeset 107


Ignore:
Timestamp:
Jul 18, 2017, 12:53:15 AM (7 years ago)
Author:
chronos
Message:
  • Added: Calculate source X,Y position. Show that position in error message.
Location:
branches/interpreter/interpreter4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/interpreter/interpreter4/Execute.pas

    r104 r107  
    301301  end else
    302302  if Execution^.Func^.Name = 'Read' then begin
    303     ExecutionContextCurrent^.VariableValues.GetByName('Output')^.ValueChar := InnerText[InnerTextPos];
    304     InnerTextPos := InnerTextPos + 1;
     303    ExecutionContextCurrent^.VariableValues.GetByName('Output')^.ValueChar := InnerText[InnerTextPos.Index];
     304    InnerTextPos.Index := InnerTextPos.Index + 1;
    305305  end else
    306306  if Execution^.Func^.Name = 'Eof' then begin
    307307    ExecuteBuildInSetResult(Execution, 'Boolean');
    308     ExecutionContextCurrent^.VariableValues.GetByName('Result')^.ValueBoolean := InnerTextPos > Length(InnerText);
     308    ExecutionContextCurrent^.VariableValues.GetByName('Result')^.ValueBoolean := InnerTextPos.Index > Length(InnerText);
    309309  end else ShowError('Unsupported build-in function.');
    310310end;
  • branches/interpreter/interpreter4/Parser.pas

    r106 r107  
    1111
    1212
     13type
     14  TTextPos = record
     15    Index: Integer;
     16    X: Integer;
     17    Y: Integer;
     18    PrevX: Integer;
     19    PrevY: Integer;
     20  end;
     21
    1322var
    1423  InnerText: string;
    15   InnerTextPos: Integer;
     24  InnerTextPos: TTextPos;
    1625
    1726implementation
     
    2332var
    2433  InputText: string;
    25   InputTextPos: Integer;
     34  InputTextPos: TTextPos;
     35  InputTextFileName: string;
    2636  LastTokenType: TTokenType;
    2737
     
    110120end;
    111121
     122function IntToStr(Value: Integer): string;
     123begin
     124  Result := '';
     125  while Value > 0 do begin
     126    Result := Chr(Ord('0') + Value mod 10) + Result;
     127    Value := Value div 10;
     128  end;
     129end;
     130
    112131procedure ShowError(Text: string);
    113132begin
    114   WriteLn(Text);
    115   WriteLn(Copy(InputText, InputTextPos, 50));
     133  WriteLn(InputTextFileName + ' (' + IntToStr(InputTextPos.Y) + ',' + IntToStr(InputTextPos.X) + ') ' +  Text);
     134  WriteLn(Copy(InputText, InputTextPos.Index, 50));
    116135  Halt;
    117136end;
     
    124143begin
    125144  LastC := #0;
    126   InputTextPos := 1;
     145  InputTextPos.Index := 1;
     146  InputTextPos.X := 1;
     147  InputTextPos.Y := 1;
     148  InputTextPos.PrevX := 1;
     149  InputTextPos.PrevY := 1;
    127150  InputText := '';
    128   InnerTextPos := 1;
     151  InnerTextPos.Index := 1;
     152  InnerTextPos.PrevX := 1;
     153  InnerTextPos.PrevY := 1;
    129154  InnerText := '';
    130155  Inner := False;
     
    147172function ReadChar: Char;
    148173begin
    149   if InputTextPos >= Length(InputText) then ShowError('Premature end of source');
    150   Result := InputText[InputTextPos];
    151   InputTextPos := InputTextPos + 1;
     174  if InputTextPos.Index >= Length(InputText) then ShowError('Premature end of source');
     175  Result := InputText[InputTextPos.Index];
     176  InputTextPos.Index := InputTextPos.Index + 1;
     177  InputTextPos.PrevX := InputTextPos.X;
     178  InputTextPos.PrevY := InputTextPos.Y;
     179  InputTextPos.X := InputTextPos.X + 1;
     180  if Result = #10 then begin
     181    InputTextPos.Y := InputTextPos.Y + 1;
     182    InputTextPos.X := 1;
     183  end;
     184end;
     185
     186procedure InputTextPosSetPrev;
     187begin
     188  InputTextPos.X := InputTextPos.PrevX;
     189  InputTextPos.Y := InputTextPos.PrevY;
     190  InputTextPos.Index := InputTextPos.Index - 1;
    152191end;
    153192
     
    164203    N := N * 10;
    165204    I := I - 1;
    166   end;
    167 end;
    168 
    169 function IntToStr(Value: Integer): string;
    170 begin
    171   Result := '';
    172   while Value > 0 do begin
    173     Result := Chr(Ord('0') + Value mod 10) + Result;
    174     Value := Value div 10;
    175205  end;
    176206end;
     
    196226          LastTokenType := ttChar;
    197227        end;
    198         InputTextPos := InputTextPos - 1;
     228        InputTextPosSetPrev;
    199229        Break;
    200230      end else Result := Result + C;
     
    230260              LastTokenType := ttComment;
    231261              Continue;
    232             end else InputTextPos := InputTextPos - 1;
     262            end else InputTextPosSetPrev;
    233263          end;
    234264          Break;
    235265        end else begin
    236           InputTextPos := InputTextPos - 1;
     266          InputTextPosSetPrev;
    237267          Break;
    238268        end;
     
    258288begin
    259289  Result := ReadNextInternal;
    260   WriteLn('ReadNext: ' + Result);
     290  //WriteLn('ReadNext: ' + Result);
    261291end;
    262292
     
    264294var
    265295  Next: string;
    266   OldPos: Integer;
     296  OldPos: TTextPos;
    267297begin
    268298  OldPos := InputTextPos;
     
    297327function ParseVariable(out Variable: PVariable): Boolean;
    298328var
    299   OldPos: Integer;
     329  OldPos: TTextPos;
    300330  Next: string;
    301331  SelfVariable: PVariable;
     
    341371      Result := False;
    342372      InputTextPos := OldPos;
     373      Break;
    343374    end;
    344375  until False;
     
    357388function ParseConstant(out Constant: PConstant): Boolean;
    358389var
    359   OldPos: Integer;
     390  OldPos: TTextPos;
    360391  Next: string;
    361392begin
     
    383414function ParseOperator(out ExpOperator: TOperator): Boolean;
    384415var
    385   OldPos: Integer;
     416  OldPos: TTextPos;
    386417  OperatorName: string;
    387418begin
     
    400431function ParseValue(Value: PConstant): Boolean;
    401432var
    402   OldPos: Integer;
     433  OldPos: TTextPos;
    403434  Text: string;
    404435begin
     
    443474  II: Integer;
    444475  FoundOperator: Boolean;
    445   OldPos: Integer;
     476  OldPos: TTextPos;
    446477  //E: TExpression;
    447478begin
     
    598629function ParseExecution(Execution: PExecution): Boolean;
    599630var
    600   OldPos: Integer;
     631  OldPos: TTextPos;
    601632  Next: string;
    602633  Func: PFunction;
     
    776807  VarName: string;
    777808  VarType: PType;
    778   OldPos: Integer;
     809  OldPos: TTextPos;
    779810  Value: string;
    780811  I: Integer;
     
    831862  ConstName: string;
    832863  ConstType: PType;
    833   OldPos: Integer;
     864  OldPos: TTextPos;
    834865  Value: string;
    835866begin
     
    10181049function ParseTypeSimple(TypeItem: PType): Boolean;
    10191050var
    1020   OldPos: Integer;
     1051  OldPos: TTextPos;
    10211052  Name: string;
    10221053  T: PType;
     
    10371068function ParseTypeSimpleForward(TypeItem: PType): Boolean;
    10381069var
    1039   OldPos: Integer;
     1070  OldPos: TTextPos;
    10401071  Name: string;
    10411072begin
     
    12071238  Name: string;
    12081239  TypeName: string;
    1209   OldPos: Integer;
     1240  OldPos: TTextPos;
    12101241  NewType: TType;
    12111242begin
     
    12371268var
    12381269  OldInputText: string;
    1239   OldInputTextPos: Integer;
     1270  OldInputTextPos: TTextPos;
    12401271  UnitFile: Text;
    12411272  Directive: TDirective;
  • branches/interpreter/interpreter4/interpreter.lpi

    r106 r107  
    116116      <Item4>
    117117        <Name Value="RunError(101)"/>
     118        <Enabled Value="False"/>
    118119      </Item4>
    119120      <Item5>
    120121        <Name Value="Unknown"/>
     122        <Enabled Value="False"/>
    121123      </Item5>
    122124    </Exceptions>
Note: See TracChangeset for help on using the changeset viewer.