Changeset 106 for branches/interpreter/interpreter4
- Timestamp:
- Jul 18, 2017, 12:07:31 AM (7 years ago)
- Location:
- branches/interpreter/interpreter4
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/interpreter/interpreter4
-
Property svn:ignore
set to
lib
interpreter.lps
-
Property svn:ignore
set to
-
branches/interpreter/interpreter4/Parser.pas
r105 r106 36 36 function ParseBeginEnd(BeginEnd: PBeginEnd): Boolean; forward; 37 37 function ParseGetValue(GetValue: PGetValue; NoExpression: Boolean = False): Boolean; forward; 38 function ParseAssignment(Assignment: PAssignment): Boolean; forward; 38 39 function ParseUses(UsesSection: PUses): Boolean; forward; 39 40 function ParseType(TypeItem: PType; AllowForward: Boolean): Boolean; forward; 40 41 function ParseTypeFunction(TypeItem: PType; WithName: Boolean = True): Boolean; forward; 41 42 function ParseTypeProcedure(TypeItem: PType; WithName: Boolean = True): Boolean; forward; 43 function ParseVariable(out Variable: PVariable): Boolean; forward; 44 function ParseExpression(Expression: PExpression): Boolean; forward; 42 45 43 46 … … 66 69 Result := (C = ';') or (C = '(') or (C = ')') or (C = ':') or (C = '=') or 67 70 (C = '+') or (C = '-') or (C = ';') or (C = '.') or (C = '{') or (C = '}') or 68 (C = ',') or (C = '^') or (C = '/') or (C = '[') or (C = ']') ;71 (C = ',') or (C = '^') or (C = '/') or (C = '[') or (C = ']') or (C = '@'); 69 72 end; 70 73 … … 173 176 end; 174 177 175 function ReadNext : string;178 function ReadNextInternal: string; 176 179 var 177 180 C: Char; … … 239 242 LastTokenType := ttNumber; 240 243 end else 244 if IsDigit(C) then begin 245 Result := Result + C; 246 LastTokenType := ttNumber; 247 end else 241 248 if C = '''' then begin 242 249 LastTokenType := ttString; … … 248 255 end; 249 256 257 function ReadNext: string; 258 begin 259 Result := ReadNextInternal; 260 WriteLn('ReadNext: ' + Result); 261 end; 262 250 263 function CheckNext(Text: string): Boolean; 251 264 var … … 254 267 begin 255 268 OldPos := InputTextPos; 256 Next := ReadNext ;269 Next := ReadNextInternal; 257 270 Result := Next = Text; 258 271 InputTextPos := OldPos; 272 WriteLn('Check: ' + Next); 259 273 end; 260 274 … … 263 277 Next: string; 264 278 begin 265 Next := ReadNext; 279 Next := ReadNextInternal; 280 WriteLn('Expect: ' + Next); 266 281 if Next <> Text then 267 282 ShowError('Expected ' + Text + ' but found ' + Next); … … 284 299 OldPos: Integer; 285 300 Next: string; 301 SelfVariable: PVariable; 302 IndexValue: TGetValue; 286 303 begin 287 304 OldPos := InputTextPos; … … 298 315 else begin 299 316 Variable := FunctionContext^.Variables.GetByName(Next); 317 if (Variable = nil) then begin 318 SelfVariable := FunctionContext^.Variables.GetByName('Self'); 319 if (SelfVariable <> nil) and (SelfVariable^.Value.ValueRecord <> nil) then begin 320 Variable := SelfVariable^.Value.ValueRecord^.GetByName(Next); 321 end; 322 end; 300 323 end; 301 324 end; 302 325 if Variable <> nil then begin 303 326 Result := True; 327 if CheckNext('[') then begin 328 if Variable^.DataType^.BaseType = btArray then begin 329 Expect('['); 330 if ParseGetValue(@IndexValue) then begin 331 //Variable := Variable^. 332 end else ShowError('Expected index value but found ' + ReadNext); 333 Expect(']'); 334 end else ShowError('Unexpected array index'); 335 end; 336 if CheckNext('.') then begin 337 Expect('.'); 338 Continue; 339 end else Break; 304 340 end else begin 305 341 Result := False; 306 342 InputTextPos := OldPos; 307 343 end; 308 if CheckNext('.') then begin309 Expect('.');310 Continue;311 end else Break;312 344 until False; 345 end; 346 347 function ParseVariablePointer(out Variable: PVariable): Boolean; 348 begin 349 Result := False; 350 if CheckNext('@') then begin 351 Expect('@'); 352 Result := True; 353 ParseVariable(Variable); 354 end; 313 355 end; 314 356 … … 402 444 FoundOperator: Boolean; 403 445 OldPos: Integer; 446 //E: TExpression; 404 447 begin 405 448 OldPos := InputTextPos; … … 430 473 Break; 431 474 end; 475 //WriteLn('Items count: ' + IntToStr(Length(Expression^.Items))); 432 476 until False; 433 477 if not FoundOperator then begin … … 442 486 I := 0; 443 487 while (I < Length(Expression^.Items) - 1) do begin 488 //E := TExpression(Expression^.Items[I]); 444 489 if (TExpression(Expression^.Items[I]).NodeType = ntOperator) and 445 490 not TExpression(Expression^.Items[I]).Associated and 446 491 (TExpression(Expression^.Items[I]).OperatorType = OperatorPrecedence[II]) then 447 492 begin 493 //WriteLn('Expression operator ' + OperatorString[OperatorPrecedence[II]]); 448 494 if Expression^.Items[I].OperatorType = opNot then begin 449 495 Expression^.Items[I].Associated := True; … … 474 520 I := I - 1; 475 521 end; 476 end else ShowError('Expression error ' + IntToStr(Length(Expression^.Items)));522 end else ShowError('Expression error. Items count: ' + IntToStr(Length(Expression^.Items))); 477 523 end; 478 524 end; … … 520 566 end else 521 567 if ParseValue(@Value) then begin 568 GetValue^.ReadType := rtValue; 569 GetValue^.Value := Value; 570 end else 571 if ParseVariablePointer(Variable) then begin 522 572 GetValue^.ReadType := rtValue; 523 573 GetValue^.Value := Value; … … 748 798 // Create subvariables for structured record type variable 749 799 if VarType^.BaseType = btRecord then begin 750 SetLength(Variables^.GetLast^. RecordVariables.Items, 0);800 SetLength(Variables^.GetLast^.Value.ValueRecord.Items, 0); 751 801 I := 0; 752 802 while (I < Length(VarType^.Fields^.Items)) do begin 753 Variables^.GetLast^. RecordVariables^.Add(803 Variables^.GetLast^.Value.ValueRecord^.Add( 754 804 VariableCreate(VarType^.Fields^.Items[I].Name, @VarType^.Fields^.Items[I])); 755 805 I := I + 1; … … 825 875 ReturnType: string; 826 876 DataType: PType; 877 I: Integer; 827 878 begin 828 879 if CheckNext('function') then begin … … 835 886 Expect('.'); 836 887 Func^.ParentRecord := Func^.Types.GetByName(Func^.Name); 888 Func^.Variables.Add(VariableCreate('Self', Func^.ParentRecord)); 889 Func^.Variables.GetLast^.Value.ValueRecord := GetMem(SizeOf(TVariables)); 890 FillChar(Func^.Variables.GetLast^.Value.ValueRecord^, SizeOf(TVariables), 0); 891 I := 0; 892 while I < Length(Func^.ParentRecord.Fields.Items) do begin 893 Func^.Variables.GetLast^.Value.ValueRecord^.Add( 894 VariableCreate(Func^.ParentRecord.Fields.Items[I].Name, 895 @(Func^.ParentRecord.Fields.Items[I]))); 896 I := I + 1; 897 end; 837 898 Continue; 838 899 end else Break; … … 856 917 857 918 function ParseProcedure(Func: PFunction): Boolean; 919 var 920 I: Integer; 858 921 begin 859 922 if CheckNext('procedure') then begin … … 865 928 if CheckNext('.') then begin 866 929 Expect('.'); 930 Func^.ParentRecord := Func^.Types.GetByName(Func^.Name); 931 Func^.Variables.Add(VariableCreate('Self', Func^.ParentRecord)); 932 Func^.Variables.GetLast^.Value.ValueRecord := GetMem(SizeOf(TVariables)); 933 FillChar(Func^.Variables.GetLast^.Value.ValueRecord^, SizeOf(TVariables), 0); 934 I := 0; 935 while I < Length(Func^.ParentRecord.Fields.Items) do begin 936 Func^.Variables.GetLast^.Value.ValueRecord^.Add( 937 VariableCreate(Func^.ParentRecord.Fields.Items[I].Name, 938 @(Func^.ParentRecord.Fields.Items[I]))); 939 I := I + 1; 940 end; 867 941 Continue; 868 942 end else Break; -
branches/interpreter/interpreter4/Source.pas
r105 r106 55 55 end; 56 56 57 TVariable = record58 Name: string;59 DataType: PType;60 Index: Integer;61 RecordVariables: PVariables;62 end;63 64 { TVariables }65 66 TVariables = record67 ParentList: PVariables;68 Items: array of TVariable;69 procedure Add(Variable: TVariable);70 function GetByName(Name: string): PVariable;71 function GetLast: PVariable;72 end;73 74 57 TConstant = record 75 58 Name: shortstring; … … 81 64 btShortString: (ValueString: ShortString); 82 65 btBoolean: (ValueBoolean: Boolean); 66 btRecord: (ValueRecord: PVariables); 67 btArray: (ValueArray: PVariables); 83 68 end; 84 69 … … 91 76 end; 92 77 PConstants = ^TConstants; 78 79 TVariable = record 80 Name: string; 81 DataType: PType; 82 Index: Integer; 83 Value: TConstant; 84 end; 85 86 { TVariables } 87 88 TVariables = record 89 ParentList: PVariables; 90 Items: array of TVariable; 91 procedure Add(Variable: TVariable); 92 function GetByName(Name: string): PVariable; 93 function GetLast: PVariable; 94 end; 93 95 94 96 TFunctionParameter = record -
branches/interpreter/interpreter4/interpreter.lpi
r104 r106 2 2 <CONFIG> 3 3 <ProjectOptions> 4 <Version Value=" 9"/>4 <Version Value="10"/> 5 5 <General> 6 6 <Flags> … … 104 104 </CompilerOptions> 105 105 <Debugging> 106 <Exceptions Count=" 3">106 <Exceptions Count="5"> 107 107 <Item1> 108 108 <Name Value="EAbort"/> … … 114 114 <Name Value="EFOpenError"/> 115 115 </Item3> 116 <Item4> 117 <Name Value="RunError(101)"/> 118 </Item4> 119 <Item5> 120 <Name Value="Unknown"/> 121 </Item5> 116 122 </Exceptions> 117 123 </Debugging>
Note:
See TracChangeset
for help on using the changeset viewer.