~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to lefty/dot2l/dotparse.y

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%{
 
2
#include <stdio.h>
 
3
typedef void *Tobj;
 
4
#include "dot2l.h"
 
5
 
 
6
static char portstr[SMALLBUF];
 
7
%}
 
8
 
 
9
%union {
 
10
    long i;
 
11
    char *s;
 
12
    void *o;
 
13
}
 
14
 
 
15
%token <i> T_graph T_digraph T_strict
 
16
%token <i> T_node T_edge T_edgeop
 
17
%token <s> T_id
 
18
%type <o> node_name node_id subg_stmt
 
19
%left <i> T_subgraph /* to eliminate subgraph hdr shift/reduce conflict */
 
20
%left '{'
 
21
%%
 
22
 
 
23
file: graph_type T_id
 
24
    { D2Lbegin ($2); free ($2); }
 
25
  '{' stmt_list '}'
 
26
    { D2Lend (); }
 
27
| error
 
28
    { D2Labort (); }
 
29
| /* empty*/
 
30
    { D2Labort (); }
 
31
;
 
32
 
 
33
graph_type: T_graph /* safe to change graph type/name before contents appear */
 
34
    { gtype = "graph"; etype = "--"; }
 
35
| T_strict T_graph
 
36
    { gtype = "strict graph"; etype = "--"; }
 
37
| T_digraph
 
38
    { gtype = "digraph"; etype = "->"; }
 
39
| T_strict T_digraph
 
40
    { gtype = "strict digraph"; etype = "->"; }
 
41
;
 
42
 
 
43
stmt_list: stmt_list1
 
44
| /* empty */
 
45
;
 
46
 
 
47
stmt_list1: stmt
 
48
| stmt_list1 stmt
 
49
;
 
50
 
 
51
stmt: stmt1
 
52
| stmt1 ';'
 
53
;
 
54
 
 
55
stmt1: node_stmt /* create nodes and set attributes */
 
56
| edge_stmt /* create edges and set attributes */
 
57
| attr_stmt /* reset value of attributes */
 
58
| subg_stmt {}
 
59
;
 
60
 
 
61
node_stmt: node_id { attrclass = NODE; portstr[0] = '\000'; }
 
62
    opt_attr_list { attrclass = GRAPH; }
 
63
;
 
64
 
 
65
node_id: node_name node_port
 
66
    { $$ = $1; }
 
67
;
 
68
 
 
69
node_name: T_id
 
70
    { $$ = D2Linsertnode ($1); free ($1); }
 
71
;
 
72
 
 
73
edge_stmt: node_id
 
74
    { D2Lbeginedge (NODE, $1, portstr); portstr[0] = '\000'; }
 
75
  edgeRHS
 
76
    { attrclass = EDGE; }
 
77
  opt_attr_list
 
78
    { D2Lendedge (); attrclass = GRAPH; }
 
79
| subg_stmt
 
80
    { D2Lbeginedge (GRAPH, $1, ""); }
 
81
  edgeRHS
 
82
    { attrclass = EDGE; }
 
83
  opt_attr_list
 
84
    { D2Lendedge (); attrclass = GRAPH; }
 
85
;
 
86
 
 
87
edgeRHS: T_edgeop node_id
 
88
    { D2Lmidedge (NODE, $2, portstr); portstr[0] = '\000'; }
 
89
| T_edgeop node_id
 
90
    { D2Lmidedge (NODE, $2, portstr); portstr[0] = '\000'; } edgeRHS
 
91
| T_edgeop subg_stmt
 
92
    { D2Lmidedge (GRAPH, $2, ""); portstr[0] = '\000'; }
 
93
| T_edgeop subg_stmt
 
94
    { D2Lmidedge (GRAPH, $2, ""); portstr[0] = '\000'; } edgeRHS
 
95
;
 
96
 
 
97
node_port: /* empty */
 
98
| port_location
 
99
| port_angle
 
100
| port_angle port_location
 
101
| port_location port_angle
 
102
;
 
103
 
 
104
port_location: ':' T_id
 
105
    {
 
106
        strcat (portstr, $2); free ($2);
 
107
    }
 
108
| ':' '(' T_id ',' T_id ')'
 
109
    {
 
110
        strcat (portstr, "("); strcat (portstr, $3);
 
111
        strcat (portstr, ","); strcat (portstr, $5);
 
112
        strcat (portstr, ")");
 
113
        free ($3), free ($5);
 
114
    }
 
115
;
 
116
 
 
117
port_angle: '@' T_id
 
118
    {
 
119
        strcat (portstr, "@"); strcat (portstr, $2); free ($2);
 
120
    }
 
121
;
 
122
 
 
123
attr_stmt: attr_class
 
124
    { inattrstmt = TRUE; }
 
125
  attr_list
 
126
    { attrclass = GRAPH; inattrstmt = FALSE; }
 
127
| attr_set
 
128
    { attrclass = GRAPH; }
 
129
;
 
130
 
 
131
attr_class: T_graph
 
132
    { attrclass = GRAPH; }
 
133
| T_node
 
134
    { attrclass = NODE; }
 
135
| T_edge
 
136
    { attrclass = EDGE; }
 
137
;
 
138
 
 
139
opt_attr_list: rec_attr_list
 
140
;
 
141
 
 
142
rec_attr_list: rec_attr_list attr_list
 
143
| /* empty */
 
144
;
 
145
 
 
146
attr_list: '[' inside_attr_list ']'
 
147
;
 
148
 
 
149
inside_attr_list: attr_set optcomma inside_attr_list
 
150
| /* empty */
 
151
;
 
152
 
 
153
attr_set: T_id '=' T_id
 
154
    { D2Lsetattr ($1, $3); free ($1); free ($3); }
 
155
;
 
156
 
 
157
optcomma: /* empty */
 
158
| ','
 
159
;
 
160
 
 
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 (); }
 
167
;
 
168
 
 
169
subg_hdr: T_subgraph T_id
 
170
    { D2Lpushgraph ($2); free ($2); }
 
171
;