- Timestamp:
- Jul 18, 2017, 12:53:15 AM (7 years ago)
- Location:
- branches/interpreter/interpreter4
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/interpreter/interpreter4/Execute.pas
r104 r107 301 301 end else 302 302 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; 305 305 end else 306 306 if Execution^.Func^.Name = 'Eof' then begin 307 307 ExecuteBuildInSetResult(Execution, 'Boolean'); 308 ExecutionContextCurrent^.VariableValues.GetByName('Result')^.ValueBoolean := InnerTextPos > Length(InnerText);308 ExecutionContextCurrent^.VariableValues.GetByName('Result')^.ValueBoolean := InnerTextPos.Index > Length(InnerText); 309 309 end else ShowError('Unsupported build-in function.'); 310 310 end; -
branches/interpreter/interpreter4/Parser.pas
r106 r107 11 11 12 12 13 type 14 TTextPos = record 15 Index: Integer; 16 X: Integer; 17 Y: Integer; 18 PrevX: Integer; 19 PrevY: Integer; 20 end; 21 13 22 var 14 23 InnerText: string; 15 InnerTextPos: Integer;24 InnerTextPos: TTextPos; 16 25 17 26 implementation … … 23 32 var 24 33 InputText: string; 25 InputTextPos: Integer; 34 InputTextPos: TTextPos; 35 InputTextFileName: string; 26 36 LastTokenType: TTokenType; 27 37 … … 110 120 end; 111 121 122 function IntToStr(Value: Integer): string; 123 begin 124 Result := ''; 125 while Value > 0 do begin 126 Result := Chr(Ord('0') + Value mod 10) + Result; 127 Value := Value div 10; 128 end; 129 end; 130 112 131 procedure ShowError(Text: string); 113 132 begin 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)); 116 135 Halt; 117 136 end; … … 124 143 begin 125 144 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; 127 150 InputText := ''; 128 InnerTextPos := 1; 151 InnerTextPos.Index := 1; 152 InnerTextPos.PrevX := 1; 153 InnerTextPos.PrevY := 1; 129 154 InnerText := ''; 130 155 Inner := False; … … 147 172 function ReadChar: Char; 148 173 begin 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; 184 end; 185 186 procedure InputTextPosSetPrev; 187 begin 188 InputTextPos.X := InputTextPos.PrevX; 189 InputTextPos.Y := InputTextPos.PrevY; 190 InputTextPos.Index := InputTextPos.Index - 1; 152 191 end; 153 192 … … 164 203 N := N * 10; 165 204 I := I - 1; 166 end;167 end;168 169 function IntToStr(Value: Integer): string;170 begin171 Result := '';172 while Value > 0 do begin173 Result := Chr(Ord('0') + Value mod 10) + Result;174 Value := Value div 10;175 205 end; 176 206 end; … … 196 226 LastTokenType := ttChar; 197 227 end; 198 InputTextPos := InputTextPos - 1;228 InputTextPosSetPrev; 199 229 Break; 200 230 end else Result := Result + C; … … 230 260 LastTokenType := ttComment; 231 261 Continue; 232 end else InputTextPos := InputTextPos - 1;262 end else InputTextPosSetPrev; 233 263 end; 234 264 Break; 235 265 end else begin 236 InputTextPos := InputTextPos - 1;266 InputTextPosSetPrev; 237 267 Break; 238 268 end; … … 258 288 begin 259 289 Result := ReadNextInternal; 260 WriteLn('ReadNext: ' + Result);290 //WriteLn('ReadNext: ' + Result); 261 291 end; 262 292 … … 264 294 var 265 295 Next: string; 266 OldPos: Integer;296 OldPos: TTextPos; 267 297 begin 268 298 OldPos := InputTextPos; … … 297 327 function ParseVariable(out Variable: PVariable): Boolean; 298 328 var 299 OldPos: Integer;329 OldPos: TTextPos; 300 330 Next: string; 301 331 SelfVariable: PVariable; … … 341 371 Result := False; 342 372 InputTextPos := OldPos; 373 Break; 343 374 end; 344 375 until False; … … 357 388 function ParseConstant(out Constant: PConstant): Boolean; 358 389 var 359 OldPos: Integer;390 OldPos: TTextPos; 360 391 Next: string; 361 392 begin … … 383 414 function ParseOperator(out ExpOperator: TOperator): Boolean; 384 415 var 385 OldPos: Integer;416 OldPos: TTextPos; 386 417 OperatorName: string; 387 418 begin … … 400 431 function ParseValue(Value: PConstant): Boolean; 401 432 var 402 OldPos: Integer;433 OldPos: TTextPos; 403 434 Text: string; 404 435 begin … … 443 474 II: Integer; 444 475 FoundOperator: Boolean; 445 OldPos: Integer;476 OldPos: TTextPos; 446 477 //E: TExpression; 447 478 begin … … 598 629 function ParseExecution(Execution: PExecution): Boolean; 599 630 var 600 OldPos: Integer;631 OldPos: TTextPos; 601 632 Next: string; 602 633 Func: PFunction; … … 776 807 VarName: string; 777 808 VarType: PType; 778 OldPos: Integer;809 OldPos: TTextPos; 779 810 Value: string; 780 811 I: Integer; … … 831 862 ConstName: string; 832 863 ConstType: PType; 833 OldPos: Integer;864 OldPos: TTextPos; 834 865 Value: string; 835 866 begin … … 1018 1049 function ParseTypeSimple(TypeItem: PType): Boolean; 1019 1050 var 1020 OldPos: Integer;1051 OldPos: TTextPos; 1021 1052 Name: string; 1022 1053 T: PType; … … 1037 1068 function ParseTypeSimpleForward(TypeItem: PType): Boolean; 1038 1069 var 1039 OldPos: Integer;1070 OldPos: TTextPos; 1040 1071 Name: string; 1041 1072 begin … … 1207 1238 Name: string; 1208 1239 TypeName: string; 1209 OldPos: Integer;1240 OldPos: TTextPos; 1210 1241 NewType: TType; 1211 1242 begin … … 1237 1268 var 1238 1269 OldInputText: string; 1239 OldInputTextPos: Integer;1270 OldInputTextPos: TTextPos; 1240 1271 UnitFile: Text; 1241 1272 Directive: TDirective; -
branches/interpreter/interpreter4/interpreter.lpi
r106 r107 116 116 <Item4> 117 117 <Name Value="RunError(101)"/> 118 <Enabled Value="False"/> 118 119 </Item4> 119 120 <Item5> 120 121 <Name Value="Unknown"/> 122 <Enabled Value="False"/> 121 123 </Item5> 122 124 </Exceptions>
Note:
See TracChangeset
for help on using the changeset viewer.