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