00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00028
00029 #ifndef _GRAMMAR
00030 #define _GRAMMAR
00031
00032 #include <string>
00033 #include <list>
00034 #include <map>
00035 #include <set>
00036
00037 #include "tokens.h"
00038
00042
00043 class rule {
00044 protected:
00046 string head;
00048 list<string> right;
00050 int gov;
00051
00052 public:
00054 rule(const string &, const list<string> &, const int);
00055 rule(const rule & r);
00056 rule();
00057 rule & operator=(const rule&);
00058
00060 void set_governor(const int);
00062 unsigned int get_governor(void) const;
00064 string get_head() const;
00066 list<string> get_right() const;
00067 };
00068
00073
00074 class grammar : public multimap<string,rule> {
00075
00076 private:
00078 set<string> nonterminal;
00080 multimap<string,rule> wild;
00082 multimap<string,string> filemap;
00084 map<string,int> prior;
00086 set<string> hidden;
00088 set<string> flat;
00090 set<string> notop;
00092 set<string> onlytop;
00094 string start;
00096 void new_rule(const string &, const list<string> &, bool, const int rgov);
00097
00098 public:
00099
00100
00101 static unsigned int NOGOV;
00102
00103 static unsigned int DEFGOV;
00104
00106 grammar(const string &);
00107
00108
00109 int get_specificity(const string &) const;
00110
00111 int get_priority(const string &) const;
00113 string get_start_symbol() const;
00115 bool is_hidden(const string &) const;
00117 bool is_flat(const string &) const;
00119 bool is_notop(const string &) const;
00121 bool is_onlytop(const string &) const;
00123 bool is_terminal(const string &) const;
00125 list<rule> get_rules_right(const string &) const;
00127 list<rule> get_rules_right_wildcard(const string &) const;
00129 bool in_filemap(const string &, const string &) const;
00130 };
00131
00132 #endif
00133
00134
00135
00136
00137