Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

grammar.h

Go to the documentation of this file.
00001 
00002 //
00003 //    FreeLing - Open Source Language Analyzers
00004 //
00005 //    Copyright (C) 2004   TALP Research Center
00006 //                         Universitat Politecnica de Catalunya
00007 //
00008 //    This library is free software; you can redistribute it and/or
00009 //    modify it under the terms of the GNU Lesser General Public
00010 //    License as published by the Free Software Foundation; either
00011 //    version 2.1 of the License, or (at your option) any later version.
00012 //
00013 //    This library is distributed in the hope that it will be useful,
00014 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 //    Lesser General Public License for more details.
00017 //
00018 //    You should have received a copy of the GNU Lesser General Public
00019 //    License along with this library; if not, write to the Free Software
00020 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00021 //
00022 //    contact: Lluis Padro (padro@lsi.upc.es)
00023 //             TALP Research Center
00024 //             despatx C6.212 - Campus Nord UPC
00025 //             08034 Barcelona.  SPAIN
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   // no-governor mark
00101   static unsigned int NOGOV;
00102   // default governor (first element in rule)
00103   static unsigned int DEFGOV;
00104 
00106   grammar(const string &);
00107 
00108   // obtain the specificity of a terminal symbol
00109   int get_specificity(const string &) const;
00110   // obtain the priority of a non-terminal symbol
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 

Generated on Wed Apr 26 12:55:30 2006 for FreeLing by  doxygen 1.4.4