summaryrefslogtreecommitdiff
path: root/fast/grammar.hh
blob: 76b96a641d2dc13734de61af2e88fe45917f1569 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once

#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
#include <map>

#include "dummyvector.h"

using namespace std;


namespace G {

struct NT {
        string symbol;
  unsigned int index;

  NT() {};
  NT(string& s);
  string repr() const;
  friend ostream& operator<<(ostream& os, const NT& 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);
};

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 G