KDevelop API Documentation

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/RIGHTS.html
00007  *
00008  * $Id: Parser.hpp,v 1.2 2003/05/02 00:36:19 okellogg 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(int i)=0;
00075 
00077     virtual RefToken LT(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     }
00103     inline RefAST getAST()
00104     {
00105         return returnAST;
00106     }
00107 
00109     virtual inline ANTLR_USE_NAMESPACE(std)string getFilename() const
00110     {
00111         return inputState->filename;
00112     }
00114     virtual void setFilename(const ANTLR_USE_NAMESPACE(std)string& f)
00115     {
00116         inputState->filename = f;
00117     }
00118 
00119     virtual void setInputState(ParserSharedInputState state)
00120     {
00121         inputState = state;
00122     }
00123     virtual inline ParserSharedInputState getInputState() const
00124     {
00125         return inputState;
00126     }
00127 
00129     virtual void consume()=0;
00131     virtual void consumeUntil(int tokenType);
00133     virtual void consumeUntil(const BitSet& set);
00134 
00139     virtual void match(int t);
00140     virtual void matchNot(int t);
00145     virtual void match(const BitSet& b);
00146 
00150     virtual inline int mark()
00151     {
00152         return inputState->getInput().mark();
00153     }
00155     virtual inline void rewind(int pos)
00156     {
00157         inputState->getInput().rewind(pos);
00158     }
00159 
00161     virtual void reportError(const RecognitionException& ex);
00163     virtual void reportError(const ANTLR_USE_NAMESPACE(std)string& s);
00165     virtual void reportWarning(const ANTLR_USE_NAMESPACE(std)string& s);
00166 
00167     static void panic();
00168 
00170     virtual const char* getTokenName(int num) const = 0;
00172     virtual const char* const* getTokenNames() const = 0;
00174 
00177     virtual int getNumTokens(void) const = 0;
00178 
00180 //  void setTokenBuffer(TokenBuffer<Token>* t);
00181 
00182     virtual void traceIndent();
00183     virtual void traceIn(const char* rname);
00184     virtual void traceOut(const char* rname);
00185 protected:
00186 //  void setTokenNames(const char** tokenNames_);
00187 
00188     ParserSharedInputState inputState;
00189 
00191     RefAST returnAST;
00192 
00194     ASTFactory *astFactory;
00195 
00196     // used to keep track of the indentation for the trace
00197     int traceDepth;
00198 
00202     class Tracer { /*{{{*/
00203     private:
00204         Parser* parser;
00205         const char* text;
00206     public:
00207         Tracer(Parser* p,const char * t)
00208         : parser(p), text(t)
00209         {
00210             parser->traceIn(text);
00211         }
00212         ~Tracer()
00213         {
00214 #ifdef ANTLR_CXX_SUPPORTS_UNCAUGHT_EXCEPTION
00215             // Only give trace if there's no uncaught exception..
00216             if(!ANTLR_USE_NAMESPACE(std)uncaught_exception())
00217 #endif              
00218                 parser->traceOut(text);
00219         }
00220     private:
00221         Tracer(const Tracer&);                          // undefined
00222         const Tracer& operator=(const Tracer&); // undefined
00223         /*}}}*/
00224     };
00225 private:
00226     Parser(const Parser&);                              // undefined
00227     const Parser& operator=(const Parser&);     // undefined
00228 };
00229 
00230 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00231 }
00232 #endif
00233 
00234 #endif //INC_Parser_hpp__
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:34 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003