* Copyright (c) 1989 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)verbose.c 5.3 (Berkeley) 1/20/91";
static short *null_rules
;
null_rules
= (short *) MALLOC(nrules
*sizeof(short));
if (null_rules
== 0) no_space();
fprintf(verbose_file
, "\f\n");
for (i
= 0; i
< nstates
; i
++)
fprintf(verbose_file
, "\n\n%d terminals, %d nonterminals\n", ntokens
,
fprintf(verbose_file
, "%d grammar rules, %d states\n", nrules
- 2, nstates
);
fprintf(verbose_file
, "\n\nRules never reduced:\n");
for (i
= 3; i
< nrules
; ++i
)
fprintf(verbose_file
, "\t%s :", symbol_name
[rlhs
[i
]]);
for (p
= ritem
+ rrhs
[i
]; *p
>= 0; ++p
)
fprintf(verbose_file
, " %s", symbol_name
[*p
]);
fprintf(verbose_file
, " (%d)\n", i
- 2);
fprintf(verbose_file
, "\n\n");
for (i
= 0; i
< nstates
; i
++)
if (SRconflicts
[i
] || RRconflicts
[i
])
fprintf(verbose_file
, "State %d contains ", i
);
fprintf(verbose_file
, "1 shift/reduce conflict");
else if (SRconflicts
[i
] > 1)
fprintf(verbose_file
, "%d shift/reduce conflicts",
if (SRconflicts
[i
] && RRconflicts
[i
])
fprintf(verbose_file
, ", ");
fprintf(verbose_file
, "1 reduce/reduce conflict");
else if (RRconflicts
[i
] > 1)
fprintf(verbose_file
, "%d reduce/reduce conflicts",
fprintf(verbose_file
, ".\n");
fprintf(verbose_file
, "\n\n");
if (SRconflicts
[state
] || RRconflicts
[state
])
fprintf(verbose_file
, "state %d\n", state
);
register int symbol
, act
, number
;
for (p
= parser
[state
]; p
; p
= p
->next
)
if (p
->action_code
== SHIFT
)
else if (p
->suppressed
== 1)
if (state
== final_state
&& symbol
== 0)
fprintf(verbose_file
, "%d: shift/reduce conflict \
(accept, reduce %d) on $end\n", state
, p
->number
- 2);
fprintf(verbose_file
, "%d: shift/reduce conflict \
(shift %d, reduce %d) on %s\n", state
, number
, p
->number
- 2,
fprintf(verbose_file
, "%d: reduce/reduce conflict \
(reduce %d, reduce %d) on %s\n", state
, number
- 2, p
->number
- 2,
statep
= state_table
[state
];
sp1
= sp
= ritem
+ statep
->items
[i
];
fprintf(verbose_file
, "\t%s : ", symbol_name
[rlhs
[rule
]]);
for (sp
= ritem
+ rrhs
[rule
]; sp
< sp1
; sp
++)
fprintf(verbose_file
, "%s ", symbol_name
[*sp
]);
fprintf(verbose_file
, " %s", symbol_name
[*sp
]);
fprintf(verbose_file
, " (%d)\n", -2 - *sp
);
register int i
, j
, k
, nnulls
;
for (p
= parser
[state
]; p
; p
= p
->next
)
if (p
->action_code
== REDUCE
&&
(p
->suppressed
== 0 || p
->suppressed
== 1))
if (rrhs
[i
] + 1 == rrhs
[i
+1])
for (j
= 0; j
< nnulls
&& i
> null_rules
[j
]; ++j
)
else if (i
!= null_rules
[j
])
for (k
= nnulls
- 1; k
> j
; --k
)
null_rules
[k
] = null_rules
[k
-1];
for (i
= 0; i
< nnulls
; ++i
)
fprintf(verbose_file
, "\t%s : . (%d)\n", symbol_name
[rlhs
[j
]],
fprintf(verbose_file
, "\n");
if (stateno
== final_state
)
fprintf(verbose_file
, "\t$end accept\n");
print_reductions(p
, defred
[stateno
]);
sp
= shift_table
[stateno
];
if (sp
&& sp
->nshifts
> 0)
as
= accessing_symbol
[sp
->shift
[sp
->nshifts
- 1]];
for (q
= p
; q
; q
= q
->next
)
if (q
->suppressed
< 2 && q
->action_code
== SHIFT
)
if (p
->action_code
== SHIFT
&& p
->suppressed
== 0)
fprintf(verbose_file
, "\t%s shift %d\n",
symbol_name
[p
->symbol
], p
->number
);
print_reductions(p
, defred
)
for (q
= p
; q
; q
= q
->next
)
if (q
->action_code
== REDUCE
&& q
->suppressed
< 2)
fprintf(verbose_file
, "\t. error\n");
if (p
->action_code
== REDUCE
&& p
->number
!= defred
)
fprintf(verbose_file
, "\t%s reduce %d\n",
symbol_name
[p
->symbol
], k
);
fprintf(verbose_file
, "\t. reduce %d\n", defred
- 2);
register short *to_state
;
putc('\n', verbose_file
);
sp
= shift_table
[stateno
];
for (i
= 0; i
< sp
->nshifts
; ++i
)
as
= accessing_symbol
[k
];
fprintf(verbose_file
, "\t%s goto %d\n", symbol_name
[as
], k
);