-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree_gen.y
executable file
·63 lines (47 loc) · 1 KB
/
tree_gen.y
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
%{
#include "helper.h"
%}
%union {
int text_key;
Node *node;
}
%token EOL
%token <text_key> TEXT_KEY
%type <node> children
%type <node> node
%start tree
%%
children:
node {
// This should be the first child
$$ = $1;
}
| children node {
insert_sibling($1, $2);
// This should be the first child
$$ = $1;
}
;
node:
'[' TEXT_KEY TEXT_KEY ']' {
Node *lexical_node = new_node($3, nullptr, nullptr);
$$ = new_node($2, lexical_node, nullptr);
}
| '[' TEXT_KEY children ']' { $$ = new_node($2, $3, nullptr); }
;
tree: /* nothing */
| tree node EOL {
GVC_t *gvc = gvContext();
Agraph_t *g = agopen(strdup("g"), Agundirected, 0);
node_to_graphviz(g, $2);
gvLayout(gvc, g, "dot");
gvRender(gvc, g, "dot", stdout);
gvFreeLayout(gvc, g);
agclose(g);
gvFreeContext(gvc);
node_free($2);
graph_strings_free();
}
| tree EOL { }
;
%%