Skip to content

Commit

Permalink
more languedoc progress
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@550 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Apr 7, 2009
1 parent aa8330b commit 535b45a
Show file tree
Hide file tree
Showing 4 changed files with 249 additions and 7 deletions.
3 changes: 1 addition & 2 deletions topics/languedoc/languedoc.csproj
Expand Up @@ -76,8 +76,7 @@
<Link>xbgf\bnf\xbgf\stripWhitespace.xbgf</Link>
</None>
<None Include="ldf\beautify.xbgf" />
<None Include="xbgf\beautify_bgf.xbgf" />
<None Include="xbgf\beautify_xbgf.xbgf" />
<None Include="xbgf\xbgf.xldf" />
<None Include="xbgf\xldf\completeDecorSection.xldf" />
<None Include="xbgf\xldf\completeDecSection.xldf" />
<None Include="xbgf\xldf\completeFoldSection.xldf" />
Expand Down
125 changes: 124 additions & 1 deletion topics/languedoc/xbgf/xldf/completeFoldSection.xldf
Expand Up @@ -321,18 +321,141 @@
</considerations>
<to>element-abridge</to>
</xldf:add-subsection>
<xldf:add-subsection>
<example id="abridge-example">
<content>
<text>
Consider this abstract syntax:
</text>
</content>
</example>
<to>element-abridge</to>
</xldf:add-subsection>
<xldf:import-grammar>
<target>abridge-example</target>
<file>../../transformation/xbgf/tests/abridge.bgf</file>
</xldf:import-grammar>
<xldf:append>
<where>abridge-example</where>
<content>
<text>After performing this transformation step:</text>
</content>
</xldf:append>
<xldf:import-sample>
<target>abridge-example</target>
<file>../../transformation/xbgf/tests/abridge.xbgf</file>
<prettyprinter>../../../shared/tools/xbgf2xbnf</prettyprinter>
</xldf:import-sample>
<xldf:append>
<where>abridge-example</where>
<content>
<text>
The grammar will be the same, but without the reflexive chain production
labelled as `bracket' previously:
</text>
</content>
</xldf:append>
<xldf:import-grammar>
<target>abridge-example</target>
<file>../../transformation/xbgf/tests/abridge.baseline</file>
</xldf:import-grammar>

<xldf:place>
<section>element-detour</section>
<inside>group-folding-transformation</inside>
</xldf:place>
<xldf:add-subsection>
<example id="detour-example">
<content>
<text>
In the same way it was removed in the previous example,
the bracketing production can be added to the grammar:
</text>
</content>
</example>
<to>element-detour</to>
</xldf:add-subsection>
<xldf:import-sample>
<target>detour-example</target>
<file>../../transformation/xbgf/tests/detour.xbgf</file>
<prettyprinter>../../../shared/tools/xbgf2xbnf</prettyprinter>
</xldf:import-sample>

<xldf:place>
<section>element-unchain</section>
<inside>group-folding-transformation</inside>
</xldf:place>
<xldf:add-subsection>
<considerations>
<content>
<text>
Chain productions are not commonly encountered in grammars of mainstream
programming languages. However, when converging grammars that hail from
different kinds of sources (i.e., different extraction processes) it can
be frequently needed to align grammars that use chain productions with
grammars that use labelled ones.
</text>
</content>
</considerations>
<to>element-unchain</to>
</xldf:add-subsection>
<xldf:add-subsection>
<example id="unchain-example">
<content>
<text>
Consider this grammar:
</text>
</content>
</example>
<to>element-unchain</to>
</xldf:add-subsection>
<xldf:import-grammar>
<target>unchain-example</target>
<file>../../transformation/xbgf/tests/unchain.bgf</file>
</xldf:import-grammar>
<xldf:append>
<where>unchain-example</where>
<content>
<text>After performing this transformation step:</text>
</content>
</xldf:append>
<xldf:import-sample>
<target>unchain-example</target>
<file>../../transformation/xbgf/tests/unchain.xbgf</file>
<prettyprinter>../../../shared/tools/xbgf2xbnf</prettyprinter>
</xldf:import-sample>
<xldf:append>
<where>unchain-example</where>
<content>
<text>
The auxiliary nonterminal symbol is gone, as is the chain production:
</text>
</content>
</xldf:append>
<xldf:import-grammar>
<target>unchain-example</target>
<file>../../transformation/xbgf/tests/unchain.baseline</file>
</xldf:import-grammar>

<xldf:place>
<section>element-chain</section>
<inside>group-folding-transformation</inside>
</xldf:place>

<xldf:add-subsection>
<example id="chain-example">
<content>
<text>
In the same way it was removed in the previous example,
the chain production can be added to the grammar:
</text>
</content>
</example>
<to>element-chain</to>
</xldf:add-subsection>
<xldf:import-sample>
<target>chain-example</target>
<file>../../transformation/xbgf/tests/chain.xbgf</file>
<prettyprinter>../../../shared/tools/xbgf2xbnf</prettyprinter>
</xldf:import-sample>

</xldf:sequence>
120 changes: 120 additions & 0 deletions topics/languedoc/xbgf/xldf/completeRefSection.xldf
Expand Up @@ -397,6 +397,67 @@
<section>element-factor</section>
<inside>group-refactoring-transformation</inside>
</xldf:place>
<xldf:add-subsection>
<considerations>
<content>
<text>
Factor transformations tend to be quite frequently used in grammar convergence.
They also have a tendency to be very long---since it is impossible to implement
<ldf:keyword>factor</ldf:keyword> symmetrically to <ldf:keyword>distribute</ldf:keyword>
(i.e., fully automated), the language engineer needs to supply two complete
expressions. The transformer then can easily assert that they are related by
distribution: basically, it internally performs <ldf:keyword>distribute</ldf:keyword>
on both of them and expects them to become identical. Hence, it is possible
to do `incomplete' factoring by pushing choices inwards but not to the innermost
position.
</text>
<text>
Two most commonly seen patterns of <ldf:keyword>factor</ldf:keyword> use are the following.
First, it is applied when we have a choice of two long expressions that are almost
identical except for some mismatching part. That part can be either extracted
or massaged later with more transformations. Second, it is needed when we have a wide
choice with the same leading (or trailing) symbol, and the goal is to let the common
part stay and encapsulate the rest inside a different nonterminal (by following
<ldf:keyword>extract</ldf:keyword>).
</text>
</content>
</considerations>
<to>element-factor</to>
</xldf:add-subsection>
<xldf:add-subsection>
<example id="factor-example">
<content>
<text>For example,</text>
</content>
</example>
<to>element-factor</to>
</xldf:add-subsection>
<xldf:import-grammar>
<target>factor-example</target>
<file>../../transformation/xbgf/tests/factor3.bgf</file>
</xldf:import-grammar>
<xldf:append>
<where>factor-example</where>
<content>
<text>After using this transformation (note the order of expressions):</text>
</content>
</xldf:append>
<xldf:import-sample>
<target>factor-example</target>
<file>../../transformation/xbgf/tests/factor3.xbgf</file>
<prettyprinter>../../../shared/tools/xbgf2xbnf</prettyprinter>
</xldf:import-sample>
<xldf:append>
<where>factor-example</where>
<content>
<text>Will look like this:</text>
</content>
</xldf:append>
<xldf:import-grammar>
<target>factor-example</target>
<file>../../transformation/xbgf/tests/factor3.baseline</file>
</xldf:import-grammar>

<xldf:place>
<section>element-deyaccify</section>
<inside>group-refactoring-transformation</inside>
Expand Down Expand Up @@ -466,22 +527,81 @@
<section>element-yaccify</section>
<inside>group-refactoring-transformation</inside>
</xldf:place>

<xldf:place>
<section>element-eliminate</section>
<inside>group-refactoring-transformation</inside>
</xldf:place>

<xldf:place>
<section>element-introduce</section>
<inside>group-refactoring-transformation</inside>
</xldf:place>

<xldf:place>
<section>element-import</section>
<inside>group-refactoring-transformation</inside>
</xldf:place>
<xldf:add-subsection>
<considerations>
<content>
<text>
There are times when <ldf:keyword>introduce</ldf:keyword> is just not enough.
The simplest of such a situations is a case when we want to introduce two
productions, each defining a fresh nonterminal symbol, and each using the other.
Without <ldf:keyword>import</ldf:keyword> the only way to do it was to run one
<ldf:keyword>introduce</ldf:keyword> and one <ldf:keyword>define</ldf:keyword>,
which is semantically wrong since we are sure that before the first nonterminal
is introduced, the second one was fresh. So, instead we take the interdependent
productions together and introduce them in one step.
</text>
<text>
Technically, <ldf:keyword>import</ldf:keyword> can be used any time to
substitute any number of <ldf:keyword>introduce</ldf:keyword> transformations.
</text>
</content>
</considerations>
<to>element-import</to>
</xldf:add-subsection>
<xldf:add-subsection>
<example id="import-example">
<content>
<text>For example,</text>
</content>
</example>
<to>element-import</to>
</xldf:add-subsection>
<xldf:import-grammar>
<target>import-example</target>
<file>../../transformation/xbgf/tests/import.bgf</file>
</xldf:import-grammar>
<xldf:append>
<where>import-example</where>
<content>
<text>After using this transformation:</text>
</content>
</xldf:append>
<xldf:import-sample>
<target>import-example</target>
<file>../../transformation/xbgf/tests/import.xbgf</file>
<prettyprinter>../../../shared/tools/xbgf2xbnf</prettyprinter>
</xldf:import-sample>
<xldf:append>
<where>import-example</where>
<content>
<text>It will look like this:</text>
</content>
</xldf:append>
<xldf:import-grammar>
<target>import-example</target>
<file>../../transformation/xbgf/tests/import.baseline</file>
</xldf:import-grammar>

<xldf:place>
<section>element-vertical</section>
<inside>group-refactoring-transformation</inside>
</xldf:place>

<xldf:place>
<section>element-horizontal</section>
<inside>group-refactoring-transformation</inside>
Expand Down
8 changes: 4 additions & 4 deletions topics/transformation/xbgf/tests/factor3.xbgf
Expand Up @@ -43,20 +43,20 @@
<bgf:expression>
<sequence>
<bgf:expression>
<nonterminal>c</nonterminal>
<nonterminal>e</nonterminal>
</bgf:expression>
<bgf:expression>
<nonterminal>d</nonterminal>
<nonterminal>f</nonterminal>
</bgf:expression>
</sequence>
</bgf:expression>
<bgf:expression>
<sequence>
<bgf:expression>
<nonterminal>e</nonterminal>
<nonterminal>c</nonterminal>
</bgf:expression>
<bgf:expression>
<nonterminal>f</nonterminal>
<nonterminal>d</nonterminal>
</bgf:expression>
</sequence>
</bgf:expression>
Expand Down

0 comments on commit 535b45a

Please sign in to comment.