Ignore:
Timestamp:
Nov 25, 2020, 12:18:45 AM (4 years ago)
Author:
chronos
Message:
  • Added: Support for more expression operators.
  • Added: Support for brackets in expressions.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/interpreter2/Generators/UGeneratorPascal.pas

    r221 r222  
    3131    procedure GenerateExpressionOperation(Block: TBlock; Expression: TExpressionOperation);
    3232    procedure GenerateExpressionOperand(Block: TBlock; Expression: TExpressionOperand);
     33    procedure GenerateExpressionBrackets(Block: TBlock; Expression: TExpressionBrackets);
    3334    procedure GenerateBreak(Block: TBlock; BreakCmd: TBreak);
    3435    procedure GenerateContinue(Block: TBlock; ContinueCmd: TContinue);
    3536    procedure GenerateValue(Value: TValue);
    3637  public
    37     Prog: TProgram;
    3838    procedure Generate; override;
     39    constructor Create; override;
    3940  end;
    4041
     
    134135  if Expression is TExpressionOperand then
    135136    GenerateExpressionOperand(Block, TExpressionOperand(Expression))
     137  else
     138  if Expression is TExpressionBrackets then
     139    GenerateExpressionBrackets(Block, TExpressionBrackets(Expression))
    136140  else raise Exception.Create('Unknown expression class.');
    137141end;
     
    145149    if I > 0 then begin
    146150      AddText(' ');
    147       if Expression.Operation = eoAdd then AddText('+')
    148       else if Expression.Operation = eoSub then AddText('-')
    149       else if Expression.Operation = eoEqual then AddText('=')
    150       else if Expression.Operation = eoNotEqual then AddText('<>');
     151      AddText(ExpressionOperatorText[Expression.Operation]);
    151152      AddText(' ');
    152153    end;
     
    165166    else raise Exception.Create('Unsupported exception operand type.');
    166167  end;
     168end;
     169
     170procedure TGeneratorPascal.GenerateExpressionBrackets(Block: TBlock;
     171  Expression: TExpressionBrackets);
     172begin
     173  AddText('(');
     174  GenerateExpression(Block, Expression.Expression);
     175  AddText(')');
    167176end;
    168177
     
    313322end;
    314323
     324constructor TGeneratorPascal.Create;
     325begin
     326  inherited;
     327  Name := 'Pascal';
     328  FileExt := '.pas';
     329end;
     330
    315331end.
    316332
Note: See TracChangeset for help on using the changeset viewer.