antlr3cyclicdfa.hpp 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. // [The "BSD licence"]
  9. // Copyright (c) 2005-2009 Gokulakannan Somasundaram, ElectronDB
  10. //
  11. // All rights reserved.
  12. //
  13. // Redistribution and use in source and binary forms, with or without
  14. // modification, are permitted provided that the following conditions
  15. // are met:
  16. // 1. Redistributions of source code must retain the above copyright
  17. // notice, this list of conditions and the following disclaimer.
  18. // 2. Redistributions in binary form must reproduce the above copyright
  19. // notice, this list of conditions and the following disclaimer in the
  20. // documentation and/or other materials provided with the distribution.
  21. // 3. The name of the author may not be used to endorse or promote products
  22. // derived from this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  25. // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  26. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  27. // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  28. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  29. // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  30. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  33. // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. namespace antlr3 {
  35. template<class ImplTraits, class CtxType>
  36. class CyclicDFA : public ImplTraits::AllocPolicyType
  37. {
  38. public:
  39. typedef typename CtxType::StreamType StreamType;
  40. typedef typename CtxType::ExceptionBaseType ExceptionBaseType;
  41. typedef typename ImplTraits::template RecognizerType<StreamType> RecognizerType;
  42. typedef typename StreamType::IntStreamType IntStreamType;
  43. typedef typename StreamType::TokenType TokenType;
  44. typedef TokenType CommonTokenType;
  45. typedef CtxType ContextType;
  46. private:
  47. /// Decision number that a particular static structure
  48. /// represents.
  49. ///
  50. const ANTLR_INT32 m_decisionNumber;
  51. /// What this decision represents
  52. ///
  53. const ANTLR_UCHAR* m_description;
  54. const ANTLR_INT32* const m_eot;
  55. const ANTLR_INT32* const m_eof;
  56. const ANTLR_INT32* const m_min;
  57. const ANTLR_INT32* const m_max;
  58. const ANTLR_INT32* const m_accept;
  59. const ANTLR_INT32* const m_special;
  60. const ANTLR_INT32* const *const m_transition;
  61. public:
  62. CyclicDFA( ANTLR_INT32 decisionNumber
  63. , const ANTLR_UCHAR* description
  64. , const ANTLR_INT32* const eot
  65. , const ANTLR_INT32* const eof
  66. , const ANTLR_INT32* const min
  67. , const ANTLR_INT32* const max
  68. , const ANTLR_INT32* const accept
  69. , const ANTLR_INT32* const special
  70. , const ANTLR_INT32* const *const transition );
  71. CyclicDFA( const CyclicDFA& cdfa );
  72. CyclicDFA& operator=( const CyclicDFA& dfa);
  73. ANTLR_INT32 specialStateTransition(CtxType * ctx, RecognizerType* recognizer, IntStreamType* is, ANTLR_INT32 s);
  74. ANTLR_INT32 specialTransition(CtxType * ctx, RecognizerType* recognizer, IntStreamType* is, ANTLR_INT32 s);
  75. template<typename SuperType>
  76. ANTLR_INT32 predict(CtxType* ctx, RecognizerType* recognizer, IntStreamType* is, SuperType& super);
  77. private:
  78. void noViableAlt(RecognizerType* rec, ANTLR_UINT32 s);
  79. };
  80. }
  81. #include "antlr3cyclicdfa.inl"
  82. #endif