00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef ARCHON_UTILITIES_LR_PARSER_CANONICAL_H
00021 #define ARCHON_UTILITIES_LR_PARSER_CANONICAL_H
00022
00023 #include <vector>
00024
00025 #include <archon/util/cfg.H>
00026 #include <archon/util/lr_parser_base.H>
00027
00028 namespace Archon
00029 {
00030 namespace Utilities
00031 {
00032 using namespace std;
00033
00034 class ClrParser: public LrParserBase
00035 {
00036 vector<int> actionTable;
00037 vector<int> gotoTable;
00038 int numberOfStates;
00039
00040 int getAction(int state, int terminal) const;
00041 int getGoto(int state, int nonterminal) const;
00042
00043 struct LR1Item
00044 {
00045 int production;
00046 int position;
00047 int lookahead;
00048 LR1Item() {}
00049 LR1Item(int production, int position, int lookahead):
00050 production(production), position(position), lookahead(lookahead) {}
00051 bool operator<(const LR1Item &i) const
00052 {
00053 return production < i.production ||
00054 production == i.production && position < i.position ||
00055 position == i.position && lookahead < i.lookahead;
00056 }
00057 };
00058
00059 string printItemSets(const vector<LR1Item> &,
00060 const vector<set<int> > &, int width);
00061
00062 public:
00063 ClrParser(CFG &, const ActorBase * =0, const Printer * =0);
00064 ~ClrParser();
00065 };
00066 }
00067 }
00068
00069 #endif // ARCHON_UTILITIES_LR_PARSER_CANONICAL_H