Here is an example of .fo code that is generating missing text.
Sorry for the length of it, but it is needed to show all the code
that is missing in the PDF. In the following paragraphs, the text
beginning "Upon an assignment statement..." through "...you can pass
that infor" appears on page 1 of a chapter. The entirety of the
fo:float appears on the top of page 2, followed by no other content
on the page. Page 3 begins with the text:
>>
All the expression-related rules in the parser grammar
Here is the FO:
<fo:block id="N100DD" space-after="6pt">
Upon an assignment statement, though, the recognizer must track
implicit local variable definitions by using the
<fo:inline font-family="Droid Sans"
font-size="90%">locals</fo:inline> <fo:inline
font-family="Droid Sans"
font-size="90%">HashMap</fo:inline>. Each
variable in a list of input expressions receives a unique local
variable number.
</fo:block>
<fo:float float="before">
<fo:block border-color="rgb(150, 150, 180)" border="2pt solid"
background-color="rgb(220, 220, 250)">
<fo:block background-color="rgb(150, 150, 180)"
padding-bottom="3pt" padding-top="3pt" font-size="90%"
font-weight="bold" space-after="0pt" space-before="0pt">
<fo:block margin-left="5pt" margin-right="5pt">Do You Ever
Need to Return a List of Templates?</fo:block>
</fo:block>
<fo:block-container margin-right="5pt" margin-left="5pt"
padding-top="3pt" font-size="85%">
<fo:block/>
<fo:block id="N100EC" space-after="6pt">
Some of you will see rules such as this:
</fo:block>
<fo:list-block provisional-distance-between-starts="0in"
space-after.maximum="10pt" space-after.optimum="8pt"
space-after.minimum="6pt" space-before.maximum="10pt"
space-before.optimum="6pt" space-before.minimum="6pt"
font-size="80%" font-family="Droid Sans Mono">
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false" text-align="start">prog : stat+
;</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
<fo:block id="N10104" space-after="6pt">
and question why <fo:inline font-family="Droid Sans"
font-size="90%">prog</fo:inline> should not return a list
of
templates. Remember that for translators in the generator
category,
you must literally specify what to emit for every input construct
even if it is just a list of input elements. The proper generated
output for <fo:inline font-family="Droid Sans"
font-size="90%">prog</fo:inline> is in fact a template that
represents a list of statements. For example, you might use
something akin to this:
</fo:block>
<fo:list-block provisional-distance-between-starts="0in"
space-after.maximum="10pt" space-after.optimum="8pt"
space-after.minimum="6pt" space-before.maximum="10pt"
space-before.optimum="6pt" space-before.minimum="6pt"
font-size="80%" font-family="Droid Sans Mono">
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false" text-align="start">prog :
(s+=stat)+ -> template(stats={$s}) <fo:inline
font-style="italic" color="rgb(25, 17,
144)">"<stats>"</fo:inline></fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</fo:block-container>
</fo:block>
</fo:float>
<fo:block id="N10125" space-after="6pt">
The expression rules are as before except for the addition of code
to
track the number of operations (to estimate stack size):
</fo:block>
<fo:block id="N1012B" space-after="6pt">
Once you have a parser grammar that builds the appropriate trees
and
computes the number of operations and <fo:inline
font-family="Droid Sans" font-size="90%">locals</fo:inline>
map, you can pass that information to the tree grammar. The tree
grammar will create a template for each subtree in order to emit
bytecodes. Start rule <fo:inline font-family="Droid Sans"
font-size="90%">prog</fo:inline>’s template return
value represents the template for the entire assembly file. The
grammar itself is identical to the <fo:inline
font-family="Droid Sans" font-size="90%">Eval</fo:inline>
tree
grammar from, but of course the actions
are different.
</fo:block>
<fo:block id="N10138" space-after="6pt">
Here is the start of the <fo:inline font-family="Droid Sans"
font-size="90%">Gen</fo:inline> tree grammar:
</fo:block>
<fo:block id="N10141" space-after="6pt">
The test rig pulls necessary data out of the parser after parsing
is
complete and passes it to the tree grammar via
<fo:inline font-family="Droid Sans"
font-size="90%">prog</fo:inline> rule parameters:
</fo:block>
<fo:block id="N1014A" space-after="6pt">
</fo:block>
<fo:block id="N1014E" space-after="6pt">
The <fo:inline font-family="Droid Sans"
font-size="90%">stat</fo:inline> rule creates an instance
of template
<fo:inline font-family="Droid Sans"
font-size="90%">exprStat</fo:inline> or <fo:inline
font-family="Droid Sans"
font-size="90%">assign</fo:inline>, depending
on which alternative matches:
</fo:block>
<fo:block color="rgb(120, 155, 125)" background="rgb(200, 235,
220)" font-weight="bold" font-size="80%" font-family="Myriad"
padding-left="0.3em" space-before.maximum="10pt"
space-before.optimum="6pt" space-before.minimum="6pt"
keep-with-next="always">
<fo:basic-link xmlns:exsl=
"http://exslt.org/common"
external-destination="url(
http://media.pragprog.com/titles/tpantlr2/code/templates/generator/2pass/Gen.g)">Download
templates/generator/2pass/Gen.g</fo:basic-link>
</fo:block>
<fo:list-block provisional-distance-between-starts="0in"
space-after.maximum="10pt" space-after.optimum="8pt"
space-after.minimum="6pt" space-before="0pt" font-size="80%"
font-family="Droid Sans Mono">
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false" text-align="start">stat: expr
-> exprStat(v={$expr.st},
descr={$expr.text})</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false" text-align="start"> |
^(<fo:inline font-style="italic" color="rgb(25, 17,
144)">'='</fo:inline> ID expr)</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false" text-align="start">
-> assign(id={$ID.text},</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false"
text-align="start">
descr={$text},</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false"
text-align="start">
varNum={locals.get($ID.text)},</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false"
text-align="start">
v={$expr.st})</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false" text-align="start">
;</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
<fo:block id="N1018D" space-after="6pt">
The template specifications compute template attributes from
grammar
attributes and members such as <fo:inline font-family="Droid
Sans" font-size="90%">locals</fo:inline>.
</fo:block>
<fo:block id="N10194" space-after="6pt">
Here are the templates used by rule <fo:inline
font-family="Droid Sans" font-size="90%">stat</fo:inline>:
</fo:block>
<fo:block color="rgb(120, 155, 125)" background="rgb(200, 235,
220)" font-weight="bold" font-size="80%" font-family="Myriad"
padding-left="0.3em" space-before.maximum="10pt"
space-before.optimum="6pt" space-before.minimum="6pt"
keep-with-next="always">
<fo:basic-link xmlns:exsl=
"http://exslt.org/common"
external-destination="url(
http://media.pragprog.com/titles/tpantlr2/code/templates/generator/2pass/ByteCode.stg)">Download
templates/generator/2pass/ByteCode.stg</fo:basic-link>
</fo:block>
<fo:list-block provisional-distance-between-starts="0in"
space-after.maximum="10pt" space-after.optimum="8pt"
space-after.minimum="6pt" space-before="0pt" font-size="80%"
font-family="Droid Sans Mono">
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false"
text-align="start">assign(varNum,v,descr,id) ::=
<<</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false" text-align="start">; compute
<descr></fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false"
text-align="start"><v></fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false" text-align="start">istore
<varNum> ; <id></fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false"
text-align="start">>></fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false"
text-align="start"></fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false" text-align="start">exprStat(v,
descr) ::= <<</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false" text-align="start">; compute
<descr></fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false"
text-align="start"><v></fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item relative-align="baseline">
<fo:list-item-label end-indent="label-end()"
start-indent="-0.5in">
<fo:block font-family="Myriad" width="0.5in" color="rgb(120, 120,
140)" font-size="65%" text-align="right"/>
</fo:list-item-label>
<fo:list-item-body end-indent="0pt" start-indent="0pt">
<fo:block padding-bottom="0pt" line-height="140%"
padding-top="0pt" margin-bottom="0pt" margin-top="0pt"
wrap-option="no-wrap" white-space-treatment="preserve"
white-space-collapse="false"
text-align="start">>></fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
<fo:block id="N101D5" space-after="6pt">
All the expression-related rules in the parser grammar collapse
into
a single <fo:inline font-family="Droid Sans"
font-size="90%">expr</fo:inline> rule in the tree grammar:
</fo:block>
!DSPAM:87,4d94852d63731826313041!
_______________________________________________
(*) To unsubscribe, please visit http://lists.renderx.com/mailman/options/xep-support
(*) By using the Service, you expressly agree to these Terms of Service http://w
ww.renderx.com/terms-of-service.html
Received on Thu Mar 31 05:44:20 2011