1*16467b97STreehugger Robot #ifndef ANTLR3TREEPARSER_HPP 2*16467b97STreehugger Robot #define ANTLR3TREEPARSER_HPP 3*16467b97STreehugger Robot 4*16467b97STreehugger Robot // [The "BSD licence"] 5*16467b97STreehugger Robot // Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB 6*16467b97STreehugger Robot 7*16467b97STreehugger Robot // 8*16467b97STreehugger Robot // All rights reserved. 9*16467b97STreehugger Robot // 10*16467b97STreehugger Robot // Redistribution and use in source and binary forms, with or without 11*16467b97STreehugger Robot // modification, are permitted provided that the following conditions 12*16467b97STreehugger Robot // are met: 13*16467b97STreehugger Robot // 1. Redistributions of source code must retain the above copyright 14*16467b97STreehugger Robot // notice, this list of conditions and the following disclaimer. 15*16467b97STreehugger Robot // 2. Redistributions in binary form must reproduce the above copyright 16*16467b97STreehugger Robot // notice, this list of conditions and the following disclaimer in the 17*16467b97STreehugger Robot // documentation and/or other materials provided with the distribution. 18*16467b97STreehugger Robot // 3. The name of the author may not be used to endorse or promote products 19*16467b97STreehugger Robot // derived from this software without specific prior written permission. 20*16467b97STreehugger Robot // 21*16467b97STreehugger Robot // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22*16467b97STreehugger Robot // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23*16467b97STreehugger Robot // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24*16467b97STreehugger Robot // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25*16467b97STreehugger Robot // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26*16467b97STreehugger Robot // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27*16467b97STreehugger Robot // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28*16467b97STreehugger Robot // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29*16467b97STreehugger Robot // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30*16467b97STreehugger Robot // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31*16467b97STreehugger Robot 32*16467b97STreehugger Robot #include "antlr3defs.hpp" 33*16467b97STreehugger Robot 34*16467b97STreehugger Robot /** Internal structure representing an element in a hash bucket. 35*16467b97STreehugger Robot * Stores the original key so that duplicate keys can be rejected 36*16467b97STreehugger Robot * if necessary, and contains function can be supported If the hash key 37*16467b97STreehugger Robot * could be unique I would have invented the perfect compression algorithm ;-) 38*16467b97STreehugger Robot */ 39*16467b97STreehugger Robot ANTLR_BEGIN_NAMESPACE() 40*16467b97STreehugger Robot 41*16467b97STreehugger Robot template<class ImplTraits> 42*16467b97STreehugger Robot class TreeParser : public ImplTraits::template RecognizerType< TreeParser<ImplTraits> > 43*16467b97STreehugger Robot { 44*16467b97STreehugger Robot public: 45*16467b97STreehugger Robot typedef typename ImplTraits::TreeNodeStreamType TreeNodeStreamType; 46*16467b97STreehugger Robot typedef TreeNodeStreamType StreamType; 47*16467b97STreehugger Robot typedef typename TreeNodeStreamType::IntStreamType IntStreamType; 48*16467b97STreehugger Robot typedef typename ImplTraits::TreeType TreeType; 49*16467b97STreehugger Robot typedef TreeType TokenType; 50*16467b97STreehugger Robot typedef typename ImplTraits::template ExceptionBase<TreeNodeStreamType> ExceptionBaseType; 51*16467b97STreehugger Robot typedef typename ImplTraits::template RecognizerType< TreeParser<ImplTraits> > RecognizerType; 52*16467b97STreehugger Robot typedef typename RecognizerType::RecognizerSharedStateType RecognizerSharedStateType; 53*16467b97STreehugger Robot typedef Empty TokenSourceType; 54*16467b97STreehugger Robot typedef typename ImplTraits::BitsetListType BitsetListType; 55*16467b97STreehugger Robot typedef typename ImplTraits::StringType StringType; 56*16467b97STreehugger Robot typedef typename ImplTraits::CommonTokenType CommonTokenType; 57*16467b97STreehugger Robot 58*16467b97STreehugger Robot private: 59*16467b97STreehugger Robot /** Pointer to the common tree node stream for the parser 60*16467b97STreehugger Robot */ 61*16467b97STreehugger Robot TreeNodeStreamType* m_ctnstream; 62*16467b97STreehugger Robot 63*16467b97STreehugger Robot public: 64*16467b97STreehugger Robot TreeParser( ANTLR_UINT32 sizeHint, TreeNodeStreamType* ctnstream, 65*16467b97STreehugger Robot RecognizerSharedStateType* state); 66*16467b97STreehugger Robot TreeNodeStreamType* get_ctnstream() const; 67*16467b97STreehugger Robot IntStreamType* get_istream() const; 68*16467b97STreehugger Robot RecognizerType* get_rec(); 69*16467b97STreehugger Robot 70*16467b97STreehugger Robot //same as above. Just that get_istream exists for lexer, parser, treeparser 71*16467b97STreehugger Robot //get_parser_istream exists only for parser, treeparser. So use it accordingly 72*16467b97STreehugger Robot IntStreamType* get_parser_istream() const; 73*16467b97STreehugger Robot 74*16467b97STreehugger Robot /** Set the input stream and reset the parser 75*16467b97STreehugger Robot */ 76*16467b97STreehugger Robot void setTreeNodeStream(TreeNodeStreamType* input); 77*16467b97STreehugger Robot 78*16467b97STreehugger Robot /** Return a pointer to the input stream 79*16467b97STreehugger Robot */ 80*16467b97STreehugger Robot TreeNodeStreamType* getTreeNodeStream(); 81*16467b97STreehugger Robot 82*16467b97STreehugger Robot TokenType* getMissingSymbol( IntStreamType* istream, 83*16467b97STreehugger Robot ExceptionBaseType* e, 84*16467b97STreehugger Robot ANTLR_UINT32 expectedTokenType, 85*16467b97STreehugger Robot BitsetListType* follow); 86*16467b97STreehugger Robot 87*16467b97STreehugger Robot /** Pointer to a function that knows how to free resources of an ANTLR3 tree parser. 88*16467b97STreehugger Robot */ 89*16467b97STreehugger Robot ~TreeParser(); 90*16467b97STreehugger Robot 91*16467b97STreehugger Robot void fillExceptionData( ExceptionBaseType* ex ); 92*16467b97STreehugger Robot void displayRecognitionError( ANTLR_UINT8** tokenNames, ExceptionBaseType* ex ); 93*16467b97STreehugger Robot void exConstruct(); 94*16467b97STreehugger Robot void mismatch(ANTLR_UINT32 ttype, BitsetListType* follow); 95*16467b97STreehugger Robot }; 96*16467b97STreehugger Robot 97*16467b97STreehugger Robot ANTLR_END_NAMESPACE() 98*16467b97STreehugger Robot 99*16467b97STreehugger Robot #include "antlr3treeparser.inl" 100*16467b97STreehugger Robot 101*16467b97STreehugger Robot #endif 102