Changeset 141
- Timestamp:
- Jan 16, 2018, 2:44:19 PM (7 years ago)
- Location:
- branches/easy compiler
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/easy compiler/Steps.txt
r140 r141 15 15 - change from static functions to dynamic predefined 16 16 Add inputln function 17 Add integer type 18 - support for mutiple types -
branches/easy compiler/UCompiler.pas
r140 r141 9 9 10 10 type 11 TSourceTokenKind = (stNone, stString, stIdentifier, stEof );11 TSourceTokenKind = (stNone, stString, stIdentifier, stEof, stInteger); 12 12 TSourceToken = record 13 13 Text: string; … … 102 102 procedure TTokenizer.Tokenize(Text: string; Tokens: TSourceTokens); 103 103 type 104 TTokenizerState = (tsNone, tsIdentifier, tsString );104 TTokenizerState = (tsNone, tsIdentifier, tsString, tsInteger); 105 105 var 106 106 State: TTokenizerState; … … 114 114 while I < Length(Text) do begin 115 115 if State = tsNone then begin 116 if IsDigit(Text[I]) then begin 117 State := tsInteger; 118 Token := Text[I]; 119 end else 116 120 if IsAlpha(Text[I]) then begin 117 121 State := tsIdentifier; … … 133 137 if IsWhiteSpace(Text[I]) then begin 134 138 Tokens.AddToken(stIdentifier, Token); 139 State := tsNone; 140 Dec(I); 141 end else 142 raise Exception.Create('Unexpected character'); 143 end else 144 if State = tsInteger then begin 145 if IsDigit(Text[I]) then begin 146 Token := Token + Text[I]; 147 end else 148 if IsWhiteSpace(Text[I]) then begin 149 Tokens.AddToken(stInteger, Token); 135 150 State := tsNone; 136 151 Dec(I); … … 156 171 var 157 172 Token: TSourceToken; 173 Token2: TSourceToken; 158 174 Keyword: string; 159 175 Instruction: TSourceInstruction; … … 161 177 Funct: TSourceFunction; 162 178 Param: TSourceFunctionParameter; 179 Variable: TSourceVariable; 180 ValueType: TSourceType; 163 181 164 182 function ParseReference: TSourceReference; … … 168 186 NewReference := TSourceReferenceConstant.Create; 169 187 TSourceReferenceConstant(NewReference).Constant := 170 Code.Constants.AddNew (Token.Text);188 Code.Constants.AddNewString(Token.Text); 171 189 end else 172 190 if Token.Kind = stIdentifier then begin … … 176 194 if TSourceReferenceVariable(NewReference).Variable = nil then 177 195 raise Exception.Create('Variable not found: ' + Token.Text); 178 end else raise Exception.Create('Unexpected parameter'); 196 end else 197 if Token.Kind = stInteger then begin 198 NewReference := TSourceReferenceConstant.Create; 199 TSourceReferenceConstant(NewReference).Constant := 200 Code.Constants.AddNewInteger(StrToInt(Token.Text)); 201 end else 202 raise Exception.Create('Unexpected parameter'); 179 203 Result := NewReference; 180 204 end; … … 187 211 TSourceReferenceVariable(NewReference).Variable := 188 212 Code.Variables.Search(Token.Text); 189 if TSourceReferenceVariable(NewReference).Variable = nil then begin 190 if Initialize then 191 TSourceReferenceVariable(NewReference).Variable := Code.Variables.AddNew(Token.Text) 192 else raise Exception.Create('Variable not found: ' + Token.Text); 193 end; 213 if TSourceReferenceVariable(NewReference).Variable = nil then 214 raise Exception.Create('Variable not found: ' + Token.Text); 194 215 195 216 end else raise Exception.Create('Unexpected parameter'); … … 203 224 if Token.Kind = stIdentifier then begin 204 225 Keyword := LowerCase(Token.Text); 205 Funct := Code.Functions.Search(Keyword); 206 if Assigned(Funct) then begin 207 Instruction := TSourceInstructionFunction.Create; 208 TSourceInstructionFunction(Instruction).Name := Keyword; 209 for Param in Funct.Parameters do 210 if Param.Kind = pkString then begin 211 TSourceInstructionFunction(Instruction).AddParameter(ParseReference) 212 end else 213 if Param.Kind = pkVariable then begin 214 TSourceInstructionFunction(Instruction).AddParameter(ParseReferenceVariable(True)); 215 end else 216 raise Exception.Create('Unsupported parameter type.'); 217 Code.Instructions.Add(Instruction); 218 end else raise Exception.Create('Unsupported keyword: ' + Token.Text); 226 if Keyword = 'var' then begin 227 Token := Tokenizer.GetNext; 228 Token2 := Tokenizer.GetNext; 229 if Token2.Kind <> stIdentifier then 230 raise Exception.Create('Expected type parameter'); 231 Variable := Code.Variables.Search(Token.Text); 232 if not Assigned(Variable) then begin 233 ValueType := Code.Types.Search(Token2.Text); 234 if not Assigned(ValueType) then 235 raise Exception.Create('Unsupported type: ' + Token2.Text); 236 Variable := Code.Variables.AddNew(Token.Text, 237 ValueType); 238 end else raise Exception.Create('Variable redefined'); 239 end else begin 240 Funct := Code.Functions.Search(Keyword); 241 if Assigned(Funct) then begin 242 Instruction := TSourceInstructionFunction.Create; 243 TSourceInstructionFunction(Instruction).Name := Keyword; 244 for Param in Funct.Parameters do 245 if Param.Kind = pkString then begin 246 TSourceInstructionFunction(Instruction).AddParameter(ParseReference) 247 end else 248 if Param.Kind = pkVariable then begin 249 TSourceInstructionFunction(Instruction).AddParameter(ParseReferenceVariable(True)); 250 end else 251 raise Exception.Create('Unsupported parameter type.'); 252 Code.Instructions.Add(Instruction); 253 end else raise Exception.Create('Unsupported keyword: ' + Token.Text); 254 end; 219 255 end else raise Exception.Create('Unsupported token kind.'); 220 256 end; -
branches/easy compiler/UFormMain.lfm
r140 r141 42 42 Top = 304 43 43 Width = 200 44 OnKeyPress = Edit1KeyPress 44 45 TabOrder = 3 45 46 end -
branches/easy compiler/UFormMain.pas
r140 r141 26 26 procedure ButtonBuildClick(Sender: TObject); 27 27 procedure ButtonSendClick(Sender: TObject); 28 procedure Edit1KeyPress(Sender: TObject; var Key: char); 28 29 procedure FormCreate(Sender: TObject); 29 30 procedure FormDestroy(Sender: TObject); … … 51 52 begin 52 53 with MemoSource.Lines do begin 54 Add('PrintLn ''Super Calculator'''); 55 Add('var Value1 Integer'); 56 Add('var Value2 Integer'); 57 Add('var Result Integer'); 58 Add('Print ''Enter value 1: '''); 59 Add('Assign Value1 0'); 60 Add('InputLn Value1'); 61 Add('Print ''Enter value 2: '''); 62 Add('Assign Value2 0'); 63 Add('InputLn Value2'); 64 65 Add('Assign Result Value1'); 66 Add('Increment Result Value2'); 67 Add('Print ''Sum of two values is: '''); 68 Add('PrintLn Result'); 69 end; 70 { with MemoSource.Lines do begin 53 71 Add('PrintLn ''Hello World!'''); 54 72 Add('print ''Hello'' PRINT '' World!'''); 55 73 Add('PrintLn ''Live your life.'''); 74 Add('var Text1 String'); 56 75 Add('Assign Text1 ''Live your life.'''); 76 Add('var Text2 String'); 57 77 Add('Assign Text2 ''Live your life.'''); 58 78 Add('PrintLn Text1'); 59 79 Add('PrintLn Text2'); 80 81 Add('var Value1 Integer'); 82 Add('Assign Value1 123'); 83 Add('Increment Value1 2'); 84 Add('PrintLn Value1'); 85 86 Add('var Text3 String'); 87 Add('Assign Text3 '''''); 88 Add('Print ''Enter your name:'''); 60 89 Add('InputLn Text3'); 61 90 Add('PrintLn Text3'); 62 91 end; 92 93 with MemoSource.Lines do begin 94 Add('Assign AnimalName[0] ''an elephant'''); 95 Add('Assign AnimalProperty[0] ''It is big and slow'''); 96 Add('Assign AnimalName[1] ''a cat'''); 97 Add('Assign AnimalProperty[1] ''It meows and purrs'''); 98 Add('Print ''An animal guessing game.'''); 99 Add('Assign AnimalCount 2'); 100 Add('Repeat'); 101 Add('BeginBlock'); 102 Add('PrintLn ''Think an animal.'''); 103 Add('Assign I 0'); 104 Add('Repeat'); 105 Add('BeginBlock'); 106 Add('Print AnimalProperty[I]'); 107 Add('Print ''? (y/n)'''); 108 Add('InputLn Answer'); 109 Add('IfEqual Answer ''y'''); 110 Add('BeginBlock'); 111 Add('PrintLn ''That''s clear. It is '''); 112 Add('PrintLn AnimalName[I]'); 113 Add('Break'); 114 Add('EndBlock'); 115 Add('Increment I'); 116 Add('IfHigherOrEqual I AnimalCount'); 117 Add('Break'); 118 Add('EndBlock'); 119 Add('PrintLn ''I am lost. What is the animal?'''); 120 Add('InputLn AnimalName[I]'); 121 Add('PrintLn ''Describe the animal for me. What is it like?'''); 122 Add('InputLn AnimalProperty[I]'); 123 Add('PrintLn ''Thank you. I will remember that animal.'''); 124 Add('Increment AnimalCount 1'); 125 Add('PrintLn '''''); 126 Add('EndBlock'); 127 end; 128 } 63 129 end; 64 130 … … 97 163 end; 98 164 165 procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: char); 166 begin 167 if Key = #13 then ButtonSend.Click; 168 end; 169 99 170 procedure TForm1.FormCreate(Sender: TObject); 100 171 begin … … 115 186 begin 116 187 while InputBuffer.Count = 0 do begin 188 if Application.Terminated then Break; 117 189 Sleep(50); 118 190 Application.ProcessMessages; 119 191 end; 120 Result := InputBuffer[0]; 121 InputBuffer.Delete(0); 192 if InputBuffer.Count > 0 then begin 193 Result := InputBuffer[0]; 194 InputBuffer.Delete(0); 195 end else Result := ''; 122 196 end; 123 197 -
branches/easy compiler/USourceCode.pas
r140 r141 18 18 end; 19 19 20 { TSourceValue } 21 22 TSourceValue = class 23 procedure Assign(Source: TSourceValue); virtual; 24 end; 25 26 TSourceValueClass = class of TSourceValue; 27 28 { TSourceType } 29 30 TSourceType = class 31 Name: string; 32 ValueClass: TSourceValueClass; 33 end; 34 35 { TSourceTypes } 36 37 TSourceTypes = class(TObjectList) 38 function AddNew(Name: string; ClassType: TSourceValueClass): TSourceType; 39 function Search(Name: string): TSourceType; 40 end; 41 42 { TSourceVariable } 43 20 44 TSourceVariable = class 21 45 Name: string; 46 ValueType: TSourceType; 22 47 end; 23 48 … … 25 50 26 51 TSourceVariables = class(TObjectList) 27 function AddNew(Name: string = ''): TSourceVariable;52 function AddNew(Name: string; ValueType: TSourceType): TSourceVariable; 28 53 function Search(Name: string): TSourceVariable; 29 54 end; … … 33 58 end; 34 59 60 { TSourceValueString } 61 62 TSourceValueString = class(TSourceValue) 63 Value: string; 64 procedure Assign(Source: TSourceValue); override; 65 end; 66 67 { TSourceValueInteger } 68 69 TSourceValueInteger = class(TSourceValue) 70 Value: Integer; 71 procedure Assign(Source: TSourceValue); override; 72 end; 73 35 74 TSourceConstant = class 36 75 Name: string; 37 Value: string;38 end; 39 40 TSourceParameterKind = (pkString, pkVariable );76 Value: TSourceValue; 77 end; 78 79 TSourceParameterKind = (pkString, pkVariable, pkType); 41 80 42 81 TSourceFunctionParameter = class … … 68 107 69 108 TSourceConstants = class(TObjectList) 70 function AddNew(Value: string; Name: string = ''): TSourceConstant; 109 function AddNewString(Value: string; Name: string = ''): TSourceConstant; 110 function AddNewInteger(Value: Integer; Name: string = ''): TSourceConstant; 111 function Search(Name: string): TSourceConstant; 71 112 end; 72 113 … … 89 130 procedure InitFunctions; 90 131 public 132 Types: TSourceTypes; 91 133 Variables: TSourceVariables; 92 134 Constants: TSourceConstants; … … 100 142 implementation 101 143 102 { TSource Functions }103 104 function TSource Functions.AddNew(Name: string): TSourceFunction;105 begin 106 Result := TSource Function.Create;144 { TSourceTypes } 145 146 function TSourceTypes.AddNew(Name: string; ClassType: TSourceValueClass): TSourceType; 147 begin 148 Result := TSourceType.Create; 107 149 Result.Name := Name; 108 Add(Result); 109 end; 110 111 function TSourceFunctions.Search(Name: string): TSourceFunction; 112 var 113 Item: TSourceFunction; 150 Result.ValueClass := ClassType; 151 Add(Result); 152 end; 153 154 function TSourceTypes.Search(Name: string): TSourceType; 155 var 156 Item: TSourceType; 114 157 begin 115 158 Result := nil; … … 121 164 end; 122 165 166 { TSourceValue } 167 168 procedure TSourceValue.Assign(Source: TSourceValue); 169 begin 170 raise Exception.Create('Value assign not implemented'); 171 end; 172 173 { TSourceValueInteger } 174 175 procedure TSourceValueInteger.Assign(Source: TSourceValue); 176 begin 177 if Source is TSourceValueInteger then 178 Value := TSourceValueInteger(Source).Value 179 else raise Exception.Create('Type for assignment not matches'); 180 end; 181 182 { TSourceValueString } 183 184 procedure TSourceValueString.Assign(Source: TSourceValue); 185 begin 186 if Source is TSourceValueString then 187 Value := TSourceValueString(Source).Value 188 else raise Exception.Create('Type for assignment not matches'); 189 end; 190 191 { TSourceFunctions } 192 193 function TSourceFunctions.AddNew(Name: string): TSourceFunction; 194 begin 195 Result := TSourceFunction.Create; 196 Result.Name := Name; 197 Add(Result); 198 end; 199 200 function TSourceFunctions.Search(Name: string): TSourceFunction; 201 var 202 Item: TSourceFunction; 203 begin 204 Result := nil; 205 for Item in Self do 206 if Item.Name = Name then begin 207 Result := Item; 208 Break; 209 end; 210 end; 211 123 212 { TSourceFunction } 124 213 … … 147 236 { TSourceVariables } 148 237 149 function TSourceVariables.AddNew(Name: string ): TSourceVariable;238 function TSourceVariables.AddNew(Name: string;ValueType: TSourceType): TSourceVariable; 150 239 begin 151 240 Result := TSourceVariable.Create; 152 241 Result.Name := Name; 242 Result.ValueType := ValueType; 153 243 Add(Result); 154 244 end; … … 156 246 function TSourceVariables.Search(Name: string): TSourceVariable; 157 247 var 158 Variable: TSourceVariable;248 Item: TSourceVariable; 159 249 begin 160 250 Result := nil; 161 for Variablein Self do162 if Variable.Name = Name then begin163 Result := Variable;251 for Item in Self do 252 if Item.Name = Name then begin 253 Result := Item; 164 254 Break; 165 255 end; … … 168 258 { TSourceConstants } 169 259 170 function TSourceConstants.AddNew(Value: string; Name: string): TSourceConstant; 260 function TSourceConstants.AddNewString(Value: string; Name: string 261 ): TSourceConstant; 171 262 begin 172 263 Result := TSourceConstant.Create; 173 Result.Value := Value; 264 Result.Value := TSourceValueString.Create; 265 TSourceValueString(Result.Value).Value := Value; 174 266 Result.Name := ''; 175 267 Add(Result); 268 end; 269 270 function TSourceConstants.AddNewInteger(Value: Integer; Name: string 271 ): TSourceConstant; 272 begin 273 Result := TSourceConstant.Create; 274 Result.Value := TSourceValueInteger.Create; 275 TSourceValueInteger(Result.Value).Value := Value; 276 Result.Name := ''; 277 Add(Result); 278 end; 279 280 function TSourceConstants.Search(Name: string): TSourceConstant; 281 var 282 Item: TSourceConstant; 283 begin 284 Result := nil; 285 for Item in Self do 286 if Item.Name = Name then begin 287 Result := Item; 288 Break; 289 end; 176 290 end; 177 291 … … 191 305 begin 192 306 Functions.Clear; 307 308 // Init types 309 Types.AddNew('Integer', TSourceValueInteger); 310 Types.AddNew('String', TSourceValueString); 311 312 // Init functions 193 313 Funct := Functions.AddNew('print'); 194 314 Funct.AddParameter('Text', pkString); 315 195 316 Funct := Functions.AddNew('println'); 196 317 Funct.AddParameter('Text', pkString); 318 319 Funct := Functions.AddNew('var'); 320 Funct.AddParameter('Variable', pkVariable); 321 Funct.AddParameter('Type', pkType); 322 197 323 Funct := Functions.AddNew('assign'); 198 324 Funct.AddParameter('Destination', pkVariable); 199 325 Funct.AddParameter('Source', pkString); 326 200 327 Funct := Functions.AddNew('inputln'); 201 328 Funct.AddParameter('Text', pkVariable); 329 330 Funct := Functions.AddNew('increment'); 331 Funct.AddParameter('Variable', pkVariable); 332 Funct.AddParameter('Addition', pkString); 202 333 end; 203 334 204 335 constructor TSourceCode.Create; 205 336 begin 337 Types := TSourceTypes.Create; 206 338 Variables := TSourceVariables.Create; 207 339 Constants := TSourceConstants.Create; 340 Functions := TSourceFunctions.Create; 208 341 Instructions := TSourceInstructions.Create; 209 Functions := TSourceFunctions.Create;210 342 InitFunctions; 211 343 end; … … 213 345 destructor TSourceCode.Destroy; 214 346 begin 347 Instructions.Free; 215 348 Functions.Free; 216 349 Variables.Free; 217 350 Constants.Free; 218 Instructions.Free;351 Types.Free; 219 352 inherited Destroy; 220 353 end; -
branches/easy compiler/USourceExecutor.pas
r140 r141 6 6 7 7 uses 8 Classes, SysUtils, USourceCode ;8 Classes, SysUtils, USourceCode, Contnrs; 9 9 10 10 type 11 11 TOutputEvent = procedure (Text: string) of object; 12 12 TInputEvent = function: string of object; 13 14 TExecutorVariable = class 15 Variable: TSourceVariable; 16 Value: TSourceValue; 17 end; 18 19 TExecutorVariables = class(TObjectList) 20 function Search(Variable: TSourceVariable): TExecutorVariable; 21 end; 13 22 14 23 { TSourceExecutor } … … 18 27 FOnInput: TInputEvent; 19 28 FOnOutput: TOutputEvent; 20 Variables: T StringList;29 Variables: TExecutorVariables; 21 30 public 22 31 constructor Create; … … 30 39 implementation 31 40 41 42 { TExecutorVariables } 43 44 function TExecutorVariables.Search(Variable: TSourceVariable): TExecutorVariable; 45 var 46 Item: TExecutorVariable; 47 begin 48 Result := nil; 49 for Item in Self do 50 if Item.Variable = Variable then begin 51 Result := Item; 52 Break; 53 end; 54 end; 55 32 56 { TSourceExecutor } 33 57 34 58 constructor TSourceExecutor.Create; 35 59 begin 36 Variables := T StringList.Create;60 Variables := TExecutorVariables.Create; 37 61 end; 38 62 … … 48 72 Instruction: TSourceInstruction; 49 73 Variable: TSourceVariable; 74 Value: TSourceValue; 75 ExecutorVar: TExecutorVariable; 50 76 51 function Read StringReference(Reference: TSourceReference): string;77 function ReadValueReference(Reference: TSourceReference): TSourceValue; 52 78 begin 53 Result := '';79 Result := nil; 54 80 if Reference is TSourceReferenceConstant then begin 55 81 Result := TSourceReferenceConstant(Reference).Constant.Value; 56 82 end else 57 83 if Reference is TSourceReferenceVariable then begin 58 Result := Variables. Values[TSourceReferenceVariable(Reference).Variable.Name];84 Result := Variables.Search(TSourceReferenceVariable(Reference).Variable).Value; 59 85 end else raise Exception.Create('Unsupported reference'); 60 86 end; … … 75 101 with TSourceInstructionFunction(Instruction) do begin 76 102 if Name = 'print' then begin 77 if Assigned(FOnOutput) then FOnOutput(ReadStringReference(Parameters[0])); 103 if Assigned(FOnOutput) then begin 104 Value := ReadValueReference(Parameters[0]); 105 if Value is TSourceValueString then 106 FOnOutput(TSourceValueString(Value).Value) 107 else if Value is TSourceValueInteger then 108 FOnOutput(IntToStr(TSourceValueInteger(Value).Value)) 109 else raise Exception.Create('Unsupported value type'); 110 end; 78 111 end else 79 112 if Name = 'println' then begin 80 if Assigned(FOnOutput) then FOnOutput(ReadStringReference(Parameters[0]) + 81 LineEnding); 113 if Assigned(FOnOutput) then begin 114 Value := ReadValueReference(Parameters[0]); 115 if Value is TSourceValueString then 116 FOnOutput(TSourceValueString(Value).Value + LineEnding) 117 else if Value is TSourceValueInteger then 118 FOnOutput(IntToStr(TSourceValueInteger(Value).Value) + LineEnding) 119 else raise Exception.Create('Unsupported value type'); 120 end; 82 121 end else 83 122 if Name = 'inputln' then begin 84 123 if Assigned(FOnInput) then begin 85 124 Variable := ReadVarReference(Parameters[0]); 86 Variables.Values[Variable.Name] := FOnInput; 125 ExecutorVar := Variables.Search(Variable); 126 if ExecutorVar.Value is TSourceValueString then begin 127 TSourceValueString(ExecutorVar.Value).Value := FOnInput; 128 FOnOutput(TSourceValueString(ExecutorVar.Value).Value + LineEnding); 129 end else 130 if ExecutorVar.Value is TSourceValueInteger then begin 131 TSourceValueInteger(ExecutorVar.Value).Value := StrToInt(FOnInput); 132 FOnOutput(IntToStr(TSourceValueInteger(ExecutorVar.Value).Value) + LineEnding); 133 end else 134 raise Exception.Create('Unsupported value type'); 87 135 end; 88 136 end else 89 137 if Name = 'assign' then begin 90 138 Variable := ReadVarReference(Parameters[0]); 91 Variables.Values[Variable.Name] := ReadStringReference(Parameters[1]); 92 end else raise Exception.Create('Unsupported function: ' + TSourceInstructionFunction(Instruction).Name); 139 Value := ReadValueReference(Parameters[1]); 140 ExecutorVar := Variables.Search(Variable); 141 if not Assigned(ExecutorVar) then begin 142 ExecutorVar := TExecutorVariable.Create; 143 ExecutorVar.Variable := Variable; 144 Variables.Add(ExecutorVar); 145 ExecutorVar.Value := Variable.ValueType.ValueClass.Create; 146 end; 147 ExecutorVar.Value.Assign(Value); 148 end else 149 if Name = 'increment' then begin 150 Variable := ReadVarReference(Parameters[0]); 151 Value := ReadValueReference(Parameters[1]); 152 ExecutorVar := Variables.Search(Variable); 153 if not Assigned(ExecutorVar) then raise Exception.Create('Variable not found'); 154 if (ExecutorVar.Value is TSourceValueInteger) and (Value is TSourceValueInteger) then 155 Inc(TSourceValueInteger(ExecutorVar.Value).Value, TSourceValueInteger(Value).Value) 156 else raise Exception.Create('Wrong type for increment'); 157 end else 158 raise Exception.Create('Unsupported function: ' + TSourceInstructionFunction(Instruction).Name); 93 159 end else raise Exception.Create('Unsupported instruction'); 94 160 Inc(IP); -
branches/easy compiler/USourceGenerator.pas
r140 r141 25 25 Instruction: TSourceInstruction; 26 26 I: Integer; 27 Value: TSourceValue; 27 28 28 29 function GenerateRef(Reference: TSourceReference): string; … … 30 31 Result := ''; 31 32 if Reference is TSourceReferenceConstant then begin 32 Result := Result + '''' + TSourceReferenceConstant(Reference).Constant.Value + ''''; 33 Value := TSourceReferenceConstant(Reference).Constant.Value; 34 if Value is TSourceValueString then 35 Result := Result + '''' + TSourceValueString(Value).Value + '''' 36 else 37 if Value is TSourceValueInteger then 38 Result := Result + IntToStr(TSourceValueInteger(Value).Value); 33 39 end else 34 40 if Reference is TSourceReferenceVariable then begin … … 43 49 with SourceCode do 44 50 for I := 0 to Variables.Count - 1 do 45 Output := Output + ' ' + TSourceVariable(Variables[I]).Name + ': string;' + LineEnding; 51 with TSourceVariable(Variables[I]) do begin 52 Output := Output + ' ' + Name + ': '; 53 if ValueType.Name = 'String' then 54 Output := Output + 'string' 55 else if ValueType.Name = 'Integer' then 56 Output := Output + 'Integer' 57 else raise Exception.Create('Unsupported type'); 58 Output := Output + ';' + LineEnding; 59 end; 46 60 Output := Output + 'begin' + LineEnding; 47 61 with SourceCode do … … 63 77 end else 64 78 if Name = 'inputln' then begin 65 Output := Output + ' ' + GenerateRef(Parameters[0]) + ' := ReadLn;' + LineEnding; 79 Output := Output + ' ReadLn(' + GenerateRef(Parameters[0]) + ');' + LineEnding; 80 end else 81 if Name = 'increment' then begin 82 Output := Output + ' Inc(' + GenerateRef(Parameters[0]) + ', ' + 83 GenerateRef(Parameters[1]) + ');' + LineEnding; 66 84 end else 67 85 raise Exception.Create('Unsupported instruction name.');
Note:
See TracChangeset
for help on using the changeset viewer.