Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@660 ab42f6e0-554d-0410-b580-99e487e6eeb2
- Loading branch information
1 parent
e3ebd34
commit 6ce3d27
Showing
12 changed files
with
1,455 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/sh | ||
|
||
LOCAL=${PWD} | ||
cd `dirname $0` | ||
cd ../.. | ||
SLPS=${PWD} | ||
cd ${LOCAL} | ||
|
||
if [ ! -r $1 ]; then | ||
echo "Oops: $1 not found or not readable." | ||
exit 1 | ||
elif [ $# -eq 2 ]; then | ||
rm -f $2 | ||
txl $1 ${SLPS}/topics/extraction/txl2bgf/TXLGrammar/Txl/txl.txl -xml > grammar.xml | ||
perl -pi -w -e 's/repeat statement/repeat_statement/g;' grammar.xml | ||
perl -pi -w -e 's/repeat compound/repeat_compound/g;' grammar.xml | ||
perl -pi -w -e 's/repeat literalOrType/repeat_literalOrType/g;' grammar.xml | ||
perl -pi -w -e 's/repeat literalOrVariable/repeat_literalOrVariable/g;' grammar.xml | ||
perl -pi -w -e 's/repeat barLiteralsAndTypes/repeat_barLiteralsAndTypes/g;' grammar.xml | ||
perl -pi -w -e 's/opt typeRepeater/opt_typeRepeater/g;' grammar.xml | ||
xsltproc ${SLPS}/shared/xsl/txl2bgf.xslt grammar.xml > $2 | ||
rm -f grammar.xml | ||
elif [ $# -eq 1 ]; then | ||
txl $1 ${SLPS}/topics/extraction/txl2bgf/TXLGrammar/Txl/txl.txl -xml > grammar.xml | ||
perl -pi -w -e 's/repeat statement/repeat_statement/g;' grammar.xml | ||
perl -pi -w -e 's/repeat compound/repeat_compound/g;' grammar.xml | ||
perl -pi -w -e 's/repeat literalOrType/repeat_literalOrType/g;' grammar.xml | ||
perl -pi -w -e 's/repeat literalOrVariable/repeat_literalOrVariable/g;' grammar.xml | ||
perl -pi -w -e 's/repeat barLiteralsAndTypes/repeat_barLiteralsAndTypes/g;' grammar.xml | ||
perl -pi -w -e 's/opt typeRepeater/opt_typeRepeater/g;' grammar.xml | ||
xsltproc ${SLPS}/shared/xsl/txl2bgf.xslt grammar.xml > ${LOCAL}/`basename $1 .txl`.bgf | ||
rm -f grammar.xml | ||
else | ||
echo "This tool extracts a BGF grammar from a TXL grammar" | ||
echo "Usage: txl2bgf <txl-grammar> [<output-grammar>]" | ||
exit 2 | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<xsl:stylesheet version = '1.0' | ||
xmlns:xsl='http://www.w3.org/1999/XSL/Transform' | ||
xmlns:bgf="http://planet-sl.org/bgf" | ||
> | ||
<xsl:output method="xml" encoding="UTF-8"/> | ||
|
||
<xsl:template match="/program"> | ||
<bgf:grammar> | ||
<xsl:apply-templates select="repeat_statement/statement/defineStatement"/> | ||
</bgf:grammar> | ||
</xsl:template> | ||
|
||
<xsl:template match="defineStatement"> | ||
<bgf:production> | ||
<nonterminal> | ||
<xsl:value-of select="typeid/id" /> | ||
</nonterminal> | ||
<!--xsl:apply-templates select="repeat_literalOrType/literalOrType/type/typeSpec"/--> | ||
<xsl:choose> | ||
<xsl:when test="repeat_barLiteralsAndTypes"> | ||
<bgf:expression> | ||
<choice> | ||
<xsl:call-template name="sequenceOrNot"> | ||
<xsl:with-param name="list" select="repeat_literalOrType"/> | ||
</xsl:call-template> | ||
<xsl:for-each select="repeat_barLiteralsAndTypes/barLiteralsAndTypes/repeat_literalOrType"> | ||
<xsl:call-template name="sequenceOrNot"> | ||
<xsl:with-param name="list" select="."/> | ||
</xsl:call-template> | ||
</xsl:for-each> | ||
</choice> | ||
</bgf:expression> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<xsl:call-template name="sequenceOrNot"> | ||
<xsl:with-param name="list" select="repeat_literalOrType"/> | ||
</xsl:call-template> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
</bgf:production> | ||
</xsl:template> | ||
|
||
<xsl:template name="sequenceOrNot"> | ||
<xsl:param name="list"/> | ||
<bgf:expression> | ||
<xsl:choose> | ||
<xsl:when test="count($list/literalOrType)=1"> | ||
<xsl:apply-templates select="$list/literalOrType"/> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<sequence> | ||
<xsl:apply-templates select="$list/literalOrType"/> | ||
</sequence> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
</bgf:expression> | ||
</xsl:template> | ||
|
||
<xsl:template match="literalOrType"> | ||
<!--xsl:for-each select="repeat_literalOrType/literalOrType"--> | ||
<xsl:choose> | ||
<xsl:when test="type/typeSpec/opt_typeRepeater/typeRepeater='+'"> | ||
<bgf:expression> | ||
<plus> | ||
<nonterminal> | ||
<xsl:value-of select="type/typeSpec/typeid/id" /> | ||
</nonterminal> | ||
</plus> | ||
</bgf:expression> | ||
</xsl:when> | ||
<xsl:when test="type/typeSpec/opt_typeRepeater/typeRepeater='*'"> | ||
<bgf:expression> | ||
<star> | ||
<nonterminal> | ||
<xsl:value-of select="type/typeSpec/typeid/id" /> | ||
</nonterminal> | ||
</star> | ||
</bgf:expression> | ||
</xsl:when> | ||
<xsl:when test="literal"> | ||
<bgf:expression> | ||
<terminal> | ||
<xsl:value-of select="literal/unquotedLiteral/special" /> | ||
</terminal> | ||
</bgf:expression> | ||
</xsl:when> | ||
<!-- fallback --> | ||
<xsl:otherwise> | ||
<bgf:expression> | ||
<nonterminal> | ||
<xsl:value-of select="type/typeSpec/typeid/id" /> | ||
</nonterminal> | ||
</bgf:expression> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:template> | ||
|
||
</xsl:stylesheet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test: | ||
../../../shared/tools/txl2bgf ../../fl/txl/FL.Txl fl.bgf | ||
../../../shared/tools/bgf2bnf fl.bgf |
84 changes: 84 additions & 0 deletions
84
topics/extraction/txl2bgf/TXLGrammar/Examples/calculator.txl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
% Calculator.Txl - simple numerical expression evaluator | ||
|
||
% Part I. Syntax specification | ||
define program | ||
[expression] | ||
end define | ||
|
||
define expression | ||
[term] | ||
| [expression] [addop] [term] | ||
end define | ||
|
||
define term | ||
[primary] | ||
| [term] [mulop] [primary] | ||
end define | ||
|
||
define primary | ||
[number] | ||
| ( [expression] ) | ||
end define | ||
|
||
define addop | ||
'+ | ||
| '- | ||
end define | ||
|
||
define mulop | ||
'* | ||
| '/ | ||
end define | ||
|
||
|
||
% Part 2. Transformation rules | ||
rule main | ||
replace [expression] | ||
E [expression] | ||
construct NewE [expression] | ||
E [resolveAddition] | ||
[resolveSubtraction] | ||
[resolveMultiplication] | ||
[resolveDivision] | ||
[resolveBracketedExpressions] | ||
where not | ||
NewE [= E] | ||
by | ||
NewE | ||
end rule | ||
|
||
rule resolveAddition | ||
replace [expression] | ||
N1 [number] + N2 [number] | ||
by | ||
N1 [+ N2] | ||
end rule | ||
|
||
rule resolveSubtraction | ||
replace [expression] | ||
N1 [number] - N2 [number] | ||
by | ||
N1 [- N2] | ||
end rule | ||
|
||
rule resolveMultiplication | ||
replace [term] | ||
N1 [number] * N2 [number] | ||
by | ||
N1 [* N2] | ||
end rule | ||
|
||
rule resolveDivision | ||
replace [term] | ||
N1 [number] / N2 [number] | ||
by | ||
N1 [/ N2] | ||
end rule | ||
|
||
rule resolveBracketedExpressions | ||
replace [primary] | ||
( N [number] ) | ||
by | ||
N | ||
end rule | ||
|
Oops, something went wrong.