@q Copyright 2012-2024, Alexander Shibakov@>
@q This file is part of SPLinT@>
@q SPLinT is free software: you can redistribute it and/or modify@>
@q it under the terms of the GNU General Public License as published by@>
@q the Free Software Foundation, either version 3 of the License, or@>
@q (at your option) any later version.@>
@q SPLinT is distributed in the hope that it will be useful,@>
@q but WITHOUT ANY WARRANTY; without even the implied warranty of@>
@q MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the@>
@q GNU General Public License for more details.@>
@q You should have received a copy of the GNU General Public License@>
@q along with SPLinT. If not, see .@>
@** Forcing \eatone{bison}\bison\ and \eatone{flex}\flex\ to output \TeX.
Instead of implementing a \bison\ (or \flex) `plugin' for outputting
\TeX\ parser, the code that follows produces a separate executable
that outputs all the required tables after the inclusion of an
ordinary \Cee\ parser produced by \bison\ (or a scanner produced by
\flex). The actions in both \bison\ parser and \flex\ scanner are
assumed to be merely |printf()| statements that output the `real'
\TeX\ actions. The code below simply cycles through all such actions to
output an `action switch' appropriate for use with \TeX. In every
other respect, the included parser or scanner can use any features
allowed in `real' parsers and scanners.
\def\action#1{\hbox{$\hbox{\\{action}}_{#1}$}}
\def\actionn{\action{n}}
@s action1 TeX
@s actionn TeX
@*1 Common routines.
The `top' level of the scanner and parser `drivers' is very similar,
and is therefore separated into a few sections that are common to both
drivers. The layout is fairly typical and follows a standard
`initialize-input-process-output-clean up' scheme. The logic behind each
section of the program will be explained in detail below.
The section below is called |@<\Cee\ postamble@>| because the output of
the tables can happen only after the \bison\ (or \flex) generated
\.{.c} file is included and all the data structures are known.
The actual `assembly' of each driver has to be done separately due to
some `singularities' of the \CWEB\ system and the design of this
software. All the essential routines are presented in the sections
below, though.
@<\Cee\ postamble@>=
@@;
int main( int argc, char **argv ) {
@@;
@@;
@@;
@@;
switch( mode ) {
@@;
default:
break;
}
fprintf( stderr, "Outputting tables and actions\n" );
if ( tables_out ) {
fprintf( stderr, " tables ... " );
@@;
fprintf( stderr, "actions ... " );
@