summaryrefslogtreecommitdiff
path: root/support/splint/tex/yynested.sty
blob: 2a47c7959322cafc9a2d48dce3e2ea835e4a7b24 (plain)
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
% Copyright 2012-2020, 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/>.

% nested and boundary parsing macros

\newcount\boundarylower
\newcount\boundaryupper

% for parsers that use short setup

\boundaryupper-\@M
\boundarylower-\@M

\expandafter\def\expandafter\bisonparserdatainit\expandafter{%
    \bisonparserdatainit
    \boundaryupper-\@M
    \boundarylower-\@M
}

\def\inputboundarynext#1{%
    \yybytepure{ }\yycp@\boundarychar
    #1\getstackpointer\yyvsa\relax
    \yybyte\expandafter{\the\yybyte{#1}}%
    \yyreturn % inserting something here will effectively insert it into the input stream
}

\newcount\vspointer

% to use while debugging, the sequence below displays the contents of the value stack

\def\yyactione{%
    \message{value stack at: \getstackpointer\yyvsa}%
    \toksa\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter{\gettopofstackcs\yyvsa}%
    \toksb\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter{\getmidstackcs\yyvsa{0}}%
    \message{on the stack: \the\toksa, bottom: \the\toksb}%
    \message{the value: \the\yyval}%
    \message{rule: \the\yyn, length: \the\yylen}%
}

% this is an example of boundary processing

\def\yyaction{%
    \vspointer=\getstackpointer\yyvsa\relax
    \advance\vspointer-\yylen
    \ifnum\vspointer<\boundarylower 
        \ifnum\boundaryupper>-\@M % all nested tokens will be reduced
            \boundaryupper=-\@M
            \boundarylower=-\@M
            \message{reduction...(\the\vspointer: \the\yy(1).\the\yy(2).)}%
            \printrule\yyn
        \else % pre boundary tokens are getting reduced
            \boundarylower=\vspointer
            \advance\boundarylower\@ne
        \fi
    \else
        \ifnum\vspointer<\boundaryupper % top nested tokens will be reduced
            \boundaryupper=\vspointer
        \fi
    \fi
    \yysymswitch{\yyn}% setting symbol names
    \yybigswitch{\yyn}%
    \yysymcleanup{\yyn}% removing symbol names from the namespace
}