diff options
author | Patrick Simianer <p@simianer.de> | 2014-07-22 00:34:01 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2014-07-22 00:34:01 +0200 |
commit | 4b7b2693e829166ccec8707b59fb2bc26179551b (patch) | |
tree | 1c103865488aa8cefabf9714cd571066135b8ca4 /fast/grammar.hh | |
parent | 02bbe0c6bc69283a988caf8f0ab3dadb5d9d72b5 (diff) |
simple sparse vector type
Diffstat (limited to 'fast/grammar.hh')
-rw-r--r-- | fast/grammar.hh | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/fast/grammar.hh b/fast/grammar.hh index d17a331..3c7f208 100644 --- a/fast/grammar.hh +++ b/fast/grammar.hh @@ -1,6 +1,13 @@ #pragma once +#include <iostream> #include <string> +#include <sstream> +#include <fstream> +#include <vector> +#include <map> + +#include "dummyvector.h" using namespace std; @@ -10,13 +17,60 @@ namespace G { struct NT { string symbol; unsigned int index; + + NT() {}; + NT(string& s); + string repr() const; + friend ostream& operator<<(ostream& os, const NT& t); }; -class T { +struct T { string word; + + T(string& s); + string repr() const; + friend ostream& operator<<(ostream& os, const NT& nt); +}; + +enum item_type { + NON_TERMINAL, + TERMINAL +}; + +struct Item { + item_type type; + NT* nt; + T* t; + + Item(string& s); + string repr() const; + friend ostream& operator<<(ostream& os, const Item& i); +}; + +struct Rule { + NT* lhs; + vector<Item*> rhs; + vector<Item*> target; + //map<int,int> map; + size_t arity; + DummyVector f; + + Rule() {}; + Rule(string& s); + string repr() const; + friend ostream& operator<<(ostream& os, const Rule& r); }; -class Rule { +struct Grammar { + vector<Rule*> rules; + vector<Rule*> flat; + vector<Rule*> start_nt; + vector<Rule*> start_t; + + Grammar(string fn); + void add_glue(); + void add_pass_through(); + friend ostream& operator<<(ostream& os, const Grammar& g); }; } // namespace |