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 Objects;                           use Objects; 
  10. with Scripting.Expressions;             use Scripting.Expressions; 
  11. with Scripting.Scripts;                 use Scripting.Scripts; 
  12. with Tokens.Scanners;                   use Tokens.Scanners; 
  13.  
  14. package Scripting.Parsers is 
  15.  
  16.     -- A Parser parses input from a token scanner. Given a token scanner loaded 
  17.     -- with an input stream, the parser will read tokens from the scanner and 
  18.     -- create a corresponding abstract syntax tree. 
  19.     type Parser is new Limited_Object with private; 
  20.     type A_Parser is access all Parser'Class; 
  21.  
  22.     -- Creates and returns a new Parser. 
  23.     function Create_Parser return A_Parser; 
  24.     pragma Postcondition( Create_Parser'Result /= null ); 
  25.  
  26.     -- Scans an expression or raises Parse_Exception if one is not found. 
  27.     -- Parse_Exception will be raised if a parsing error occurs. Token_Exception 
  28.     -- will be raised if an unrecognized token is encountered by the scanner. 
  29.     function Expect_Expression( this    : not null access Parser'Class; 
  30.                                 scanner : not null A_Token_Scanner ) return A_Expression; 
  31.     pragma Postcondition( Expect_Expression'Result /= null ); 
  32.  
  33.     -- Scans an expression or returns null if one is not found. Parse_Exception 
  34.     -- will be raised if a parsing error occurs. Token_Exception will be raised 
  35.     -- if an unrecognized token is encountered by the scanner. 
  36.     function Scan_Expression( this    : not null access Parser'Class; 
  37.                               scanner : not null A_Token_Scanner ) return A_Expression; 
  38.  
  39.     -- Scans a script or returns null if one is not found. Parse_Exception will 
  40.     -- be raised if a parsing error occurs. Token_Exception will be raised if an 
  41.     -- unrecognized token is encounter by the scanner. 
  42.     -- 
  43.     -- The grammar implemented by this function is: 
  44.     -- script := <statement_list> 
  45.     function Scan_Script( this    : not null access Parser'Class; 
  46.                           scanner : not null A_Token_Scanner ) return A_Script; 
  47.  
  48.     -- Deletes the Parser. 
  49.     procedure Delete( this : in out A_Parser ); 
  50.     pragma Postcondition( this = null ); 
  51.  
  52. private 
  53.  
  54.     type Parser is new Limited_Object with null record; 
  55.  
  56. end Scripting.Parsers;