antlr3treeparser.hpp 4.1 KB

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