1 #ifndef _LALRANALYSER_H_INCLUDED_ 2 #define _LALRANALYSER_H_INCLUDED_ 3 /////////////////////////////////////////////////////////////////////////////// 4 // 5 // LALRAnalyser.h 6 // -------------- 7 // Dragon LALR parse table analyser interface defintion 8 // 9 // Design and Implementation by Bjoern Lemke 10 // 11 // (C)opyright 2007 by Bjoern Lemke 12 // 13 // This program is free software; you can redistribute it and/or modify 14 // it under the terms of the GNU General Public License as published by 15 // the Free Software Foundation; either version 2, or (at your option) 16 // any later version. 17 // 18 // This program is distributed in the hope that it will be useful, 19 // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 // GNU General Public License for more details. 22 // 23 // You should have received a copy of the GNU General Public License 24 // along with this program; see the file COPYING. If not, write to 25 // the Free Software Foundation, 59 Temple Place - Suite 330, 26 // Boston, MA 02111-1307, USA. 27 // 28 // INTERFACE MODULE 29 // 30 // Class: LALRAnalyser 31 // 32 // Description: 33 // 34 /////////////////////////////////////////////////////////////////////////////// 35 36 #include <lfcbase/SetT.h> 37 #include <lfcbase/Chain.h> 38 39 #include "Terminal.h" 40 #include "Production.h" 41 #include "FirstHash.h" 42 #include "TransHash.h" 43 #include "LR0Hash.h" 44 #include "LR1Hash.h" 45 #include "LALRHash.h" 46 #include "LR1Trans.h" 47 #include "ClosureCache.h" 48 #include "LR0Element.h" 49 50 class LALRAnalyser { 51 public: 52 53 LALRAnalyser(SetT<Terminal> *pTerminalSet, SetT<Production>* pProductionSet, 54 SetT<FirstHash>* pFirstHashSet); 55 56 ~LALRAnalyser(); 57 58 int analyse(SetT<LR1Hash>& LR1HashSet, SetT<LR1Trans>& LR1TransSet); 59 60 61 private: 62 63 void hashProdTrans(); 64 void getSubTrans(const Chain& prodName, SetT<Chain>& transSet); 65 void getSymbolSet(SetT<Chain>& symbolSet); 66 void getStartElement(LR0Element& e); 67 void getClosure(SetT<LR1Element>& t, const LR1Element& e); 68 bool jumpAndAdd(const SetT<LR1Trans>& LR1TransSet, int id, const Chain& symbol, const LR1Element& e); 69 void getLookAhead(int id, const LR1Element& e, SetT<Chain>& lhset); 70 void createLALRClosure(SetT<LR1Hash>& LR1HashSet); 71 bool getCoreJump(SetT<LR0Element>& t, SetT<LR0Element>& s, const Chain& symbol); 72 bool isEpsilonProd(const Chain& prod); 73 74 int _rot; 75 void rotate(const Chain&); 76 77 SetT<Terminal>* _pTerminalSet; 78 SetT<Production>* _pProductionSet; 79 const SetT<FirstHash>* _pFirstHashSet; 80 81 SetT<ClosureCache> _closureCacheSet; 82 83 SetT<TransHash> _transHashSet; 84 SetT<LR0Hash> _LR0HashSet; 85 SetT<LALRHash> _LALRHashSet; 86 }; 87 88 #endif 89 90 91 92 93 94