Skip to content

Commit

Permalink
Java (in)equivalence by testing nearing finish;
Browse files Browse the repository at this point in the history
BTF-to-source bug fixes and feature additions


git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@1012 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Apr 7, 2011
1 parent d29342a commit 12e5e06
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 10 deletions.
90 changes: 82 additions & 8 deletions topics/export/source/btf2source.xslt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<?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"
xmlns:btf="http://planet-sl.org/btf"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
version="1.0">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:bgf="http://planet-sl.org/bgf" xmlns:btf="http://planet-sl.org/btf" xmlns:xhtml="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:output method="text" encoding="UTF-8" omit-xml-declaration="yes"/>
<xsl:variable name="apos">'</xsl:variable>
<xsl:variable name="bs">\</xsl:variable>
<xsl:template match="/btf:root">
<xsl:apply-templates select="./btf:tree"/>
<xsl:text>
Expand All @@ -20,11 +17,34 @@
<xsl:text>α</xsl:text>
</xsl:when>
<xsl:when test="terminal">
<xsl:value-of select="terminal"/>
<xsl:variable name="trmQuotesGone">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="terminal"/>
<xsl:with-param name="replace" select="concat($bs,$apos)"/>
<xsl:with-param name="by" select="$apos"/>
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$trmQuotesGone"/>
<xsl:with-param name="replace" select="concat($bs,$bs)"/>
<xsl:with-param name="by" select="$bs"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="nonterminal|choice|selectable">
<xsl:when test="choice|selectable">
<xsl:apply-templates select="*/btf:tree"/>
</xsl:when>
<xsl:when test="nonterminal">
<xsl:choose>
<xsl:when test="substring(nonterminal/bgf:production/nonterminal,1,1) = translate(substring(nonterminal/bgf:production/nonterminal,1,1), 'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')">
<xsl:for-each select="*/btf:tree">
<xsl:call-template name="lextree"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="*/btf:tree"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="sequence|star|plus|optional">
<xsl:if test="*/btf:tree">
<xsl:for-each select="*/btf:tree[1]">
Expand All @@ -42,4 +62,58 @@
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- no whitespace for lexical nonterminals -->
<xsl:template name="lextree">
<xsl:choose>
<xsl:when test="epsilon">
<xsl:text/>
</xsl:when>
<xsl:when test="alpha">
<xsl:text>α</xsl:text>
</xsl:when>
<xsl:when test="terminal">
<xsl:variable name="trmQuotesGone">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="terminal"/>
<xsl:with-param name="replace" select="concat($bs,$apos)"/>
<xsl:with-param name="by" select="$apos"/>
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$trmQuotesGone"/>
<xsl:with-param name="replace" select="concat($bs,$bs)"/>
<xsl:with-param name="by" select="$bs"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="nonterminal|choice|selectable|sequence|star|plus|optional">
<xsl:for-each select="*/btf:tree">
<xsl:call-template name="lextree"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="local-name(*)"/>
<xsl:text>?</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- taken from http://geekswithblogs.net/Erik/archive/2008/04/01/120915.aspx -->
<xsl:template name="string-replace-all">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="by"/>
<xsl:choose>
<xsl:when test="contains($text, $replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$by"/>
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="by" select="$by"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
11 changes: 9 additions & 2 deletions topics/testing/gbtf/tests/java/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gbtf-options = sc root strip uppy
gbtf-options = root uppy sc rc nc bc cdbc
include ../Makefile.include

cj:
Expand All @@ -21,4 +21,11 @@ cj:

%.count.par:
@/bin/echo -n ' ' $*:
@find . -name 'parr.bgf-*-$*-*.btf' | wc -l
@find . -name 'parr.bgf-*-$*-*.btf' | wc -l

execute:
time ls -1 habelitz.bgf-*.src | xargs -n1 ./java.run habelitz.jar > results/h2h.res 2>&1
time ls -1 habelitz.bgf-*.src | xargs -n1 ./java.run parr.jar > results/h2p.res 2>&1
time ls -1 parr.bgf-*.src | xargs -n1 ./java.run habelitz.jar > results/p2h.res 2>&1
time ls -1 parr.bgf-*.src | xargs -n1 ./java.run parr.jar > results/p2p.res 2>&1
./report-results.py
4 changes: 4 additions & 0 deletions topics/testing/gbtf/tests/java/java.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

echo '[' $2 ']----------'
java -cp ../../../../../download/antlr-3.2.jar:$1 -ea TestIO $2 || echo 'NONZERO EXIT STATUS'
57 changes: 57 additions & 0 deletions topics/testing/gbtf/tests/java/report-results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os, sys, math, glob

def readDashSep(s):
# aaa\n----------\nbbb...
f = open(s,'r')
res = ['']
met = ['']
nam = ['']
i = 0
for line in f.readlines():
if line.strip()[-10:] == '----------':
i += 1
res.append('')
met.append(line.split('-')[2])
nam.append(line.split('-')[3].split('.')[0])
else:
res[i] += line.strip()
f.close()
return res[1:],met[1:],nam[1:]

if __name__ == "__main__":
if len(sys.argv) > 1:
print 'No parameters expected!'
sys.exit(-1)
report = {}
repkeys = []
for f in glob.glob( 'results/*.res'):
out,met,nam = readDashSep(f)
total = len(out)
passed = total
bymethod = {}
for tc in range(0,total):
if met[tc] not in bymethod.keys():
bymethod[met[tc]]=[0,0,[]]
if out[tc] == 'pass' or out[tc] == '':
bymethod[met[tc]][0] += 1
else:
bymethod[met[tc]][2].append(nam[tc])
bymethod[met[tc]][1] += 1
repkeys.append(f.replace('.res','').replace('results/',''))
report[repkeys[-1]] = bymethod
for k in repkeys:
passed = total = 0
repkk = []
for method in ('sc','rc','nc','bc','cdbc'):
if method in report[k].keys():
repkk.append(method)
for m in repkk:
passed += report[k][m][0]
total += report[k][m][1]
print '%-20s'%(k+' '+m.upper()),':','%6.2f'%(100.0*report[k][m][0]/report[k][m][1]),'% [',report[k][m][0],'/',report[k][m][1],']'
if report[k][m][1]-report[k][m][0]<5 and report[k][m][1]!=report[k][m][0]:
print ' => fails on',report[k][m][2]
print '%-20s'%(k+' total'),':','%6.2f'%(100.0*passed/total),'% [',passed,'/',total,']'
sys.exit()

0 comments on commit 12e5e06

Please sign in to comment.