From 4b7b2693e829166ccec8707b59fb2bc26179551b Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Tue, 22 Jul 2014 00:34:01 +0200 Subject: simple sparse vector type --- fast/grammar.hh | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'fast/grammar.hh') 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 #include +#include +#include +#include +#include + +#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 rhs; + vector target; + //map 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 rules; + vector flat; + vector start_nt; + vector start_t; + + Grammar(string fn); + void add_glue(); + void add_pass_through(); + friend ostream& operator<<(ostream& os, const Grammar& g); }; } // namespace -- cgit v1.2.3