Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now "extraction" topic is dedicated strictly to derivation of BGFs from various sources. The "presentation" topic is for getting various info out of BGFs. The "transformation" topic is still for BGF to BGF transformations. The "convergence" topic is for using BGF to BGF transformations for grammar convergence. git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@314 ab42f6e0-554d-0410-b580-99e487e6eeb2
- Loading branch information
1 parent
05fc543
commit 392f8fb
Showing
9 changed files
with
193 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/sh | ||
|
||
LOCAL=${PWD} | ||
cd `dirname $0` | ||
cd ../.. | ||
SLPS=${PWD} | ||
cd ${LOCAL} | ||
|
||
if [ $# -eq 1 ]; then | ||
OUTPUT=`basename $1 .bgf`.bnf | ||
elif [ $# -ne 2 ]; then | ||
echo "This tool transforms XML BNF-like Grammar Format documents to EBNF dialect used in JLS." | ||
echo "Usage: bgf2bnf <input-bgf-document> [<output-text>]" | ||
exit 1 | ||
elif [ ! -r $1 ]; then | ||
echo "Oops: $1 not found or not readable." | ||
exit 1 | ||
else | ||
OUTPUT=$2 | ||
fi | ||
|
||
${SLPS}/shared/tools/xbgf ${SLPS}/topics/presentation/bgf2bnf/strips.xbgf $1 $1.noselectors > /dev/null | ||
if [ ! -r $1.noselectors ]; then | ||
${SLPS}/shared/tools/xbgf ${SLPS}/topics/presentation/bgf2bnf/stripl.xbgf $1 $1.nolabels > /dev/null | ||
if [ -r $1.nolabels ]; then | ||
mv $1.nolabels $1.stripped | ||
else | ||
cp $1 $1.stripped | ||
fi | ||
else | ||
${SLPS}/shared/tools/xbgf ${SLPS}/topics/presentation/bgf2bnf/stripl.xbgf $1.noselectors $1.nolabels > /dev/null | ||
if [ -r $1.nolabels ]; then | ||
mv $1.nolabels $1.stripped | ||
else | ||
mv $1.noselectors $1.stripped | ||
fi | ||
fi | ||
xsltproc ${SLPS}/shared/xsl/bgf2bnf.xslt $1.stripped > ${OUTPUT} | ||
rm -f $1.stripped $1.noselectors $1.nolabels |
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,129 @@ | ||
<xsl:stylesheet version = '1.0' | ||
xmlns:xsl='http://www.w3.org/1999/XSL/Transform' | ||
xmlns:bgf="http://planet-sl.org/bgf" | ||
xmlns:xhtml="http://www.w3.org/1999/xhtml"> | ||
|
||
<xsl:output | ||
method="text" | ||
encoding="UTF-8" | ||
omit-xml-declaration="yes" | ||
/> | ||
|
||
<xsl:template match="/bgf:grammar"> | ||
<xsl:apply-templates select="./bgf:*"/> | ||
</xsl:template> | ||
|
||
<xsl:template match="bgf:production"> | ||
<xsl:value-of select="./nonterminal"/> | ||
<xsl:text>:</xsl:text> | ||
<xsl:choose> | ||
<xsl:when test="./bgf:expression/choice"> | ||
<xsl:for-each select="./bgf:expression/choice/bgf:expression"> | ||
<xsl:text> | ||
</xsl:text> | ||
<xsl:apply-templates select="."/> | ||
</xsl:for-each> | ||
<xsl:text> | ||
</xsl:text> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<xsl:text> | ||
</xsl:text> | ||
<xsl:apply-templates select="./bgf:expression"/> | ||
<xsl:text> | ||
</xsl:text> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:template> | ||
|
||
<xsl:template match="bgf:expression"> | ||
<xsl:apply-templates select="./*"/> | ||
</xsl:template> | ||
|
||
<xsl:template match="plus"> | ||
<xsl:apply-templates select="./*"/> | ||
<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:text>[ </xsl:text> | ||
<xsl:apply-templates select="./*"/> | ||
<xsl:text>] </xsl:text> | ||
</xsl:template> | ||
|
||
<xsl:template match="terminal"> | ||
<xsl:text>"</xsl:text> | ||
<xsl:value-of select="."/> | ||
<xsl:text>" </xsl:text> | ||
</xsl:template> | ||
|
||
<xsl:template match="value"> | ||
<xsl:choose> | ||
<xsl:when test=". = 'string'"> | ||
<xsl:text>STRING </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:value-of select="."/> | ||
<xsl:text> </xsl:text> | ||
</xsl:template> | ||
|
||
<xsl:template match="sequence"> | ||
<xsl:apply-templates select="./*"/> | ||
</xsl:template> | ||
|
||
<xsl:template match="choice"> | ||
<xsl:call-template name="car"> | ||
<xsl:with-param name="expr" select="./bgf:expression[1]"/> | ||
</xsl:call-template> | ||
<xsl:for-each select="./bgf:expression[position()>1]"> | ||
<xsl:call-template name="cdr"> | ||
<xsl:with-param name="expr" select="."/> | ||
</xsl:call-template> | ||
</xsl:for-each> | ||
</xsl:template> | ||
|
||
<xsl:template name="car"> | ||
<xsl:param name="expr"/> | ||
<xsl:text> | ||
</xsl:text> | ||
<xsl:apply-templates select="$expr/*"/> | ||
<xsl:text> | ||
</xsl:text> | ||
</xsl:template> | ||
|
||
<xsl:template name="cdr"> | ||
<xsl:param name="expr"/> | ||
<xsl:text> | ||
</xsl:text> | ||
<xsl:apply-templates select="$expr/*"/> | ||
<xsl:text> | ||
</xsl:text> | ||
</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,12 @@ | ||
all: | ||
make clean | ||
make test | ||
|
||
build: | ||
|
||
test: | ||
find ../../fl/lci/snapshot/ -name "*.bgf" | xargs -n1 ../../../shared/tools/bgf2bnf | ||
find ../../java/lci/snapshot/ -name "*.bgf" | xargs -n1 ../../../shared/tools/bgf2bnf | ||
|
||
clean: | ||
rm -f *.bnf |
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,6 @@ | ||
<xbgf:sequence | ||
xmlns:xbgf="http://planet-sl.org/xbgf"> | ||
<xbgf:strip> | ||
<allLabels/> | ||
</xbgf:strip> | ||
</xbgf:sequence> |
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,6 @@ | ||
<xbgf:sequence | ||
xmlns:xbgf="http://planet-sl.org/xbgf"> | ||
<xbgf:strip> | ||
<allSelectors/> | ||
</xbgf:strip> | ||
</xbgf:sequence> |
File renamed without changes.
File renamed without changes.
File renamed without changes.