Ignore:
Timestamp:
Jan 16, 2018, 2:44:19 PM (7 years ago)
Author:
chronos
Message:
  • Added: Support for multiple value types. String and Integer are supported for the start.
  • Added: "var" keyword for compile time definition of variable and its type.
  • Added: Increment function for integer values.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/easy compiler/USourceGenerator.pas

    r140 r141  
    2525  Instruction: TSourceInstruction;
    2626  I: Integer;
     27  Value: TSourceValue;
    2728
    2829function GenerateRef(Reference: TSourceReference): string;
     
    3031  Result := '';
    3132  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);
    3339  end else
    3440  if Reference is TSourceReferenceVariable then begin
     
    4349  with SourceCode do
    4450  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;
    4660  Output := Output + 'begin' + LineEnding;
    4761  with SourceCode do
     
    6377      end else
    6478      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;
    6684      end else
    6785      raise Exception.Create('Unsupported instruction name.');
Note: See TracChangeset for help on using the changeset viewer.