1 /// Definition of a cyclic dfa structure such that it can be
2 /// initialized at compile time and have only a single
3 /// runtime function that can deal with all cyclic dfa
4 /// structures and show Java how it is done ;-)
5 ///
6 #ifndef	ANTLR3_CYCLICDFA_HPP
7 #define	ANTLR3_CYCLICDFA_HPP
8 
9 // [The "BSD licence"]
10 // Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
11 
12 //
13 // All rights reserved.
14 //
15 // Redistribution and use in source and binary forms, with or without
16 // modification, are permitted provided that the following conditions
17 // are met:
18 // 1. Redistributions of source code must retain the above copyright
19 //    notice, this list of conditions and the following disclaimer.
20 // 2. Redistributions in binary form must reproduce the above copyright
21 //    notice, this list of conditions and the following disclaimer in the
22 //    documentation and/or other materials provided with the distribution.
23 // 3. The name of the author may not be used to endorse or promote products
24 //    derived from this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 
37 #include   "antlr3defs.hpp"
38 
39 #ifdef ANTLR3_WINDOWS
40 #pragma warning	(push)
41 #pragma warning (disable : 4510)
42 #pragma warning (disable : 4512)
43 #pragma warning (disable : 4610)
44 #endif
45 
46 ANTLR_BEGIN_NAMESPACE()
47 
48 template<class ImplTraits, class CtxType>
49 class CyclicDFA : public ImplTraits::AllocPolicyType
50 {
51 public:
52 	typedef typename CtxType::StreamType StreamType;
53 	typedef typename CtxType::ExceptionBaseType ExceptionBaseType;
54 	typedef typename ImplTraits::template RecognizerType<StreamType> RecognizerType;
55 	typedef typename StreamType::IntStreamType IntStreamType;
56 	typedef typename StreamType::TokenType	TokenType;
57 	typedef TokenType	CommonTokenType;
58 	typedef CtxType ContextType;
59 
60 private:
61     /// Decision number that a particular static structure
62     ///  represents.
63     ///
64     const ANTLR_INT32		m_decisionNumber;
65 
66     /// What this decision represents
67     ///
68     const ANTLR_UCHAR*			m_description;
69 	const ANTLR_INT32* const	m_eot;
70     const ANTLR_INT32* const	m_eof;
71     const ANTLR_INT32* const	m_min;
72     const ANTLR_INT32* const	m_max;
73     const ANTLR_INT32* const	m_accept;
74     const ANTLR_INT32* const	m_special;
75     const ANTLR_INT32* const *const	m_transition;
76 
77 public:
78 	CyclicDFA( ANTLR_INT32	decisionNumber
79 				, const ANTLR_UCHAR*	description
80 				, const ANTLR_INT32* const	eot
81 				, const ANTLR_INT32* const	eof
82 				, const ANTLR_INT32* const	min
83 				, const ANTLR_INT32* const	max
84 				, const ANTLR_INT32* const	accept
85 				, const ANTLR_INT32* const	special
86 				, const ANTLR_INT32* const *const	transition );
87 	CyclicDFA( const CyclicDFA& cdfa );
88     CyclicDFA& operator=( const CyclicDFA& dfa);
89 
90 	ANTLR_INT32	specialStateTransition(CtxType * ctx, RecognizerType* recognizer, IntStreamType* is, ANTLR_INT32 s);
91     ANTLR_INT32	specialTransition(CtxType * ctx, RecognizerType* recognizer, IntStreamType* is, ANTLR_INT32 s);
92 
93 	template<typename SuperType>
94     ANTLR_INT32	predict(CtxType* ctx, RecognizerType* recognizer, IntStreamType* is, SuperType& super);
95 
96 private:
97 	void noViableAlt(RecognizerType* rec, ANTLR_UINT32	s);
98 };
99 
100 ANTLR_END_NAMESPACE()
101 
102 #ifdef ANTLR3_WINDOWS
103 #pragma warning	(pop)
104 #endif
105 
106 #include "antlr3cyclicdfa.inl"
107 
108 #endif
109