% Copyright 2012-2015, Alexander Shibakov
% This file is part of SPLinT
%
% SPLinT is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% SPLinT is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with SPLinT.  If not, see <http://www.gnu.org/licenses/>.

\def\optimization{5}

\input yycommon.sty % general routines for stack and array access
\input yymisc.sty   % helper macros (stack manipulation, table processing, value stack pointers)
\input yyinput.sty  % input functions
\input yyparse.sty  % parser machinery
\input flex.sty     % lexer functions
\input yyfaststack.sty % sped up stack access functions
\input yyboth.sty   % parser initialization, optimization
\input yyunion.sty

\genericparser 
    name: main, 
    ptables: cweb/byytab.tex, 
    ltables: cweb/lstab.tex, 
    tokens: {}, 
    asetup: \let\setflexstates\relax, 
    dsetup: {}, 
    rsetup: {},
    optimization: \optimizeall;%

\let\parsernamespace\mainnamespace
\let\yylexreturn\yylexreturnregular

% main section macro

\let\nx\noexpand

\expandafter\def\csname parserstack[b]\endcsname#1#2{%
    \basicparserinit\yyparse#1\yyeof\yyeof\endparseinput\endparse
    \ifyyparsefail % do nothing if parsing failed
        \yybreak{}%
    \else % Stage three, process the parsed table
        \yybreak{%
            \restorecslist{bootstrap}\yyunion
            \the\table\relax
        }%
    \yycontinue
}

\expandafter\def\csname parserstack[]\endcsname#1#2{%
    \basicparserinit\yyparse#1\yyeof\yyeof\endparseinput\endparse
    \ifyyparsefail % do nothing if parsing failed
        \yybreak{}%
    \else % Stage three, process the parsed table
        \yybreak{%
            \restorecslist{bootstrap}\yyunion
            \the\table\relax
        }%
    \yycontinue
}

\newwrite\stlist
