Changeset 9 for branches/Void/UCompilator.pas
- Timestamp:
- Nov 9, 2009, 10:15:36 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Void/UCompilator.pas
r8 r9 10 10 type 11 11 TOnErrorEvent = procedure (Text: string; var Terminate: Boolean; Position: TPoint) of object; 12 13 { TCompilator } 12 14 13 15 TCompilator = class … … 58 60 procedure TCompilator.ProcessLine(Line: string); 59 61 var 60 Command: string; 62 CommandName: string; 63 Command: TProcedure; 61 64 Variable: TVariable; 62 65 VariableName: string; 63 66 begin 64 67 with Model, BeginEnd do begin 65 Command := Parse(Line); 66 if Command = 'Write' then 67 with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin 68 Name := 'WriteLn'; 69 Parameters.Add(Parse(Line)); 70 end else if Command = 'Define' then begin 71 VariableName := Parse(Line); 72 Variable := FindVariableByName(VariableName); 73 if Assigned(Variable) then DoError('Variable ' + VariableName + ' redefined') 74 else begin 75 Variable := TVariable.Create; 76 with Variable do begin 77 Name := VariableName; 78 VarType := 'string'; 68 CommandName := Parse(Line); 69 if CommandName = 'Define' then begin 70 VariableName := Parse(Line); 71 Variable := FindVariableByName(VariableName); 72 if Assigned(Variable) then DoError('Variable ' + VariableName + ' redefined') 73 else begin 74 Variable := TVariable.Create; 75 with Variable do begin 76 Name := VariableName; 77 VarType := 'string'; 78 end; 79 Variables.Add(Variable); 79 80 end; 80 Variables.Add(Variable); 81 end else if CommandName = 'Assign' then with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin 82 VariableName := Parse(Line); 83 Variable := FindVariableByName(VariableName); 84 if not Assigned(Variable) then DoError('Undefined variable ' + VariableName) 85 else begin 86 Name := 'Assignment'; 87 Parameters.Add(VariableName); 88 Parameters.Add(Parse(Line)); 89 end; 90 end else begin 91 Command := FindProcedureByName(CommandName); 92 if Assigned(Command) then begin 93 with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin 94 Name := CommandName; 95 96 end; 97 end else DoError('Unknown command ' + CommandName); 81 98 end; 82 end else if Command = 'Assign' then with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin83 VariableName := Parse(Line);84 Variable := FindVariableByName(VariableName);85 if not Assigned(Variable) then DoError('Undefined variable ' + VariableName)86 else begin87 Name := 'Assignment';88 Parameters.Add(VariableName);89 Parameters.Add(Parse(Line));90 end;91 end else if Command = 'Pause' then with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin92 Name := 'ReadLn';93 end else if Command = 'Exit' then with TCommand(Commands[Commands.Add(TCommand.Create)]) do begin94 Name := 'Exit';95 end else DoError('Unknown command ' + Command);96 97 99 end; 98 100 end;
Note:
See TracChangeset
for help on using the changeset viewer.