6
static char portstr[SMALLBUF];
15
%token <i> T_graph T_digraph T_strict
16
%token <i> T_node T_edge T_edgeop
18
%type <o> node_name node_id subg_stmt
19
%left <i> T_subgraph /* to eliminate subgraph hdr shift/reduce conflict */
24
{ D2Lbegin ($2); free ($2); }
33
graph_type: T_graph /* safe to change graph type/name before contents appear */
34
{ gtype = "graph"; etype = "--"; }
36
{ gtype = "strict graph"; etype = "--"; }
38
{ gtype = "digraph"; etype = "->"; }
40
{ gtype = "strict digraph"; etype = "->"; }
55
stmt1: node_stmt /* create nodes and set attributes */
56
| edge_stmt /* create edges and set attributes */
57
| attr_stmt /* reset value of attributes */
61
node_stmt: node_id { attrclass = NODE; portstr[0] = '\000'; }
62
opt_attr_list { attrclass = GRAPH; }
65
node_id: node_name node_port
70
{ $$ = D2Linsertnode ($1); free ($1); }
74
{ D2Lbeginedge (NODE, $1, portstr); portstr[0] = '\000'; }
78
{ D2Lendedge (); attrclass = GRAPH; }
80
{ D2Lbeginedge (GRAPH, $1, ""); }
84
{ D2Lendedge (); attrclass = GRAPH; }
87
edgeRHS: T_edgeop node_id
88
{ D2Lmidedge (NODE, $2, portstr); portstr[0] = '\000'; }
90
{ D2Lmidedge (NODE, $2, portstr); portstr[0] = '\000'; } edgeRHS
92
{ D2Lmidedge (GRAPH, $2, ""); portstr[0] = '\000'; }
94
{ D2Lmidedge (GRAPH, $2, ""); portstr[0] = '\000'; } edgeRHS
97
node_port: /* empty */
100
| port_angle port_location
101
| port_location port_angle
104
port_location: ':' T_id
106
strcat (portstr, $2); free ($2);
108
| ':' '(' T_id ',' T_id ')'
110
strcat (portstr, "("); strcat (portstr, $3);
111
strcat (portstr, ","); strcat (portstr, $5);
112
strcat (portstr, ")");
113
free ($3), free ($5);
119
strcat (portstr, "@"); strcat (portstr, $2); free ($2);
123
attr_stmt: attr_class
124
{ inattrstmt = TRUE; }
126
{ attrclass = GRAPH; inattrstmt = FALSE; }
128
{ attrclass = GRAPH; }
132
{ attrclass = GRAPH; }
134
{ attrclass = NODE; }
136
{ attrclass = EDGE; }
139
opt_attr_list: rec_attr_list
142
rec_attr_list: rec_attr_list attr_list
146
attr_list: '[' inside_attr_list ']'
149
inside_attr_list: attr_set optcomma inside_attr_list
153
attr_set: T_id '=' T_id
154
{ D2Lsetattr ($1, $3); free ($1); free ($3); }
157
optcomma: /* empty */
161
subg_stmt: subg_hdr '{' stmt_list '}' %prec '{'
162
{ $$ = D2Lpopgraph (); }
163
| '{' { D2Lpushgraph (NULL); } stmt_list '}'
164
{ $$ = D2Lpopgraph (); }
165
| subg_hdr %prec T_subgraph
166
{ $$ = D2Lpopgraph (); }
169
subg_hdr: T_subgraph T_id
170
{ D2Lpushgraph ($2); free ($2); }