1 /***********************************************************
2 Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
3 Amsterdam, The Netherlands.
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI not be used in advertising or publicity pertaining to
13 distribution of the software without specific, written prior permission.
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
25 /* Print a bunch of C initializers that represent a grammar */
27 #include "pgenheaders.h"
31 static void printarcs
PROTO((int, dfa
*, FILE *));
32 static void printstates
PROTO((grammar
*, FILE *));
33 static void printdfas
PROTO((grammar
*, FILE *));
34 static void printlabels
PROTO((grammar
*, FILE *));
41 fprintf(fp
, "#include \"pgenheaders.h\"\n");
42 fprintf(fp
, "#include \"grammar.h\"\n");
45 fprintf(fp
, "grammar gram = {\n");
46 fprintf(fp
, "\t%d,\n", g
->g_ndfas
);
47 fprintf(fp
, "\tdfas,\n");
48 fprintf(fp
, "\t{%d, labels},\n", g
->g_ll
.ll_nlabels
);
49 fprintf(fp
, "\t%d\n", g
->g_start
);
54 printnonterminals(g
, fp
)
62 for (i
= g
->g_ndfas
; --i
>= 0; d
++)
63 fprintf(fp
, "#define %s %d\n", d
->d_name
, d
->d_type
);
77 for (j
= 0; j
< d
->d_nstates
; j
++, s
++) {
78 fprintf(fp
, "static arc arcs_%d_%d[%d] = {\n",
81 for (k
= 0; k
< s
->s_narcs
; k
++, a
++)
82 fprintf(fp
, "\t{%d, %d},\n", a
->a_lbl
, a
->a_arrow
);
97 for (i
= 0; i
< g
->g_ndfas
; i
++, d
++) {
99 fprintf(fp
, "static state states_%d[%d] = {\n",
102 for (j
= 0; j
< d
->d_nstates
; j
++, s
++)
103 fprintf(fp
, "\t{%d, arcs_%d_%d},\n",
118 fprintf(fp
, "static dfa dfas[%d] = {\n", g
->g_ndfas
);
120 for (i
= 0; i
< g
->g_ndfas
; i
++, d
++) {
121 fprintf(fp
, "\t{%d, \"%s\", %d, %d, states_%d,\n",
122 d
->d_type
, d
->d_name
, d
->d_initial
, d
->d_nstates
, i
);
123 fprintf(fp
, "\t \"");
124 for (j
= 0; j
< NBYTES(g
->g_ll
.ll_nlabels
); j
++)
125 fprintf(fp
, "\\%03o", d
->d_first
[j
] & 0xff);
126 fprintf(fp
, "\"},\n");
139 fprintf(fp
, "static label labels[%d] = {\n", g
->g_ll
.ll_nlabels
);
140 l
= g
->g_ll
.ll_label
;
141 for (i
= g
->g_ll
.ll_nlabels
; --i
>= 0; l
++) {
142 if (l
->lb_str
== NULL
)
143 fprintf(fp
, "\t{%d, 0},\n", l
->lb_type
);
145 fprintf(fp
, "\t{%d, \"%s\"},\n",
146 l
->lb_type
, l
->lb_str
);