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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
/* $Id: dotparse.y,v 1.3 2005/04/08 20:45:34 erg Exp $ $Revision: 1.3 $ */
/* vim:set shiftwidth=4 ts=8: */
/**********************************************************
* This software is part of the graphviz package *
* http://www.graphviz.org/ *
* *
* Copyright (c) 1994-2004 AT&T Corp. *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Corp. *
* *
* Information and Software Systems Research *
* AT&T Research, Florham Park NJ *
**********************************************************/
%{
#if _PACKAGE_ast
#include <ast.h>
#endif
#include <stdio.h>
typedef void *Tobj;
#include "config.h"
#include "dot2l.h"
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#include <string.h>
static char portstr[SMALLBUF];
extern void yyerror(const char *fmt, ...);
%}
%union {
long i;
char *s;
void *o;
}
%token <i> T_graph T_digraph T_strict
%token <i> T_node T_edge T_edgeop
%token <s> T_id
%type <o> node_name node_id subg_stmt
%left <i> T_subgraph /* to eliminate subgraph hdr shift/reduce conflict */
%left '{'
%%
file: graph_type T_id
{ D2Lbegin ($2); free ($2); }
'{' stmt_list '}'
{ D2Lend (); }
| error
{ D2Labort (); }
| /* empty*/
{ D2Labort (); }
;
graph_type: T_graph /* safe to change graph type/name before contents appear */
{ gtype = "graph"; etype = "--"; }
| T_strict T_graph
{ gtype = "strict graph"; etype = "--"; }
| T_digraph
{ gtype = "digraph"; etype = "->"; }
| T_strict T_digraph
{ gtype = "strict digraph"; etype = "->"; }
;
stmt_list: stmt_list1
| /* empty */
;
stmt_list1: stmt
| stmt_list1 stmt
;
stmt: stmt1
| stmt1 ';'
;
stmt1: node_stmt /* create nodes and set attributes */
| edge_stmt /* create edges and set attributes */
| attr_stmt /* reset value of attributes */
| subg_stmt {}
;
node_stmt: node_id { attrclass = NODE; portstr[0] = '\000'; }
opt_attr_list { attrclass = GRAPH; }
;
node_id: node_name node_port
{ $$ = $1; }
;
node_name: T_id
{ $$ = D2Linsertnode ($1); free ($1); }
;
edge_stmt: node_id
{ D2Lbeginedge (NODE, $1, portstr); portstr[0] = '\000'; }
edgeRHS
{ attrclass = EDGE; }
opt_attr_list
{ D2Lendedge (); attrclass = GRAPH; }
| subg_stmt
{ D2Lbeginedge (GRAPH, $1, ""); }
edgeRHS
{ attrclass = EDGE; }
opt_attr_list
{ D2Lendedge (); attrclass = GRAPH; }
;
edgeRHS: T_edgeop node_id
{ D2Lmidedge (NODE, $2, portstr); portstr[0] = '\000'; }
| T_edgeop node_id
{ D2Lmidedge (NODE, $2, portstr); portstr[0] = '\000'; } edgeRHS
| T_edgeop subg_stmt
{ D2Lmidedge (GRAPH, $2, ""); portstr[0] = '\000'; }
| T_edgeop subg_stmt
{ D2Lmidedge (GRAPH, $2, ""); portstr[0] = '\000'; } edgeRHS
;
node_port: /* empty */
| port_location
| port_angle
| port_angle port_location
| port_location port_angle
;
port_location: ':' T_id
{
strcat (portstr, $2); free ($2);
}
| ':' '(' T_id ',' T_id ')'
{
strcat (portstr, "("); strcat (portstr, $3);
strcat (portstr, ","); strcat (portstr, $5);
strcat (portstr, ")");
free ($3), free ($5);
}
;
port_angle: '@' T_id
{
strcat (portstr, "@"); strcat (portstr, $2); free ($2);
}
;
attr_stmt: attr_class
{ inattrstmt = TRUE; }
attr_list
{ attrclass = GRAPH; inattrstmt = FALSE; }
| attr_set
{ attrclass = GRAPH; }
;
attr_class: T_graph
{ attrclass = GRAPH; }
| T_node
{ attrclass = NODE; }
| T_edge
{ attrclass = EDGE; }
;
opt_attr_list: rec_attr_list
;
rec_attr_list: rec_attr_list attr_list
| /* empty */
;
attr_list: '[' inside_attr_list ']'
;
inside_attr_list: attr_set optcomma inside_attr_list
| /* empty */
;
attr_set: T_id '=' T_id
{ D2Lsetattr ($1, $3); free ($1); free ($3); }
;
optcomma: /* empty */
| ','
;
subg_stmt: subg_hdr '{' stmt_list '}' %prec '{'
{ $$ = D2Lpopgraph (); }
| '{' { D2Lpushgraph (NULL); } stmt_list '}'
{ $$ = D2Lpopgraph (); }
| subg_hdr %prec T_subgraph
{ $$ = D2Lpopgraph (); }
;
subg_hdr: T_subgraph T_id
{ D2Lpushgraph ($2); free ($2); }
;
|