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

TreeParser.hpp

Go to the documentation of this file.
00001 #ifndef INC_TreeParser_hpp__
00002 #define INC_TreeParser_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: TreeParser.hpp,v 1.1 2004/10/08 16:27:34 dfisher Exp $
00009  */
00010 
00011 #include <antlr/config.hpp>
00012 #include <antlr/AST.hpp>
00013 #include <antlr/ASTFactory.hpp>
00014 #include <antlr/BitSet.hpp>
00015 #include <antlr/RecognitionException.hpp>
00016 #include <antlr/TreeParserSharedInputState.hpp>
00017 
00018 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00019 namespace antlr {
00020 #endif
00021 
00022 class ANTLR_API TreeParser {
00023 public:
00024         TreeParser();
00025         TreeParser(const TreeParserSharedInputState& state);
00026         virtual ~TreeParser();
00027 
00029         virtual RefAST getAST() = 0;
00030 
00035         virtual void match(RefAST t, const BitSet& b);
00036 
00043         virtual void setASTFactory(ASTFactory* factory)
00044         {
00045                 astFactory = factory;
00046         }
00048         virtual ASTFactory* getASTFactory() const
00049         {
00050                 return astFactory;
00051         }
00053         virtual const char* getTokenName(int num) const = 0;
00055         virtual int getNumTokens() const = 0;
00057         virtual const char* const* getTokenNames() const = 0;
00058 
00060         virtual void reportError(const RecognitionException& ex);
00062         virtual void reportError(const ANTLR_USE_NAMESPACE(std)string& s);
00064         virtual void reportWarning(const ANTLR_USE_NAMESPACE(std)string& s);
00068         virtual void panic();
00069 
00071         virtual void traceIndent();
00072         virtual void traceIn(const char* rname, RefAST t);
00073         virtual void traceOut(const char* rname, RefAST t);
00074 
00080         static RefAST ASTNULL;
00081 
00082 protected:
00083         virtual void match(RefAST t, int ttype);
00084         virtual void matchNot(RefAST t, int ttype);
00085 
00086         /* Where did this rule leave off parsing; avoids a return parameter */
00087         //RefAST _retTree;
00088         /* AST return value for a rule is squirreled away here */
00089         //RefAST returnAST;
00091         ASTFactory* astFactory;
00092 
00094         TreeParserSharedInputState inputState;
00095 
00097         int traceDepth;
00098 
00102         class Tracer {
00103         private:
00104                 TreeParser* parser;
00105                 const char* text;
00106                 RefAST tree;
00107         public:
00108                 Tracer(TreeParser* p, const char* t, RefAST a)
00109                 : parser(p), text(t), tree(a)
00110                 {
00111                         parser->traceIn(text,tree);
00112                 }
00113                 ~Tracer()
00114                 {
00115                         parser->traceOut(text,tree);
00116                 }
00117         private:
00118                 Tracer(const Tracer&);                                                  // undefined
00119                 const Tracer& operator=(const Tracer&); // undefined
00120         };
00121 
00122 private:
00123         // no copying of treeparser instantiations...
00124         TreeParser(const TreeParser& other);
00125         TreeParser& operator=(const TreeParser& other);
00126 };
00127 
00128 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00129 }
00130 #endif
00131 
00132 #endif //INC_TreeParser_hpp__

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