CVC3

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  *
00011  * License to use, copy, modify, sell and/or distribute this software
00012  * and its documentation for any purpose is hereby granted without
00013  * royalty, subject to the terms and conditions defined in the \ref
00014  * LICENSE file provided with this distribution.
00015  * 
00016  * <hr>
00017  * 
00018  * The top-level API to the parser.  At this level, it is simply a
00019  * stream of commands (Expr's) terminated by an infinite sequence of
00020  * Null Expr.  It has a support to parse several different input
00021  * languages (as many as we care to implement), and may take a file
00022  * name, or an istream to read from (default: std::cin, or stdin).
00023  * Using iostream means no more worries about whether to close files
00024  * or not.
00025  */
00026 /*****************************************************************************/
00027 
00028 #ifndef _cvc3__parser_h_
00029 #define _cvc3__parser_h_
00030 
00031 #include "exception.h"
00032 #include "lang.h"
00033 
00034 namespace CVC3 {
00035 
00036   class ValidityChecker;
00037   class Translator;
00038   class Expr;
00039   
00040   // Internal parser state and other data
00041   class ParserData;
00042 
00043   class Parser {
00044   private:
00045     ParserData* d_data;
00046     // Internal methods for constructing and destroying the actual parser
00047     void initParser();
00048     void deleteParser();
00049   public:
00050     // Constructors
00051     Parser(ValidityChecker* vc, Translator* translator, InputLanguage lang,
00052      // The 'interactive' flag is ignored when fileName != ""
00053      bool interactive = true,
00054      const std::string& fileName = "");
00055     Parser(ValidityChecker* vc, Translator* translator, InputLanguage lang, std::istream& is,
00056      bool interactive = false);
00057     // Destructor
00058     ~Parser();
00059     // Read the next command.  
00060     Expr next();
00061     // Check if we are done (end of input has been reached)
00062     bool done() const;
00063     // The same check can be done by using the class Parser's value as
00064     // a Boolean
00065     operator bool() const { return done(); }
00066     void printLocation(std::ostream & out) const;
00067     // Reset any local data that depends on validity checker
00068     void reset();
00069   }; // end of class Parser
00070 
00071   // The global pointer to ParserTemp.  Each instance of class Parser
00072   // sets this pointer before any calls to the lexer.  We do it this
00073   // way because flex and bison use global vars, and we want each
00074   // Parser object to appear independent.
00075   class ParserTemp;
00076   extern ParserTemp* parserTemp;
00077 
00078 } // end of namespace CVC3
00079 
00080 #endif