Skip to content

Commit

Permalink
circulus vitiosus from BGF to TXL to BGF back
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@834 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Sep 29, 2010
1 parent 5a2be99 commit 62ddb24
Show file tree
Hide file tree
Showing 5 changed files with 295 additions and 115 deletions.
2 changes: 1 addition & 1 deletion shared/tools/bgf2txl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ else
OUTPUT=$2 OUTPUT=$2
fi fi


xsltproc ${SLPS}/shared/xsl/bgf2txl.xslt $1> ${OUTPUT} xsltproc ${SLPS}/topics/export/txl/bgf2txl.xslt $1> ${OUTPUT}
7 changes: 7 additions & 0 deletions topics/export/txl/Makefile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,5 +4,12 @@ tooldir = ../../../shared/tools
test: test:
ls -1 ${bgfdir} | xargs -n1 ./bgf2txl2bgf ${tooldir} ${bgfdir} ls -1 ${bgfdir} | xargs -n1 ./bgf2txl2bgf ${tooldir} ${bgfdir}


fl:
cp ../../fl/txl/FL.Txl FL0.txl
${tooldir}/txl2bgf FL0.txl fl1.bgf
${tooldir}/bgf2txl fl1.bgf FL2.txl
${tooldir}/txl2bgf FL2.txl fl3.bgf
${tooldir}/gdt fl1.bgf fl3.bgf

clean: clean:
rm -f *~ *.bgf *.txl *.bnf rm -f *~ *.bgf *.txl *.bnf
167 changes: 167 additions & 0 deletions topics/export/txl/bgf2txl.xslt
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,167 @@
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:bgf="http://planet-sl.org/bgf" xmlns:xhtml="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:output method="text" encoding="UTF-8" omit-xml-declaration="yes"/>
<xsl:template match="/bgf:grammar">
<xsl:text>%% GENERATED GRAMMAR
#pragma -newline
</xsl:text>
<xsl:if test="//terminal[string-length(.) &gt; 1]">
<xsl:text>compounds
</xsl:text>
<xsl:for-each select="//terminal[string-length(.) &gt; 1]">
<xsl:value-of select="."/>
<xsl:text> </xsl:text>
</xsl:for-each>
<xsl:text>end compounds
</xsl:text>
</xsl:if>
<!-- todo later -->
<xsl:apply-templates select="./bgf:*"/>
<xsl:if test="//root">
<xsl:text>
function main match [</xsl:text>
<xsl:value-of select="//root[1]"/>
<xsl:text>] _ [</xsl:text>
<xsl:value-of select="//root[1]"/>
<xsl:text>] end function
</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template match="bgf:production">
<xsl:text>define </xsl:text>
<xsl:value-of select="./nonterminal"/>
<xsl:text>
</xsl:text>
<!-- what to do with labels? TODO -->
<xsl:if test="./label">
<xsl:text>[</xsl:text>
<xsl:value-of select="./label"/>
<xsl:text>] </xsl:text>
</xsl:if>
<xsl:choose>
<xsl:when test="./bgf:expression/choice">
<xsl:for-each select="./bgf:expression/choice/bgf:expression">
<xsl:if test="position() != 1">
<xsl:text>
| </xsl:text>
</xsl:if>
<xsl:call-template name="no-parenthesis">
<xsl:with-param name="expr" select="."/>
</xsl:call-template>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="no-parenthesis">
<xsl:with-param name="expr" select="./bgf:expression"/>
</xsl:call-template>
<xsl:text>
</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>end define
</xsl:text>
</xsl:template>
<xsl:template match="bgf:expression">
<xsl:apply-templates select="./*"/>
</xsl:template>
<xsl:template match="marked">
<xsl:text><![CDATA[<]]></xsl:text>
<xsl:apply-templates select="./*"/>
<xsl:text><![CDATA[>]]></xsl:text>
</xsl:template>
<xsl:template match="plus">
<xsl:text>[</xsl:text>
<xsl:apply-templates select="./*"/>
<xsl:text>+]</xsl:text>
</xsl:template>
<xsl:template match="star">
<xsl:text>[</xsl:text>
<xsl:apply-templates select="./*"/>
<xsl:text>*]</xsl:text>
</xsl:template>
<xsl:template match="optional">
<xsl:apply-templates select="./*"/>
<xsl:text>?</xsl:text>
</xsl:template>
<xsl:template match="terminal">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="value">
<xsl:choose>
<xsl:when test=". = 'string'">
<xsl:text>STR</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>INT</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="epsilon">
<xsl:text>EPSILON</xsl:text>
</xsl:template>
<xsl:template match="empty">
<xsl:text>EMPTY</xsl:text>
</xsl:template>
<xsl:template match="any">
<xsl:text>ANY</xsl:text>
</xsl:template>
<xsl:template match="nonterminal">
<xsl:if test="local-name(../..) != 'plus' and local-name(../..) != 'star'">
<xsl:text>[</xsl:text>
</xsl:if>
<xsl:value-of select="."/>
<xsl:if test="local-name(../..) != 'plus' and local-name(../..) != 'star'">
<xsl:text>]</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template match="selectable">
<xsl:value-of select="selector"/>
<xsl:text>::</xsl:text>
<xsl:choose>
<xsl:when test="local-name(bgf:expression/*) = 'star' or local-name(bgf:expression/*) = 'optional' or local-name(bgf:expression/*) = 'plus'">
<xsl:text>(</xsl:text>
<xsl:apply-templates select="bgf:expression"/>
<xsl:text>)</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="bgf:expression"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="sequence">
<xsl:text>(</xsl:text>
<xsl:apply-templates select="./bgf:expression[1]/*"/>
<xsl:for-each select="./bgf:expression[position()&gt;1]">
<xsl:text> </xsl:text>
<xsl:apply-templates select="./*"/>
</xsl:for-each>
<xsl:text>)</xsl:text>
</xsl:template>
<!-- inner choices - BNF bar -->
<xsl:template match="choice">
<xsl:text>(</xsl:text>
<xsl:apply-templates select="./bgf:expression[1]/*"/>
<xsl:for-each select="./bgf:expression[position()&gt;1]">
<xsl:text> | </xsl:text>
<xsl:apply-templates select="./*"/>
</xsl:for-each>
<xsl:text>)</xsl:text>
</xsl:template>
<xsl:template name="no-parenthesis">
<xsl:param name="expr"/>
<xsl:choose>
<xsl:when test="$expr/sequence">
<xsl:apply-templates select="$expr/sequence/bgf:expression[1]/*"/>
<xsl:for-each select="$expr/sequence/bgf:expression[position()&gt;1]">
<xsl:text> </xsl:text>
<xsl:apply-templates select="./*"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="$expr"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Loading

0 comments on commit 62ddb24

Please sign in to comment.