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. with Ada.Containers;                    use Ada.Containers; 
  10. with Ada.Containers.Doubly_Linked_Lists; 
  11. with Objects;                           use Objects; 
  12. with Tokens;                            use Tokens; 
  13.  
  14. package Scripting.Expressions is 
  15.  
  16.     -- An Expression represents a mathematical or logical expression tree that 
  17.     -- can be evaluated to produce a value. It is composed of operators and 
  18.     -- operands. The three base data types used in expressions are numeric, 
  19.     -- string, and boolean, which are represented with the Values hierarchy. 
  20.     type Expression is abstract new Limited_Object with private; 
  21.     type A_Expression is access all Expression'Class; 
  22.  
  23.     -- Evaluates the expression and it's subtree(s). Returns null if the 
  24.     -- expression can't be evaluated due to mismatched types or unresolved 
  25.     -- symbols. 
  26.     function Evaluate( this    : access Expression; 
  27.                        context : not null A_Eval_Context ) return Value_Ptr is abstract; 
  28.  
  29.     -- Deletes the Expression. 
  30.     procedure Delete( this : in out A_Expression ); 
  31.     pragma Postcondition( this = null ); 
  32.  
  33.     ---------------------------------------------------------------------------- 
  34.  
  35.     package Expression_Lists is new Ada.Containers.Doubly_Linked_Lists( A_Expression, "=" ); 
  36.  
  37.     -- Deep deletes the list. 
  38.     procedure Delete_Contents( expressions : in out Expression_Lists.List ); 
  39.     pragma Postcondition( Expression_Lists.Length( expressions ) = 0 ); 
  40.  
  41. private 
  42.  
  43.     type Expression is abstract new Limited_Object with 
  44.         record 
  45.             loc : Token_Location; 
  46.         end record; 
  47.  
  48.     procedure Construct( this : access Expression; loc : Token_Location ); 
  49.  
  50. end Scripting.Expressions;