Tensor Comprehensions
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
parser.h
Go to the documentation of this file.
1 
16 #pragma once
17 
18 #include <iostream>
19 #include <memory>
20 #include <string>
21 #include <unordered_map>
22 #include <vector>
23 
24 namespace tc {
25 namespace parser {
26 
27 int uid();
28 
29 struct Node;
30 
31 struct Edge {
32  Edge(const Node& s, const std::string& trans, const Node& t)
33  : source(s), transition(trans), target(t) {}
34 
35  Edge(Edge&&) = default;
36  Edge(const Edge&) = delete;
37  Edge& operator=(const Edge&) const = delete;
38 
39  const Node& source;
40  std::string transition;
41  const Node& target;
42 };
43 
44 struct Node {
45  Node(const std::string& n) : id(uid()), name(n) {}
46 
47  Node(Node&&) = default;
48  Node(const Node&) = delete;
49  Node& operator=(const Node&) const = delete;
50 
51  int id;
52  std::string name;
53  std::vector<Edge> outEdges;
54 };
55 
56 struct GFG {
57  GFG() {}
58  Node& addNode(const std::string& name);
59  const Edge& addEdge(Node& s, const std::string& transition, const Node& t);
60 
61  GFG(GFG&&) = default;
62  GFG(const GFG&) = delete;
63  GFG& operator=(const GFG&) const = delete;
64 
65  static GFG makeGFG(const std::string& grammar);
66 
67  std::vector<std::unique_ptr<Node>> nodes;
68 
69  friend std::ostream& operator<<(std::ostream& os, const GFG& g);
70 
71  private:
72  std::unordered_map<std::string, int> name2NodeId;
73 };
74 
75 std::ostream& operator<<(std::ostream& os, const Node& n);
76 std::ostream& operator<<(std::ostream& os, const Edge& e);
77 std::ostream& operator<<(std::ostream& os, const GFG& g);
78 }
79 } // ns tc::parser
std::unordered_map< std::string, int > name2NodeId
Definition: parser.h:72
static GFG makeGFG(const std::string &grammar)
Definition: parser.h:44
std::ostream & operator<<(std::ostream &os, const Node &n)
Node & operator=(const Node &) const =delete
Node & addNode(const std::string &name)
int id
Definition: parser.h:51
Edge(const Node &s, const std::string &trans, const Node &t)
Definition: parser.h:32
friend std::ostream & operator<<(std::ostream &os, const GFG &g)
Edge & operator=(const Edge &) const =delete
std::vector< std::unique_ptr< Node > > nodes
Definition: parser.h:67
GFG()
Definition: parser.h:57
std::string name
Definition: parser.h:52
std::vector< Edge > outEdges
Definition: parser.h:53
std::string transition
Definition: parser.h:40
const Node & target
Definition: parser.h:41
GFG & operator=(const GFG &) const =delete
const Edge & addEdge(Node &s, const std::string &transition, const Node &t)
const Node & source
Definition: parser.h:39
Definition: parser.h:31
Node(const std::string &n)
Definition: parser.h:45
Definition: parser.h:56