Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Parser.hpp

Go to the documentation of this file.
00001 #ifndef INC_Parser_hpp__
00002 #define INC_Parser_hpp__
00003 
00004 /* ANTLR Translator Generator
00005  * Project led by Terence Parr at http://www.jGuru.com
00006  * Software rights: http://www.antlr.org/license.html
00007  *
00008  * $Id: Parser.hpp,v 1.1 2004/10/08 16:27:34 dfisher Exp $
00009  */
00010 
00011 #include <antlr/config.hpp>
00012 #include <antlr/BitSet.hpp>
00013 #include <antlr/TokenBuffer.hpp>
00014 #include <antlr/RecognitionException.hpp>
00015 #include <antlr/ASTFactory.hpp>
00016 #include <antlr/ParserSharedInputState.hpp>
00017 
00018 #include <exception>
00019 
00020 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00021 namespace antlr {
00022 #endif
00023 
00024 extern bool DEBUG_PARSER;
00025 
00061 class ANTLR_API Parser {
00062 protected:
00063         Parser(TokenBuffer& input_);
00064         Parser(TokenBuffer* input_);
00065 
00066         Parser(const ParserSharedInputState& state);
00067 public:
00068         virtual ~Parser();
00069 
00074         virtual int LA(unsigned int i)=0;
00075 
00077         virtual RefToken LT(unsigned int i)=0;
00078 
00083         virtual void setASTNodeFactory( ASTFactory *factory )
00084         {
00085                 astFactory = factory;
00086         }
00090         virtual void setASTFactory( ASTFactory *factory )
00091         {
00092                 astFactory = factory;
00093         }
00098         virtual ASTFactory* getASTFactory()
00099         {
00100                 return astFactory;
00101         }
00106         virtual RefAST getAST() {
00107                 return RefAST();
00108         }
00109 
00111         virtual inline ANTLR_USE_NAMESPACE(std)string getFilename() const
00112         {
00113                 return inputState->filename;
00114         }
00116         virtual void setFilename(const ANTLR_USE_NAMESPACE(std)string& f)
00117         {
00118                 inputState->filename = f;
00119         }
00120 
00121         virtual void setInputState(ParserSharedInputState state)
00122         {
00123                 inputState = state;
00124         }
00125         virtual inline ParserSharedInputState getInputState() const
00126         {
00127                 return inputState;
00128         }
00129 
00131         virtual void consume()=0;
00133         virtual void consumeUntil(int tokenType);
00135         virtual void consumeUntil(const BitSet& set);
00136 
00141         virtual void match(int t);
00142         virtual void matchNot(int t);
00147         virtual void match(const BitSet& b);
00148 
00152         virtual inline unsigned int mark()
00153         {
00154                 return inputState->getInput().mark();
00155         }
00157         virtual inline void rewind(unsigned int pos)
00158         {
00159                 inputState->getInput().rewind(pos);
00160         }
00161 
00163         virtual void reportError(const RecognitionException& ex);
00165         virtual void reportError(const ANTLR_USE_NAMESPACE(std)string& s);
00167         virtual void reportWarning(const ANTLR_USE_NAMESPACE(std)string& s);
00168 
00172         virtual void panic();
00173 
00175         virtual const char* getTokenName(int num) const = 0;
00177         virtual const char* const* getTokenNames() const = 0;
00181         virtual int getNumTokens(void) const = 0;
00182 
00184 //      void setTokenBuffer(TokenBuffer<Token>* t);
00185 
00186         virtual void traceIndent();
00187         virtual void traceIn(const char* rname);
00188         virtual void traceOut(const char* rname);
00189 protected:
00190 //      void setTokenNames(const char** tokenNames_);
00191 
00192         ParserSharedInputState inputState;
00193 
00194 //      /// AST return value for a rule is squirreled away here
00195 //      RefAST returnAST;
00196 
00198         ASTFactory *astFactory;
00199 
00200         // used to keep track of the indentation for the trace
00201         int traceDepth;
00202 
00206         class Tracer { /*{{{*/
00207         private:
00208                 Parser* parser;
00209                 const char* text;
00210         public:
00211                 Tracer(Parser* p,const char * t)
00212                 : parser(p), text(t)
00213                 {
00214                         parser->traceIn(text);
00215                 }
00216                 ~Tracer()
00217                 {
00218 #ifdef ANTLR_CXX_SUPPORTS_UNCAUGHT_EXCEPTION
00219                         // Only give trace if there's no uncaught exception..
00220                         if(!ANTLR_USE_NAMESPACE(std)uncaught_exception())
00221 #endif
00222                                 parser->traceOut(text);
00223                 }
00224         private:
00225                 Tracer(const Tracer&);                                                  // undefined
00226                 const Tracer& operator=(const Tracer&); // undefined
00227                 /*}}}*/
00228         };
00229 private:
00230         Parser(const Parser&);                                                          // undefined
00231         const Parser& operator=(const Parser&);         // undefined
00232 };
00233 
00234 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00235 }
00236 #endif
00237 
00238 #endif //INC_Parser_hpp__

Generated on Wed Nov 3 12:59:01 2004 for Lemur Toolkit by doxygen1.2.18