diff options
Diffstat (limited to 'support/splint/examples/ld/ldlex.w')
-rw-r--r-- | support/splint/examples/ld/ldlex.w | 73 |
1 files changed, 34 insertions, 39 deletions
diff --git a/support/splint/examples/ld/ldlex.w b/support/splint/examples/ld/ldlex.w index 9d1c256e62..2312fd1027 100644 --- a/support/splint/examples/ld/ldlex.w +++ b/support/splint/examples/ld/ldlex.w @@ -1,4 +1,4 @@ -@q Copyright 2012-2015 Alexander Shibakov@> +@q Copyright 2012-2020 Alexander Shibakov@> @q Copyright 2002-2014 Free Software Foundation, Inc.@> @q This file is part of SPLinT@> @@ -16,9 +16,9 @@ @q along with SPLinT. If not, see <http://www.gnu.org/licenses/>.@> @** The lexer. -\ifx\parsernamespace\UNDEFINED +\ifbootstrapmode \input ldman.sty - \input limbo.sty + \modebootstrap \input dcols.sty \setupfootnotes \def\MRI{} @@ -65,13 +65,13 @@ void define_all_states( void ) { #include "ldl_states.h" #undef _register_name -@ \yyskipparsetrue The character classes used by the scanner as well as +@ The character classes used by the scanner as well as lexer state declarations have been put in the definitions section of the input file. No attempt has been made to clean up the definitions of the character classes. @<\ld\ lexer definitions@>= @<\ld\ lexer states@>@; -@G +@G(fs1) CMDFILENAMECHAR [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~] CMDFILENAMECHAR1 [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~] FILENAMECHAR1 [_a-zA-Z\/\.\\\$\_\~] @@ -93,7 +93,6 @@ very rarely used explicitly. Keeping all the state declarations in the same section simplifies the job of the \locallink{bootstrapstates}bootstrap parser\endlink, as well. \ifbootstrapmode\immediate\openout\stlist=ldl_states.h\fi -\yyskipparsefalse @<\ld\ lexer states@>= @G %s SCRIPT @@ -109,8 +108,8 @@ same section simplifies the job of the @*1 Macros for lexer functions. The \locallink{pingpong}state switching\endlink\ `ping-pong' between the lexer and the parser aside, the \ld\ lexer is very traditional. One implementation choice -deserving some attenion is the treatment of comments by the lexer. The -difficulty of implementing \Cee\ style comment lexing using regular +deserving some attention is the treatment of comments. The +difficulty of implementing \Cee\ style comment scanning using regular expressions is well-known so an often used alternative is a special function that simply skips to the end of the comment. This is exactly what the \ld\ lexer does with an aptly named |comment()| @@ -119,7 +118,7 @@ the same purpose. For the curious, here is a \flex\ style regular expression defining \Cee\ comments\footnote{Taken from W.~McKeeman's site at \url{http://www.cs.dartmouth.edu/~mckeeman/cs118/assignments/comment.html} -and adopted to \flex\ syntax.}: +and adapted to \flex\ syntax.}: $$ \hbox{\.{"/*" ("/"\yl[\^*/]\yl"*"+[\^*/])* "*"+ "/"}} $$ @@ -136,7 +135,7 @@ setup of the lexer and enters a `|while| loop' in the input routine. This macro is a reasonable approximation of the functionality provided by |comment()|. @<Additional macros for the \ld\ lexer/parser@>= -@G +@G(t) \def\ldcomment{% \let\oldyyreturn\yyreturn \let\oldyylextail\yylextail @@ -147,7 +146,7 @@ provided by |comment()|. @ The rest of the |while| loop merely waits for the \.{*/} combination. @<Additional macros for the \ld\ lexer/parser@>= -@G +@G(t) \def\ldcommentskipchars{% \ifnum\yycp@@=`* \yybreak{\let\yyreturn\ldcommentseekslash\yyinput}% @@ -174,7 +173,7 @@ provided by |comment()|. @ Once the end of the comment has been found, resume lexing the input stream. @<Additional macros for the \ld\ lexer/parser@>= -@G +@G(t) \def\ldcommentfinish{% \let\yyreturn\oldyyreturn \let\yylextail\oldyylextail @@ -195,7 +194,7 @@ an `optimized' lexer the restriction is even weaker, namely, \.{\\yylextail} merely has to be absent in the portion of the action following \.{\\ldcomment}). @<Additional macros for the \ld\ lexer/parser@>= -@G +@G(t) \def\ldcomment#1\yylextail{% \let\oldyyreturn\yyreturn \def\yylexcontinuation{#1\yylextail}% @@ -224,7 +223,7 @@ appropriate end of file marker for the lexer (a double has to be cleaned up from the input stream (the lexer is designed to leave it intact). The macros below are designed to handle this assignment. @<Additional macros for the \ld\ lexer/parser@>= -@G +@G(t) \def\ldcleanyyeof#1\yylextail{% \let\oldyyinput\yyinput \def\yyinput\yyeof\yyeof{\let\yyinput\oldyyinput#1\yylextail}% @@ -240,11 +239,11 @@ sections that follow. Variable names and algebraic operations come first. @<\ld\ token regular expressions@>= -@G +@G(fs2) <BOTH,SCRIPT,EXPRESSION,VERS_START,VERS_NODE,VERS_SCRIPT>"/*" {@> @[TeX_( "/ldcomment/yylexnext" );@]@=} <DEFSYMEXP>"-" {@> @[TeX_( "/yylexreturnchar" );@]@=} <DEFSYMEXP>"+" {@> @[TeX_( "/yylexreturnchar" );@]@=} -<DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}* {@> @[TeX_( "/yylexreturnval{NAME}" );@]@=} +<DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}* {@> @[TeX_( "/yylexreturnsym{NAME}" );@]@=} <DEFSYMEXP>"=" {@> @[TeX_( "/yylexreturnchar" );@]@=} <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {@> @<Return an absolute hex constant@> @=} <MRI,EXPRESSION>([0-9A-Fa-f])+(H|h|X|x|B|b|O|o|D|d) {@> @<Return a constant in a specific radix@>@=} @@ -294,7 +293,7 @@ Variable names and algebraic operations come first. inside script files. File name syntax is listed as well, along with miscellanea such as whitespace and version symbols. @<\ld\ token regular expressions@>= -@G +@G(fs2) <BOTH,SCRIPT>"MEMORY" {@> @[TeX_( "/yylexreturnptr{MEMORY}" );@]@=} <BOTH,SCRIPT>"REGION_ALIAS" {@> @[TeX_( "/yylexreturnptr{REGION_ALIAS}" );@]@=} <BOTH,SCRIPT>"LD_FEATURE" {@> @[TeX_( "/yylexreturnptr{LD_FEATURE}" );@]@=} @@ -420,11 +419,11 @@ miscellanea such as whitespace and version symbols. <MRI>"list".* {@> @[TeX_( "/yylexreturnptr{LIST}" );@]@=} <MRI>"sect" {@> @[TeX_( "/yylexreturnptr{SECT}" );@]@=} <EXPRESSION,BOTH,SCRIPT,MRI>"absolute" {@> @[TeX_( "/yylexreturnptr{ABSOLUTE}" );@]@=} -<MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* {@> @[TeX_( "/yylexreturnval{NAME}" );@]@=} -<BOTH>{FILENAMECHAR1}{FILENAMECHAR}* {@> @[TeX_( "/yylexreturnval{NAME}" );@]@=} -<BOTH>"-l"{FILENAMECHAR}+ {@> @[TeX_( "/yylexreturnval{NAME}" );@]@=} -<EXPRESSION>{FILENAMECHAR1}{NOCFILENAMECHAR}* {@> @[TeX_( "/yylexreturnval{NAME}" );@]@=} -<EXPRESSION>"-l"{NOCFILENAMECHAR}+ {@> @[TeX_( "/yylexreturnval{NAME}" );@]@=} +<MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* {@> @[TeX_( "/yylexreturnsym{NAME}" );@]@=} +<BOTH>{FILENAMECHAR1}{FILENAMECHAR}* {@> @[TeX_( "/yylexreturnsym{NAME}" );@]@=} +<BOTH>"-l"{FILENAMECHAR}+ {@> @[TeX_( "/yylexreturnsym{NAME}" );@]@=} +<EXPRESSION>{FILENAMECHAR1}{NOCFILENAMECHAR}* {@> @[TeX_( "/yylexreturnsym{NAME}" );@]@=} +<EXPRESSION>"-l"{NOCFILENAMECHAR}+ {@> @[TeX_( "/yylexreturnsym{NAME}" );@]@=} <SCRIPT>{WILDCHAR}* {@> @[@<Skip a possible comment and return a \prodstyle{NAME}@>@]@=} <EXPRESSION,BOTH,SCRIPT,VERS_NODE>"\""[^\"]*"\"" {@> @[@<Return the \prodstyle{NAME} inside quotes@>@]@=} <BOTH,SCRIPT,EXPRESSION>"\n" {@> @[TeX_( "/yylexnext" );@]@=} @@ -457,7 +456,7 @@ macros are looking for a \.{\$} suffix while the contents of @[TeX_( "/yylexreturn{INT}" );@]@; @ @<Additional macros for the \ld\ lexer/parser@>= -@G +@G(t) @=\def\matchcomment@@#1/*#2\yyeof#3#4{%@>@; \yystringempty{#1}{#3}{#4}% } @@ -480,28 +479,28 @@ try again.} @<Skip a possible comment and return a \prodstyle{NAME}@>= @[TeX_( "/matchcomment/yytextpure" );@]@; @[TeX_( " {/yyless/tw@@/ldcomment}" );@]/*matched the beginning of a comment*/@; - @[TeX_( " {/yylexreturnval{NAME}}" );@]@; + @[TeX_( " {/yylexreturnsym{NAME}}" );@]@; @ {\it No matter the state, quotes give what's inside.} @<Return the \prodstyle{NAME} inside quotes@>= - @[TeX_( "/ldstripquotes/yylexreturnval{NAME}" );@]@; + @[TeX_( "/ldstripquotes/yylexreturnsym{NAME}" );@]@; @ @<Additional macros for the \ld\ lexer/parser@>= -@G +@G(t) \newcount\versnodenesting \newcount\includestackptr @g @ Some syntax specific to version scripts. @<\ld\ token regular expressions@>= -@G +@G(fs2) <VERS_SCRIPT>"{" {@> @[TeX_( "/yyBEGIN{VERS_NODE}/versnodenesting=/z@@/yylexreturnchar" );@]@=} <VERS_SCRIPT>"}" {@> @[TeX_( "/yylexreturnchar" );@]@=} <VERS_NODE>"{" {@> @[TeX_( "/advance/versnodenesting/@@ne /yylexreturnchar" );@]@=} -<VERS_NODE>"}" {@> @[TeX_( "/advance/versnodenesting/m@@ne" );@]@; - @> @[TeX_( "/ifnum/versnodenesting</z@@" );@]@; - @> @[TeX_( " /yyBEGIN{VERS_SCRIPT}" );@]@; - @> @[TeX_( "/fi" );@]@; +<VERS_NODE>"}" {@> @[TeX_( "/advance/versnodenesting/m@@ne" );@]@= + @> @[TeX_( "/ifnum/versnodenesting</z@@" );@]@= + @> @[TeX_( " /yyBEGIN{VERS_SCRIPT}" );@]@= + @> @[TeX_( "/fi" );@]@= @> @[TeX_( "/yylexreturnchar" );@]@=} <VERS_START,VERS_NODE,VERS_SCRIPT>[\n] {@> @[TeX_( "/yylexnext" );@]@=} <VERS_START,VERS_NODE,VERS_SCRIPT>#.* {@> @[TeX_( "/yylexnext" );@]@=} @@ -509,12 +508,8 @@ try again.} <<EOF>> {@> @[@<Process the end of (possibly included) file@>@]@=} -<SCRIPT,MRI,VERS_START,VERS_SCRIPT,VERS_NODE>. {@> @[TeX_( "/yycomplain{bad character `/the/yytext'" );@] - @> @[TeX_( " in script}" );@] - @> @[TeX_( "/yyerrterminate" );@]@=} -<EXPRESSION,DEFSYMEXP,BOTH>. {@> @[TeX_( "/yycomplain{bad character `/the/yytext'" );@] - @> @[TeX_( " in expression}" );@]@= - @> @[TeX_( "/yyerrterminate" );@]@=} +<SCRIPT,MRI,VERS_START,VERS_SCRIPT,VERS_NODE>. {@> @[TeX_( "/yyfatal{bad character `/the/yytext' in script}" );@]@=} +<EXPRESSION,DEFSYMEXP,BOTH>. {@> @[TeX_( "/yyfatal{bad character `/the/yytext' in expression}" );@]@=} @g @ @<Process the end of (possibly included) file@>= @@ -529,7 +524,7 @@ try again.} \namedspot{stateswitchers}Here are the long promised auxiliary macros for switching lexer states and handling file input. @<Additional macros for the \ld\ lexer/parser@>= -@G +@G(t) \def\ldlex@@script{\yypushstate{SCRIPT}} \def\ldlex@@mri@@script{\yypushstate{MRI}} \def\ldlex@@version@@script{\yypushstate{VERS_START}} @@ -541,7 +536,7 @@ macros for switching lexer states and handling file input. \def\ldfile@@open@@command@@file#1{% \advance\includestackptr\@@ne - \appendl\yytextseen{\noexpand\yyeof\noexpand\yyeof}% + \appendlnx\yytext@@seen{\yyeof\yyeof}% \yytextbackuptrue } |