parser.h

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  * \file parser.h
00004  * 
00005  * Author: Sergey Berezin
00006  * 
00007  * Created: Wed Feb  5 11:46:57 2003
00008  *
00009  * <hr>
00010  * Copyright (C) 2003 by the Board of Trustees of Leland Stanford
00011  * Junior University and by New York University. 
00012  *
00013  * License to use, copy, modify, sell and/or distribute this software
00014  * and its documentation for any purpose is hereby granted without
00015  * royalty, subject to the terms and conditions defined in the \ref
00016  * LICENSE file provided with this distribution.  In particular:
00017  *
00018  * - The above copyright notice and this permission notice must appear
00019  * in all copies of the software and related documentation.
00020  *
00021  * - THE SOFTWARE IS PROVIDED "AS-IS", WITHOUT ANY WARRANTIES,
00022  * EXPRESSED OR IMPLIED.  USE IT AT YOUR OWN RISK.
00023  * 
00024  * <hr>
00025  * 
00026  * The top-level API to the parser.  At this level, it is simply a
00027  * stream of commands (Expr's) terminated by an infinite sequence of
00028  * Null Expr.  It has a support to parse several different input
00029  * languages (as many as we care to implement), and may take a file
00030  * name, or an istream to read from (default: std::cin, or stdin).
00031  * Using iostream means no more worries about whether to close files
00032  * or not.
00033  */
00034 /*****************************************************************************/
00035 
00036 #ifndef _CVC_lite__parser_h_
00037 #define _CVC_lite__parser_h_
00038 
00039 #include "exception.h"
00040 #include "lang.h"
00041 
00042 namespace CVCL {
00043 
00044   class ValidityChecker;
00045   class Expr;
00046   
00047   // Internal parser state and other data
00048   class ParserData;
00049 
00050   class Parser {
00051   private:
00052     ParserData* d_data;
00053     // Internal methods for constructing and destroying the actual parser
00054     void initParser();
00055     void deleteParser();
00056   public:
00057     // Constructors
00058     Parser(ValidityChecker* vc, InputLanguage lang,
00059            // The 'interactive' flag is ignored when fileName != ""
00060            bool interactive = true,
00061            const std::string& fileName = "");
00062     Parser(ValidityChecker* vc, InputLanguage lang, std::istream& is,
00063            bool interactive = false);
00064     // Destructor
00065     ~Parser();
00066     // Read the next command.  
00067     Expr next() throw (Exception);
00068     // Check if we are done (end of input has been reached)
00069     bool done() const;
00070     // The same check can be done by using the class Parser's value as
00071     // a Boolean
00072     operator bool() const { return done(); }
00073     void printLocation(std::ostream & out) const;
00074   }; // end of class Parser
00075 
00076   // The global pointer to ParserTemp.  Each instance of class Parser
00077   // sets this pointer before any calls to the lexer.  We do it this
00078   // way because flex and bison use global vars, and we want each
00079   // Parser object to appear independent.
00080   class ParserTemp;
00081   extern ParserTemp* parserTemp;
00082 
00083 } // end of namespace CVCL
00084 
00085 #endif

Generated on Thu Apr 13 16:57:32 2006 for CVC Lite by  doxygen 1.4.4