1. -- 
  2. -- Copyright (c) 2012 Kevin Wellwood 
  3. -- All rights reserved. 
  4. -- 
  5. -- This source code is distributed under the Modified BSD License. For terms and 
  6. -- conditions, see license.txt. 
  7. -- 
  8.  
  9. package Scripting.Expressions.Operators is 
  10.  
  11.     -- A Binary_Operator has two operands upon which it operates. Evaluating it 
  12.     -- produces a single resultant value. 
  13.     -- 
  14.     -- Relative order of operations (highest priority first) 
  15.     -- * / %           | Multiplication, division, modulo 
  16.     -- + -             | Addition, subtraction 
  17.     -- = != < <= > >=  | Comparators 
  18.     -- && ||           | Logical operators 
  19.     type Binary_Operator is abstract new Expression with private; 
  20.     type A_Binary_Operator is access all Binary_Operator'Class; 
  21.  
  22.     -- Creates a new Binary_Operator of a concrete type depending on 'token'. 
  23.     function Create_Binary_Operator( token : not null A_Token ) return A_Binary_Operator; 
  24.  
  25.     function Get_Precedence( this : not null access Binary_Operator'Class ) return Positive; 
  26.  
  27.     -- Sets the 'left' and 'right' operands of the operator. 
  28.     procedure Set_Operands( this        : not null access Binary_Operator'Class; 
  29.                             left, right : in out A_Expression ); 
  30.     pragma Precondition( left /= null ); 
  31.     pragma Precondition( right /= null ); 
  32.     pragma Postcondition( left = null ); 
  33.     pragma Postcondition( right = null ); 
  34.  
  35.     -- Returns True if the token type represents a binary operator. 
  36.     function Is_Binary( tokenType : Token_Type ) return Boolean; 
  37.  
  38.     ---------------------------------------------------------------------------- 
  39.  
  40.     -- A Unary_Operator has only one operand upon which it operates. Evaluating 
  41.     -- it produces a single resultant value. 
  42.     type Unary_Operator is abstract new Expression with private; 
  43.     type A_Unary_Operator is access all Unary_Operator'Class; 
  44.  
  45.     -- Creates a new Unary_Operator of a concrete type depending on 'token'. 
  46.     function Create_Unary_Operator( token : not null A_Token ) return A_Unary_Operator; 
  47.  
  48.     -- Sets the 'right' (and only) operand of the operator. 
  49.     procedure Set_Operand( this  : not null access Unary_Operator'Class; 
  50.                            right : in out A_Expression ); 
  51.     pragma Precondition( right /= null ); 
  52.     pragma Postcondition( right = null ); 
  53.  
  54.     -- Returns True if the token type represents a unary operator. 
  55.     function Is_Unary( tokenType : Token_Type ) return Boolean; 
  56.  
  57. private 
  58.  
  59.     type Binary_Operator is abstract new Expression with 
  60.         record 
  61.             precedence : Positive; 
  62.             left       : A_Expression; 
  63.             right      : A_Expression; 
  64.         end record; 
  65.  
  66.     procedure Construct( this       : access Binary_Operator; 
  67.                          loc        : Token_Location; 
  68.                          precedence : Positive ); 
  69.  
  70.     procedure Delete( this : in out Binary_Operator ); 
  71.  
  72.     ---------------------------------------------------------------------------- 
  73.  
  74.     type Unary_Operator is abstract new Expression with 
  75.         record 
  76.             right : A_Expression; 
  77.         end record; 
  78.  
  79.     procedure Delete( this : in out Unary_Operator ); 
  80.  
  81. end Scripting.Expressions.Operators;