diff options
Diffstat (limited to 'support/splint/examples/ld/ldgram.w')
-rw-r--r-- | support/splint/examples/ld/ldgram.w | 108 |
1 files changed, 68 insertions, 40 deletions
diff --git a/support/splint/examples/ld/ldgram.w b/support/splint/examples/ld/ldgram.w index 5e7ff73a03..3671ee52ce 100644 --- a/support/splint/examples/ld/ldgram.w +++ b/support/splint/examples/ld/ldgram.w @@ -1,4 +1,4 @@ -@q Copyright 2012-2020 Alexander Shibakov@> +@q Copyright 2012-2022 Alexander Shibakov@> @q Copyright 2002-2014 Free Software Foundation, Inc.@> @q This file is part of SPLinT@> @@ -18,10 +18,12 @@ @** The parser. \ifbootstrapmode \def\tokendeffile{ldp.tok}% - \input ldman.sty + \input ldman.sty + \def\bstrapparser{dyytab.tex}% only the full or preamble parser would know how to + % parse grammar sections that mix \prodstyle{\%token} + % declarations with other \bison\ syntax + \def\bstraptokens{bo.tok}% token equivalences for the full lexer \modebootstrap - \input dcols.sty - \setupfootnotes \def\MRI{} \def\ld{} \fi @@ -76,8 +78,6 @@ is supplied by the \TeX\ macros in \.{ldman.sty}. @ @<Union of grammar parser types@>= @ @<\ld\ parser \Cee\ postamble@>= -#define YYPRINT(file, type, value) yyprint (file, type, value) - static void yyprint (FILE *file, int type, YYSTYPE value){} @ @<\ld\ parser productions@>= @<\GNU\ \ld\ script rules@>@; @@ -129,13 +129,13 @@ by the \ld\ parser are put in a single list. %left OROR ANDAND '|' '^' '&' EQ NE '<' '>' LE GE LSHIFT RSHIFT '+' '-' '*' '/' '%' '(' @g -@*1 Grammar rules, an overview. +@*1 Grammar rules, an overview. The first natural step in transforming an existing parser into a `parser stack' for pretty printing is to understand the `anatomy' of the grammar. Not every grammar is suitable for such a transformation and in almost every case, some modifications are needed. The parser and lexer implementation for \ld\ is not terrible although it does -have some idiosynchasies that could have been eliminated by a careful +have some idiosynchrasies that could have been eliminated by a careful grammar redesign. Instead of invasive rewriting of significant portions of the grammar, the approach taken here merely omits some rules and partitions the grammar into several subsets, each of which @@ -143,7 +143,7 @@ is supposed to handle a well defined logical section of an \ld\ script file. One example of a trick used by the \ld\ parser that is not appropriate for a -pretty printing grammar implements a way of handling the choice of the +pretty printing grammar is the way the original parser handles the choice of the format of an input file. After a command line option that selects the input format has been read (or the format has been determined using some other method), the first token output by the lexer branches the @@ -219,12 +219,14 @@ defsym_expr: @ {\it Syntax within an \MRI\ script file}\footnote{As explained at the beginning of this chapter, the text in {\it italics\/} was taken from -the original comments by \ld\ parser and lexer programmers.}. The parser for typesetting +the original comments by the \ld\ parser and lexer programmers.}. The parser for typesetting is only intended to process \GNU\ \ld\ scripts and does not concern itself with any additional compatibility modes. For this reason, all support for \MRI\ style scripts has been omitted. One use for the section below is a small demonstration of the formatting tools that change the output of the \bison\ parser. +%\checktabletrue +%\tracingliststrue @<\MRI\ style script rules@>= @G @t}\vb{\inline\flatten}{@> @@ -315,6 +317,8 @@ casesymlist: @ {\it Parsed as expressions so that commas separate entries.} The core of the parser consists of productions describing \GNU\ \ld\ linker scripts. The first rule is common to both \MRI\ and \GNU\ formats. +\checktablefalse +\tracinglistsfalse @<\GNU\ \ld\ script rules@>= @G extern_name_list: @@ -435,7 +439,7 @@ sections: sec_or_group_p1: sec_or_group_p1 section {@>@<Add the next section chunk@>@=} - | sec_or_group_p1 statement_anywhere {@>@<Add the next section chunk@>@=} + | sec_or_group_p1 statement_anywhere {@>@<Add the next section statement@>@=} | {@>@[TeX_( "/yy0{}" );@]@=} ; @@ -451,10 +455,20 @@ statement_anywhere: @[TeX_( "/yy0{/nx/ldinsertcweb/the/yy(1){sect}{/nx/ldsections{/the/yy(3)/nx/ldsectionstash/the/yy(4)}}}" );@] @ @<Add the next section chunk@>= - @[TeX_( "/getsecond{/yy(2)}/to/tokse/getthird{/yy(2)}/to/toksf" );@]@; - @[TeX_( "/getfourth{/yy(2)}/to/toksg/getfifth{/yy(2)}/to/toksh" );@]@; - @[TeXb( "/yytoksempty{/yy(1)}{/yy0{/nx/ldsectionstash{/the/tokse}{/the/toksf}/the/toksh}}" );@]@; - @[TeXfo( " {/yy0{/the/yy(1)/nx/ldsectionseparator{/the/tokse}{/the/toksf}/the/toksh}}" );@]@; + @[TeX_( "/yytoksempty{/yy(2)}{/yy0{/the/yy(1)}}{" );@]@; + @[TeX_( " /getsecond{/yy(2)}/to/tokse/getthird{/yy(2)}/to/toksf" );@]@; + @[TeX_( " /getfourth{/yy(2)}/to/toksg/getfifth{/yy(2)}/to/toksh" );@]@; + @[TeXb( " /yytoksempty{/yy(1)}{/yy0{/nx/ldsectionstash{/the/tokse}{/the/toksf}/the/toksh}}" );@]@; + @[TeXa( " {/yy0{/the/yy(1)/nx/ldsectionseparator{/the/tokse}{/the/toksf}/the/toksh}}" );@]@; + @[TeXfo( "}" );@]@; + +@ @<Add the next section statement@>= + @[TeX_( "/yytoksempty{/yy(2)}{/yy0{/the/yy(1)}}{" );@]@; + @[TeX_( " /getsecond{/yy(2)}/to/tokse/getthird{/yy(2)}/to/toksf" );@]@; + @[TeX_( " /getfourth{/yy(2)}/to/toksg/getfifth{/yy(2)}/to/toksh" );@]@; + @[TeXb( " /yytoksempty{/yy(1)}{/yy0{/nx/ldsectionstash{/the/tokse}{/the/toksf}/nx/ldfreestmt{/the/toksh}}}" );@]@; + @[TeXa( " {/yy0{/the/yy(1)/nx/ldsectionseparator{/the/tokse}{/the/toksf}/nx/ldfreestmt{/the/toksh}}}" );@]@; + @[TeXfo( "}" );@]@; @ @<Form an \prodstyle{ENTRY} statement@>= @[TeX_( "/yy0{/nx/ldinsertcweb/the/yy(1){stmt}{/nx/ldstatement{/nx/ldentry{/nx/ldregexp{/the/yy(3)}}}}}" );@] @@ -631,14 +645,14 @@ length: | SHORT {} | BYTE {} ; - +@t}\vb{\resetf\inline}{@> fill_exp: mustbe_exp {@>@<Carry on@>@=} ; - +@t}\vb{\flatten}{@> fill_opt: - '=' fill_exp {@>@[TeX_( "/yy0{/noexpand/ldfill{/the/yy(2)}}" );@]@=} - | {@>@[TeX_( "/yy0{}" );@]@=} + {@>@[TeX_( "/yy0{}" );@]@=} + | '=' fill_exp {@>@[TeX_( "/yy0{/noexpand/ldfill{/the/yy(2)}}" );@]@=} ; @t}\vb{\resetf}{@> @@ -710,9 +724,7 @@ memory_spec_list: memory_spec: NAME {} - attributes_opt ':' - origin_spec -@t}\vb{\breakline}{@> + attributes_opt ':' origin_spec opt_comma length_spec {@>@<Declare a named memory region@>@=} | INCLUDE filename {@>@<Peek at a file@>@=} memory_spec_list_opt END {@>@<Close the file@>@=} @@ -759,8 +771,8 @@ attributes_list: ; attributes_string: - NAME {@>@[TeX_( "/yy0{/noexpand/ldattributes{/the/yy(1)}}" );@]@=} - | '!' NAME {@>@[TeX_( "/yy0{/noexpand/ldattributesneg{/the/yy(2)}}" );@]@=} + NAME {@>@[TeX_( "/yy0{/noexpand/ldattrstring/the/yy(1)}" );@]@=} + | '!' NAME {@>@[TeX_( "/yy0{/noexpand/ldattrstringneg/the/yy(2)}" );@]@=} ; startup: @@ -812,7 +824,7 @@ expressions out of simpler chunks and basic building blocks tied together by algebraic operations. @<Grammar rules@>= @G -exp : +exp: '-' exp %prec UNARY {@>@[TeX_( "/yy0{{-/the/yy(2)}}" );@]@=} | '(' exp ')' {@>@[TeX_( "/yy0{(/the/yy(2))}" );@]@=} | NEXT '(' exp ')' %prec UNARY {@>@[TeX_( "/yy0{/hbox{/nx/ssf next}(/the/yy(3))}" );@]@=} @@ -844,28 +856,28 @@ exp : @<Grammar rules@>= @G exp : - DEFINED '(' NAME ')' {} - | INT {} + DEFINED '(' NAME ')' {@>@[TeX_( "/def/ldfuncname{defined}" );@]@<Apply a function to a name@>@=} + | INT {@>@<Carry on@>@=} | SIZEOF_HEADERS {} - | ALIGNOF '(' NAME ')' {} - | SIZEOF '(' NAME ')' {} - | ADDR '(' NAME ')' {} - | LOADADDR '(' NAME ')' {} - | CONSTANT '(' NAME ')' {} - | ABSOLUTE '(' exp ')' {} + | ALIGNOF '(' NAME ')' {@>@[TeX_( "/def/ldfuncname{alignof}" );@]@<Apply a function to a name@>@=} + | SIZEOF '(' NAME ')' {@>@[TeX_( "/def/ldfuncname{sizeof}" );@]@<Apply a function to a name@>@=} + | ADDR '(' NAME ')' {@>@[TeX_( "/def/ldfuncname{addr}" );@]@<Apply a function to a name@>@=} + | LOADADDR '(' NAME ')' {@>@[TeX_( "/def/ldfuncname{loadaddr}" );@]@<Apply a function to a name@>@=} + | CONSTANT '(' NAME ')' {@>@[TeX_( "/def/ldfuncname{constant}" );@]@<Apply a function to a name@>@=} + | ABSOLUTE '(' exp ')' {@>@[TeX_( "/yy0{/nx/mathop{/hbox{/nx/ssf absolute}}(/the/yy(3))}" );@]@=} | ALIGN_K '(' exp ')' {@>@[TeX_( "/yy0{/nx/mathop{/hbox{/nx/ssf align}}(/the/yy(3))}" );@]@=} | ALIGN_K '(' exp ',' exp ')' {} | DATA_SEGMENT_ALIGN '(' exp ',' exp ')' {} | DATA_SEGMENT_RELRO_END '(' exp ',' exp ')' {} | DATA_SEGMENT_END '(' exp ')' {} | SEGMENT_START '(' NAME ',' exp ')' {} - | BLOCK '(' exp ')' {} + | BLOCK '(' exp ')' {@>@[TeX_( "/yy0{/nx/mathop{/hbox{/nx/ssf block}}(/the/yy(3))}" );@]@=} | NAME {@>@[TeX_( "/yy0{/nx/ldregexp{/the/yy(1)}}" );@]@=} | MAX_K '(' exp ',' exp ')' {} | MIN_K '(' exp ',' exp ')' {} | ASSERT_K '(' exp ',' NAME ')' {} - | ORIGIN '(' NAME ')' {} - | LENGTH '(' NAME ')' {} + | ORIGIN '(' NAME ')' {@>@[TeX_( "/def/ldfuncname{origin}" );@]@<Apply a function to a name@>@=} + | LENGTH '(' NAME ')' {@>@[TeX_( "/def/ldfuncname{length}" );@]@<Apply a function to a name@>@=} | LOG2CEIL '(' exp ')' {} ; @g @@ -875,6 +887,9 @@ exp : @[TeXb( "/yy0{/hbox{/nx/ttl do }/xi(/the/yy(1))/hbox{ /nx/ttl where }" );@]@; @[TeXfo( " {/let/nx/{/nx/bigbracedel/nx/xi(x)=/nx/cases{/the/yy(5)& if /inmath{x=0}/cr/the/yy(3)& if /inmath{x/nx/not=0}}}}" );@]@; +@ @<Apply a function to a name@>= +@[TeX_( "/yy0{/nx/mathop{/hbox{/nx/ssf /ldfuncname}}(/nx/ldregexp{/the/yy(3))}}" );@] + @ @<Grammar rules@>= @G memspec_at_opt: @@ -966,6 +981,10 @@ section: @[TeXfo( " {{/the/yy(15)}{/the/yy(16)}{/the/yy(17)}{/the/yy(18)}}}}" );@]@; /*memory specifiers */ @ @<Record an overlay section@>= + @[TeXb( "/getfirst{/yy(1)}/to/toksa/getsecond{/yy(1)}/to/toksb" );@]@; + @[TeXf( "/yy0{/nx/ldinsertcweb{/the/toksa}{/the/toksb}{osect}{/nx/ldoverlay{/the/yy(3)}{/the/yy(4)}{/the/yy(5)}{/the/yy(6)}" );@]@; + @[TeXf( " {/the/yy(10)}" );@]@;/* sections */ + @[TeXfo( " {{/the/yy(13)}{/the/yy(14)}{/the/yy(15)}{/the/yy(16)}}}}" );@]@; /*memory specifiers, etc.*/ @ @<Grammar rules@>= @G @@ -999,8 +1018,8 @@ opt_exp_with_type: ; opt_exp_without_type: - exp ':' {} - | ':' {} + exp ':' {@>@[TeX_( "/yy0{/the/yy(1)}" );@]@=} + | ':' {@>@[TeX_( "/yy0{}" );@]@=} ; opt_nocrossrefs: @@ -1019,12 +1038,12 @@ phdr_opt: ; overlay_section: - + {@>@[TeX_( "/yy0{}" );@]@=} | overlay_section NAME {@>@[TeX_( "/ldlex@@script" );@]@=} '{' statement_list_opt '}' {@>@[TeX_( "/ldlex@@popstate/ldlex@@expression" );@]@=} phdr_opt fill_opt {@>@[TeX_( "/ldlex@@popstate" );@]@=} - opt_comma + opt_comma {@>@<Add a section to the overlay@>@=} ; @g @@ -1032,6 +1051,15 @@ overlay_section: @[TeXb( "/yytoksempty{/yy(1)}{/yy0{{/the/yy(3)}}}" );@]@; @[TeXao( "{/yy0{/the/yy(1)/noexpand/ldor{/the/yy(3)}}}" );@]@; +@ @<Add a section to the overlay@>= + @[TeXb( "/getthird{/yy(2)}/to/toksa/getfourth{/yy(2)}/to/toksb" );@]@;/* \prodstylens{name}{\ldnamespace} pointers */ + @[TeXf( "/getfifth{/yy(5)}/to/toksc" );@]@;/* \prodstylens{statement\_list\_opt}{\ldnamespace} contents */ + @[TeXf( "/yytoksempty{/yy(1)}{" );@]@; + @[TeXf( " /yy0{/nx/ldoverlaysection{/the/yy(2)}{/the/toksc}{/the/yy(8)}{/the/yy(9)}}" );@]@; + @[TeXf( "}{" );@]@; + @[TeXf( " /yy0{/the/yy(1)/nx/ldoverlaysection{/the/yy(2)}{/the/toksc}{/the/yy(8)}{/the/yy(9)}}" );@]@; + @[TeXfo( "}" );@]@; + @ @<Grammar rules@>= @G phdrs: |