1. with Objects;                           use Objects; 
  2. with Symbol_Resolvers;                  use Symbol_Resolvers; 
  3. with Tokens;                            use Tokens; 
  4. with Values;                            use Values; 
  5.  
  6. private with Ada.Unchecked_Deallocation; 
  7.  
  8. package Expressions is 
  9.  
  10.     -- An Expression represents a mathematical or logical expression tree that 
  11.     -- can be evaluated to produce a value. It is composed of operators and 
  12.     -- operands. The three base data types used in expressions are numeric, 
  13.     -- string, and boolean, which are represented with the Values hierarchy. 
  14.     type Expression is abstract new Limited_Object with private; 
  15.     type A_Expression is access all Expression'Class; 
  16.  
  17.     -- Deletes the Expression. 
  18.     procedure Delete( this : in out A_Expression ); 
  19.  
  20. private 
  21.  
  22.     type Eval_Context is tagged 
  23.         record 
  24.             resolver : A_Symbol_Resolver; 
  25.         end record; 
  26.     type A_Eval_Context is access all Eval_Context'Class; 
  27.  
  28.     -- Creates a new Eval_Context using 'resolver' to resolve symbol names. 
  29.     function Create_Eval_Context( resolver : A_Symbol_Resolver ) return A_Eval_Context; 
  30.     pragma Postcondition( Create_Eval_Context'Result /= null ); 
  31.  
  32.     -- Resolves symbol name 'symbol', returning the result. null will be 
  33.     -- returned if the symbol can't be resolved. 
  34.     function Resolve( this : access Eval_Context; symbol : String ) return A_Value; 
  35.  
  36.     -- Deletes the Eval_Context object. 
  37.     procedure Delete is new Ada.Unchecked_Deallocation( Eval_Context'Class, A_Eval_Context ); 
  38.  
  39.     ---------------------------------------------------------------------------- 
  40.  
  41.     type Expression is abstract new Limited_Object with 
  42.         record 
  43.             loc : Token_Location; 
  44.         end record; 
  45.  
  46.     procedure Construct( this : access Expression; loc : Token_Location ); 
  47.  
  48.     -- Evaluates the expression and it's subtree(s). Returns null if the 
  49.     -- expression can't be evaluated due to mismatched types or unresolved 
  50.     -- symbols. 
  51.     -- 
  52.     -- This function must be overridden. It is not declared abstract to avoid 
  53.     -- declaring it publicly and exposing the Eval_Context class. The default 
  54.     -- implementation raises Constraint_Error. 
  55.     function Evaluate( this    : access Expression; 
  56.                        context : not null A_Eval_Context ) return A_Value; 
  57.  
  58. end Expressions;