@q Copyright 2012-2022, 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 .@> @** The name parser for \ld\ term names. We take a lazy approach to the typeseting of term names for the \ld\ grammar by creating a dedicated parser for name processing. This way any pattern we notice can be quickly incorporated into our typesetting scheme. % We include the macros here since this file is intended to be % included by the documentation `aggregator' so putting bare \TeX\ % at the beginning of the file runs the risk of producing an error % of having \TeX\ material inside a \Cee\ section. \genericprettytokens namespace: ldsmall, tokens: {}, correction: lstokenset.sty, host: ldsmall; \iffalse \let\currentparsernamespace\parsernamespace \let\parsernamespace\ldsmallnamespace \let\hostparsernamespace\ldsmallnamespace \input lstokenset.sty \let\parsernamespace\currentparsernamespace \fi @(ld_num_parser.yy@>= @G Switch to generic mode. %{@> @ @=%} @> @ @= %union {@> @ @=} %{@> @ @=%} @> @ @= %% @> @ @= %% @g @ To put the new name parser to work, we need to initialize it. The initialization is done by the macros below. After the initialization has been completed, the switch command is replaced by the one that activates the new name parser. @= @G \genericparser name: ldnum, ptables: ld_num_tab.tex, ltables: ld_num_dfa.tex, tokens: {}, asetup: {}, dsetup: {}, rsetup: {}, optimization: {};% @g @ @= @G %token-table %debug %start hex_number @g @ @= @G %token DIGIT NYBBLE @g @*1 The name parser productions. These macros do a bit more than we need to typeset the term names. Their core is designed to treat suffixes and prefixes of a certain form in a special way. In addition, some productions were left in place from the original name parser in order to be able to refer to, say, \flex\ options in text. The inline action in one of the rules for \prodstyle{identifier\_string} was added to adjust the number and the position of the terms so that the appropriate action can be reused later for \prodstyle{qualified\_identifier\_string}. @= @G hex_number: DIGIT {} | DIGIT DIGIT {} | DIGIT DIGIT DIGIT {} | hex_number nybble {} ; nybble: DIGIT DIGIT DIGIT DIGIT {} ; @g @ @= @[TeX_( "/yy0{/the/yy(1)/the/yy(2)}/namechars/yyval" );@]@; @ @= @[TeX_( "/yy0{/the/yy(3)/the/yy(4)/nx/dotsp/nx/qual/the/yy(1)}/namechars/yyval" );@]@; @ @= @[TeX_( "/getfirst{/yy(1)}/to/toksa" );@]@; @[TeX_( "/getsecond{/yy(1)}/to/toksb" );@]@; @[TeX_( "/yy0{/nx/optstr{/the/toksa}{/the/toksb}}" );@]@; @ @= @[TeX_( "/getfirst{/yy(1)}/to/toksa" );@]@; @[TeX_( "/getsecond{/yy(1)}/to/toksb" );@]@; @[TeX_( "/yy0{/nx/idstr{/the/toksa}{/the/toksb}}" );@]@; @ @= @[TeX_( "/getfirst{/yy(2)}/to/toksa" );@]@; @[TeX_( "/getsecond{/yy(2)}/to/toksb" );@]@; @[TeX_( "/yy0{/nx/idstr{}{}}" );@]@; @ @= @[TeX_( "/getfirst{/yy(2)}/to/toksa" );@]@; @[TeX_( "/getsecond{/yy(2)}/to/toksb" );@]@; @[TeX_( "/yy0{/nx/chstr{/the/toksa}{/the/toksb}}" );@]@; @ @= @@; @ @= @[TeX_( "/getsecond{/yy(1)}/to/toksa" );@]@; @[TeX_( "/appendr/toksa{/noexpand/_}" );@]@; @[TeX_( "/getfirst{/yy(3)}/to/toksb" );@]@; @[TeX_( "/concat/toksa/toksb" );@]@; @[TeX_( "/getthird{/yy(1)}/to/toksb" );@]@; @[TeX_( "/appendr/toksb{/uscoreletter}" );@]@; @[TeX_( "/getsecond{/yy(3)}/to/toksc" );@]@; @[TeX_( "/concat/toksb/toksc" );@]@; @[TeX_( "/yy0{/nx/idstr{/the/toksa}{/the/toksb}}" );@]@; @ @= @ @= @[TeX_( "/yy0{/nx/dotsp/nx/sfxi/the/yy(1)}" );@]@; @ @= @[TeX_( "/yy0{/nx/dotsp/nx/sfxi/the/yy(2)}" );@]@; @ @= @[TeX_( "/yy0{/nx/dotsp/nx/qual/the/yy(2)}" );@]@; @ @= @[TeX_( "/yy0{/nx/dotsp/the/yy(2)}" );@]@; @ @= @@; @ @= @[TeX_( "/yy0{/nx/sfxn/the/yy(1)}" );@]@; @ @= @[TeX_( "/yy0{/nx/sfxi/the/yy(1)}" );@]@; @ @= @[TeX_( "/yy0{/the/yy(1)/nx/dotsp}" );@]@; @ @= @[TeX_( "/yy0{/the/yy(1)/nx/sfxi/the/yy(2)}" );@]@; @ @= @[TeX_( "/yy0{/the/yy(1)/nx/sfxn/the/yy(2)}" );@]@; @ @= @[TeX_( "/yy0{/the/yy(1)/nx/qual/the/yy(2)}" );@]@; @ @= @[TeX_( "/yy0{/nx/qual/the/yy(1)}" );@]@; @ \Cee\ preamble. In this case, there are no `real' actions that our grammar performs, only \TeX\ output, so this section is empty. @= @ \Cee\ postamble. It is tricky to insert function definitions that use \bison's internal types, as they have to be inserted in a place that is aware of the internal definitions but before said definitions are used. @= @ Union of types. @= @*1 The name scanner. %\checktabletrue @(ld_num_lexer.ll@>= @G @> @ @= %{@> @ @=%} @> @ @= %% @> @ @= %% @O void define_all_states( void ) { @@; } @o @g @ \ifbotstrapmode\yyskipparsetrue\fi@= @@; @G aletter [a-zA-Z] wc ([^\\\'\"-]{-}[_a-zA-Z0-9]|\\.) id ({aletter}|{aletter}({aletter}|[0-9])*{aletter}) int [0-9]+ @g @ @= #define _register_name( name ) @[Define_State( #name, name )@] /* nothing for now */ #undef _register_name @ Strings and characters in directives/rules. @= @G(fs1) %x SC_ESCAPED_STRING SC_ESCAPED_CHARACTER @g @ @= #include #include @ \yyskipparsefalse@= @G(fs1) %option bison-bridge %option noyywrap nounput noinput reentrant %option noyy_top_state %option debug %option stack %option outfile="ld_num_lexer.c" @g @ @= @@; @@; @ White space skipping. \traceparserstatestrue \tracestackstrue \tracerulestrue \traceactionstrue \tracelookaheadtrue \traceparseresultstrue \tracebadcharstrue \yyflexdebugtrue % %\prodstyle{abc123} % \traceparserstatesfalse \tracestacksfalse \tracerulesfalse \traceactionsfalse \tracelookaheadfalse \traceparseresultsfalse \tracebadcharsfalse \yyflexdebugfalse % %\yyskipparsetrue @= @G [ \f\n\t\v] {@> @[TeX_( "/yylexnext" );@]@=} @g @ This collection of regular expressions might seem redundant, and in its present state, it certainly is. However, if later on the typesetting style for some of the keywords would need to be adjusted, such changes would be easy to implement, since the template is already here. %\yyskipparsefalse % this is not necessary @= @G "%"({aletter}|[0-9]|[-_]|"%"|[<>])+ {@> @[TeX_( "/yylexreturnval{PERCENT_IDENTIFIER}" );@]@=} "opt" {@> @[TeX_( "/yylexreturnval{OPTIONAL}" );@]@=} "na" {@> @[TeX_( "/yylexreturnval{NO_ATTR}" );@]@=} "ext" {@> @[TeX_( "/yylexreturnval{EXTENDED}" );@]@=} [<>._\'] {@> @[TeX_( "/yylexreturnchar" );@]@=} {wc} {@> @[TeX_( "/yylexreturnval{WILDCARD}" );@]@=} {id} {@> @[@@]@=} {int} {@> @[TeX_( "/yylexreturnval{INTEGER}" );@]@=} "\"" {@> @[TeX_( "/yylexnext" );@]@=} . {@> @[@@]@=} @g @ @= @[TeX_( "/yylexreturnval{IDENTIFIER}" );@]@; @ \let\hostparsernamespace\ldnamespace @= @[TeX_( "/iftracebadchars" );@]@; @[TeX_( " /yycomplain{invalid character(s): /the/yytext}" );@]@; @[TeX_( "/fi" );@]@; @[TeX_( "/yyerrterminate" );@]@;