Changeset 141 for branches/easy compiler/USourceGenerator.pas
- Timestamp:
- Jan 16, 2018, 2:44:19 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.