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/UGeneratorPhp.pas

    r221 r222  
    3030    procedure GenerateExpressionOperation(Block: TBlock; Expression: TExpressionOperation);
    3131    procedure GenerateExpressionOperand(Block: TBlock; Expression: TExpressionOperand);
     32    procedure GenerateExpressionBrackets(Block: TBlock; Expression: TExpressionBrackets);
    3233    procedure GenerateBreak(Block: TBlock; BreakCmd: TBreak);
    3334    procedure GenerateReturn(Block: TBlock; Return: TReturn);
     
    3536    procedure GenerateValue(Value: TValue);
    3637  public
    37     Prog: TProgram;
    3838    procedure Generate; override;
    39   end;
     39    constructor Create; override;
     40  end;
     41
    4042
    4143implementation
     44
     45const
     46  ExpressionOperatorTextPhp: array[TExpressionOperator] of string = ('', '+',
     47    '-', '*', '/', '/', '%', 'and', 'xor', 'or', '<<',
     48    '>>', '==', '!=', '<', '>', '<=','>=', '!');
    4249
    4350{ TGeneratorPhp }
     
    142149  if Expression is TExpressionOperand then
    143150    GenerateExpressionOperand(Block, TExpressionOperand(Expression))
     151  else
     152  if Expression is TExpressionBrackets then
     153    GenerateExpressionBrackets(Block, TExpressionBrackets(Expression))
    144154  else raise Exception.Create('Unknown expression class.');
    145155end;
     
    156166        else AddText(' + ');
    157167      end
    158       else if Expression.Operation = eoSub then AddText(' - ')
    159       else if Expression.Operation = eoEqual then AddText(' == ')
    160       else if Expression.Operation = eoNotEqual then AddText(' != ');
     168      else AddText(' ' + ExpressionOperatorTextPhp[Expression.Operation] + ' ');
    161169    end;
    162170    GenerateExpression(Block, TExpression(Expression.Items[I]));
     
    174182    else raise Exception.Create('Unsupported exception operand type.');
    175183  end;
     184end;
     185
     186procedure TGeneratorPhp.GenerateExpressionBrackets(Block: TBlock;
     187  Expression: TExpressionBrackets);
     188begin
     189  AddText('(');
     190  GenerateExpression(Block, Expression.Expression);
     191  AddText(')');
    176192end;
    177193
     
    290306end;
    291307
     308constructor TGeneratorPhp.Create;
     309begin
     310  inherited;
     311  Name := 'PHP';
     312  FileExt := '.php';
     313end;
     314
    292315end.
    293316
Note: See TracChangeset for help on using the changeset viewer.