Skip to content

Commit

Permalink
TXL2BGF updated; TXL grammar given a separate directory
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@1089 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Jun 10, 2011
1 parent eddf46c commit d9a0b05
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 59 deletions.
32 changes: 0 additions & 32 deletions shared/internals/fixtxlxml

This file was deleted.

15 changes: 10 additions & 5 deletions shared/tools/txl2bgf
Expand Up @@ -19,9 +19,14 @@ else
exit 2
fi

txl $1 ${SLPS}/topics/extraction/txl/TXLGrammar/Txl/txl.txl -xml > grammar.xml
`dirname $0`/../internals/fixtxlxml grammar.xml grammar2.xml
xsltproc ${SLPS}/topics/extraction/txl/txl2bgf.xslt grammar2.xml > tmp.bgf
txl $1 ${SLPS}/topics/grammars/metasyntax/txl/TXLGrammar/Txl/txl.txl -xml > grammar.xml
#`dirname $0`/../internals/fixtxlxml grammar.xml grammar2.xml
xsltproc ${SLPS}/topics/extraction/txl/txl2bgf.xslt grammar.xml > tmp.bgf
xsltproc ${SLPS}/topics/transformation/normalization/subdefs/inline.xslt tmp.bgf > tmp.xbgf
${SLPS}/shared/tools/xbgf tmp.xbgf tmp.bgf ${OUTPUT}
rm -f tmp.bgf tmp.xbgf grammar.xml grammar2.xml
diff tmp.xbgf `dirname $0`/../internals/empty.xbgf > /dev/null
if [ "$?" -ne "0" ]; then
${SLPS}/shared/tools/xbgf tmp.xbgf tmp.bgf ${OUTPUT}
else
cp tmp.bgf ${OUTPUT}
fi
rm -f tmp.bgf tmp.xbgf grammar.xml
115 changes: 93 additions & 22 deletions topics/extraction/txl/txl2bgf.xslt
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:bgf="http://planet-sl.org/bgf" version="1.0">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/program">
Expand All @@ -7,13 +7,11 @@
<xsl:apply-templates select="repeat_statement/statement/defineStatement"/>
</bgf:grammar>
</xsl:template>

<xsl:template match="functionStatement">
<root>
<xsl:value-of select=".//typeid/id"/>
</root>
</xsl:template>

<xsl:template match="defineStatement">
<bgf:production>
<nonterminal>
Expand Down Expand Up @@ -43,7 +41,6 @@
</xsl:choose>
</bgf:production>
</xsl:template>

<xsl:template name="sequenceOrNot">
<xsl:param name="list"/>
<xsl:choose>
Expand All @@ -59,9 +56,8 @@
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="literalOrType">
<!--xsl:for-each select="repeat_literalOrType/literalOrType"-->
<!--xsl:for-each select="repeat_literalOrType/literalOrType"-->
<xsl:choose>
<xsl:when test="type/typeSpec/opt_typeRepeater/typeRepeater='+'">
<bgf:expression>
Expand All @@ -74,7 +70,8 @@
</plus>
</bgf:expression>
</xsl:when>
<xsl:when test="type/typeSpec/opt_typeRepeater/typeRepeater='*'">
<!-- we assumpe that [repeat x] means x* -->
<xsl:when test="type/typeSpec/opt_typeRepeater/typeRepeater='*' or type/typeSpec/opt_typeModifier/typeModifier='repeat'">
<bgf:expression>
<star>
<bgf:expression>
Expand All @@ -85,23 +82,28 @@
</star>
</bgf:expression>
</xsl:when>
<xsl:when test="type/typeSpec/opt_typeRepeater/typeRepeater='?'">
<bgf:expression>
<optional>
<bgf:expression>
<nonterminal>
<xsl:value-of select="type/typeSpec/typeid/id"/>
</nonterminal>
</bgf:expression>
</optional>
</bgf:expression>
<xsl:when test="type/typeSpec/opt_typeRepeater/typeRepeater='?' or type/typeSpec/opt_typeModifier/typeModifier='opt'">
<xsl:if test="type/typeSpec/typeid/id">
<bgf:expression>
<optional>
<bgf:expression>
<nonterminal>
<xsl:value-of select="type/typeSpec/typeid/id"/>
</nonterminal>
</bgf:expression>
</optional>
</bgf:expression>
</xsl:if>
<xsl:if test="type/typeSpec/typeid/literal">
<bgf:expression>
<optional>
<xsl:apply-templates select="type/typeSpec/typeid/literal"/>
</optional>
</bgf:expression>
</xsl:if>
</xsl:when>
<xsl:when test="literal">
<bgf:expression>
<terminal>
<xsl:value-of select="literal/unquotedLiteral/*"/>
</terminal>
</bgf:expression>
<xsl:apply-templates select="literal"/>
</xsl:when>
<xsl:when test="type/typeSpec/typeid/id = 'empty'">
<bgf:expression>
Expand All @@ -113,6 +115,10 @@
<any/>
</bgf:expression>
</xsl:when>
<!-- whitespace-related special nonterminals -->
<xsl:when test="type/formatCues">
<xsl:apply-templates select="type/formatCues"/>
</xsl:when>
<!-- fallback -->
<xsl:otherwise>
<bgf:expression>
Expand All @@ -123,4 +129,69 @@
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="literal">
<xsl:choose>
<xsl:when test="comment"/>
<xsl:when test="substring-after(unquotedLiteral/special,&quot;'&quot;)!=&quot;&quot;">
<bgf:expression>
<terminal>
<xsl:value-of select="substring-after(unquotedLiteral/special,&quot;'&quot;)"/>
</terminal>
</bgf:expression>
</xsl:when>
<xsl:otherwise>
<bgf:expression>
<terminal>
<xsl:value-of select="unquotedLiteral/*"/>
</terminal>
</bgf:expression>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="formatCues">
<xsl:choose>
<xsl:when test="count(repeat_formatCue/formatCue) &gt; 1">
<bgf:expression>
<sequence>
<xsl:for-each select="repeat_formatCue/formatCue">
<xsl:choose>
<xsl:when test="substring-after(formatId,' ')!=''">
<bgf:expression>
<nonterminal>
<xsl:value-of select="substring-after(formatId,' ')"/>
</nonterminal>
</bgf:expression>
</xsl:when>
<xsl:otherwise>
<bgf:expression>
<nonterminal>
<xsl:value-of select="formatId"/>
</nonterminal>
</bgf:expression>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</sequence>
</bgf:expression>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="substring-after(repeat_formatCue/formatCue/formatId,' ')!=''">
<bgf:expression>
<nonterminal>
<xsl:value-of select="substring-after(repeat_formatCue/formatCue/formatId,' ')"/>
</nonterminal>
</bgf:expression>
</xsl:when>
<xsl:otherwise>
<bgf:expression>
<nonterminal>
<xsl:value-of select="repeat_formatCue/formatCue/formatId"/>
</nonterminal>
</bgf:expression>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
3 changes: 3 additions & 0 deletions topics/fl/txl/Makefile
Expand Up @@ -10,3 +10,6 @@ test:
@/bin/echo -n "evaluate x = " >>fac5.fl
@cat ../shared/fac5.txt >> fac5.fl
@txl fac5.fl FL_evaluator.Txl

extract:
../../../shared/tools/txl2bgf FL.Txl fl.bgf
4 changes: 4 additions & 0 deletions topics/grammars/metasyntax/txl/Makefile
@@ -0,0 +1,4 @@
extract:
${tooldir}/txl2bgf TXLGrammar/Txl/txl.grm grammar.bgf

include ../../Makefile.grammar
File renamed without changes.

0 comments on commit d9a0b05

Please sign in to comment.