summaryrefslogtreecommitdiff
path: root/fast/grammar.hh
diff options
context:
space:
mode:
Diffstat (limited to 'fast/grammar.hh')
-rw-r--r--fast/grammar.hh58
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