Changeset 105 for branches/interpreter/interpreter4/Parser.pas
- Timestamp:
- Feb 17, 2017, 11:19:22 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/interpreter/interpreter4/Parser.pas
r104 r105 286 286 begin 287 287 OldPos := InputTextPos; 288 Next := ReadNext; 289 if FunctionContext = nil then 290 Variable := MainProgram^.Variables.GetByName(Next) 291 else Variable := FunctionContext^.Variables.GetByName(Next); 292 if Variable <> nil then begin 293 Result := True; 294 end else begin 295 Result := False; 296 InputTextPos := OldPos; 297 end; 288 Variable := nil; 289 repeat 290 Next := ReadNext; 291 if Assigned(Variable) and (Variable^.DataType^.BaseType = btRecord) then begin 292 // if FunctionContext = nil then 293 // Variable := MainProgram^.Variables.GetByName(Next) 294 // else Variable := FunctionContext^.Variables.GetByName(Next); 295 end else begin 296 if FunctionContext = nil then 297 Variable := MainProgram^.Variables.GetByName(Next) 298 else begin 299 Variable := FunctionContext^.Variables.GetByName(Next); 300 end; 301 end; 302 if Variable <> nil then begin 303 Result := True; 304 end else begin 305 Result := False; 306 InputTextPos := OldPos; 307 end; 308 if CheckNext('.') then begin 309 Expect('.'); 310 Continue; 311 end else Break; 312 until False; 298 313 end; 299 314 … … 549 564 I := 0; 550 565 while I < Length(Func^.Parameters.Items) do begin 551 ParseGetValue(@Execution^.Parameters.Items[I]); 566 if ParseGetValue(@Execution^.Parameters.Items[I]) then begin 567 end else ShowError('Value exprected but found ' + ReadNext); 568 552 569 if I < (Length(Func^.Parameters.Items) - 1) then Expect(','); 553 570 I := I + 1; … … 711 728 OldPos: Integer; 712 729 Value: string; 730 I: Integer; 713 731 begin 714 732 if CheckNext('var') then begin … … 728 746 if ParseType(VarType, False) then begin 729 747 Variables^.Add(VariableCreate(VarName, VarType)); 748 // Create subvariables for structured record type variable 749 if VarType^.BaseType = btRecord then begin 750 SetLength(Variables^.GetLast^.RecordVariables.Items, 0); 751 I := 0; 752 while (I < Length(VarType^.Fields^.Items)) do begin 753 Variables^.GetLast^.RecordVariables^.Add( 754 VariableCreate(VarType^.Fields^.Items[I].Name, @VarType^.Fields^.Items[I])); 755 I := I + 1; 756 end; 757 end; 730 758 end else ShowError('Unknown variable type ' + ReadNext); 731 759 if CheckNext('=') then begin … … 802 830 Expect('function'); 803 831 FunctionContext := Func; 804 Func^.Name := ReadNext; 805 Func^.Parameters.TypeList := @MainProgram^.Types; 832 repeat 833 Func^.Name := ReadNext; 834 if CheckNext('.') then begin 835 Expect('.'); 836 Func^.ParentRecord := Func^.Types.GetByName(Func^.Name); 837 Continue; 838 end else Break; 839 until False; 840 Func^.Parameters.TypeList := @Func^.Types; 806 841 ParseParams(@Func^.Parameters); 807 842 Expect(':'); 808 843 ReturnType := ReadNext; 809 DataType := MainProgram.Types.GetByName(ReturnType);844 DataType := Func^.Types.GetByName(ReturnType); 810 845 if DataType <> nil then Func^.ReturnType := DataType 811 846 else ShowError('Unknown type ' + ReturnType); … … 826 861 Expect('procedure'); 827 862 FunctionContext := Func; 828 Func^.Name := ReadNext; 829 Func^.Parameters.TypeList := @MainProgram^.Types; 863 repeat 864 Func^.Name := ReadNext; 865 if CheckNext('.') then begin 866 Expect('.'); 867 Continue; 868 end else Break; 869 until False; 870 Func^.Parameters.TypeList := @Func^.Types; 830 871 ParseParams(@Func^.Parameters); 831 872 Expect(';'); … … 1126 1167 Directive: TDirective; 1127 1168 NewType: TType; 1169 NewFunc: TFunction; 1128 1170 begin 1129 1171 OldInputText := InputText; … … 1162 1204 1163 1205 Expect('implementation'); 1206 1207 repeat 1208 SetLength(NewFunc.Parameters.Items, 0); 1209 SetLength(NewFunc.Variables.Items, 0); 1210 NewFunc.Types.ParentList := @UnitItem^.Types; 1211 if ParseFunction(@NewFunc) then begin 1212 UnitItem.Functions.Add(NewFunc); 1213 end else 1214 if ParseProcedure(@NewFunc) then begin 1215 UnitItem.Functions.Add(NewFunc); 1216 end else Break; 1217 until False; 1164 1218 1165 1219 Expect('end'); … … 1269 1323 SetLength(NewFunc.Parameters.Items, 0); 1270 1324 SetLength(NewFunc.Variables.Items, 0); 1325 NewFunc.Types.ParentList := @ProgramCode^.Types; 1271 1326 if ParseFunction(@NewFunc) then begin 1272 1327 ProgramCode.Functions.Add(NewFunc);
Note:
See TracChangeset
for help on using the changeset viewer.