summaryrefslogtreecommitdiff
path: root/fast/grammar.hh
blob: 51501cfc991b3ec3400ab9a518e39579e40503e4 (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
78
79
80
81
82
83
84
85
#pragma once

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

#include "dummyvector.h"

using namespace std;


string esc_str(const string& s); // FIXME

namespace G {

struct NT {
        string symbol;
  unsigned int index;

  NT() {};
  NT(string& s);
  string repr() const;
  string escaped() const;
  friend ostream& operator<<(ostream& os, const NT& t);
};

struct T {
  string word;

  T(string& s);
  string repr() const;
  string escaped() const { return esc_str(word); }
  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;
  string escaped() 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;
  string escaped() const;
  friend ostream& operator<<(ostream& os, const Rule& r);

  MSGPACK_DEFINE();
};

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