Skip to content

Commit

Permalink
presentation -> investigation; LEV in Python
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@929 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Feb 1, 2011
1 parent b45c416 commit 196bbda
Show file tree
Hide file tree
Showing 45 changed files with 87 additions and 1 deletion.
2 changes: 1 addition & 1 deletion topics/export/ebnf/export.py
Expand Up @@ -8,7 +8,7 @@

if __name__ == "__main__":
if len(sys.argv) != 3:
print 'This tool extracts a Rascal grammar.'
print 'This tool generates a BNF representation for any given BGF grammar.'
print 'Usage:'
print ' bgf2bnf <bgf-input> <bnf-output>'
sys.exit(1)
Expand Down
7 changes: 7 additions & 0 deletions topics/investigation/lev/Makefile
@@ -0,0 +1,7 @@
test:
cp ../../convergence/fl/snapshot/*.bgf tests/
cp ../../convergence/java/snapshot/*.bgf tests/
ls -1 tests/*.bgf | xargs -n1 ./testperform

clean:
rm -f tests/*.bgf tests/*.out
56 changes: 56 additions & 0 deletions topics/investigation/lev/levels.py
@@ -0,0 +1,56 @@
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import os
import sys
sys.path.append('../../../shared/python')
import slpsns
import BGF
import elementtree.ElementTree as ET

calls = {}

if __name__ == "__main__":
# |>*
if len(sys.argv) != 2:
#print 'This tool generates a BNF representation for any given BGF grammar.'
print 'Usage:'
print ' bgf2bnf <bgf-input> <bnf-output>'
sys.exit(1)
bgf = BGF.Grammar()
bgf.parse(sys.argv[1])
for p in bgf.prods:
if p.nt not in calls.keys():
calls[p.nt] = []
for n in p.expr.wrapped.getXml().findall('.//nonterminal'):
if n.text not in calls[p.nt]:
calls[p.nt].append(n.text)
#for n in calls.keys():
# print n,'▻',calls[n]
#print '--------------------'
for n in calls.keys():
for x in calls[n]:
if x not in calls.keys():
calls[x] = []
for y in calls[x]:
if y not in calls[n]:
calls[n].append(y)
calls[n].sort()
#for n in calls.keys():
# print n,'▻*',calls[n]
#print '--------------------'
unassigned = calls.keys()
levels = []
while len(unassigned)>0:
nt = unassigned[0]
levels.append([])
levels[-1].append(nt)
unassigned = unassigned[1:]
for n in calls[nt]:
if nt in calls[n]:
levels[-1].append(n)
if n in unassigned:
unassigned.remove(n)
print 'LEV =',len(levels)
#for l in levels:
# print l
sys.exit(0)
5 changes: 5 additions & 0 deletions topics/investigation/lev/testperform
@@ -0,0 +1,5 @@
#!/bin/sh

echo [Test Case] `basename $1`
./levels.py $1 > $1.out || exit -1
diff $1.out $1.baseline
1 change: 1 addition & 0 deletions topics/investigation/lev/tests/antlr.bgf.baseline
@@ -0,0 +1 @@
LEV = 7
1 change: 1 addition & 0 deletions topics/investigation/lev/tests/dcg.bgf.baseline
@@ -0,0 +1 @@
LEV = 7
1 change: 1 addition & 0 deletions topics/investigation/lev/tests/ecore.bgf.baseline
@@ -0,0 +1 @@
LEV = 5
1 change: 1 addition & 0 deletions topics/investigation/lev/tests/ecore2.bgf.baseline
@@ -0,0 +1 @@
LEV = 6
1 change: 1 addition & 0 deletions topics/investigation/lev/tests/fl_ldf.bgf.baseline
@@ -0,0 +1 @@
LEV = 5
1 change: 1 addition & 0 deletions topics/investigation/lev/tests/impl1.bgf.baseline
@@ -0,0 +1 @@
LEV = 83
1 change: 1 addition & 0 deletions topics/investigation/lev/tests/impl2.bgf.baseline
@@ -0,0 +1 @@
LEV = 41
1 change: 1 addition & 0 deletions topics/investigation/lev/tests/impl3.bgf.baseline
@@ -0,0 +1 @@
LEV = 35
1 change: 1 addition & 0 deletions topics/investigation/lev/tests/jaxb.bgf.baseline
@@ -0,0 +1 @@
LEV = 9
1 change: 1 addition & 0 deletions topics/investigation/lev/tests/ldf.bgf.baseline
@@ -0,0 +1 @@
LEV = 5
1 change: 1 addition & 0 deletions topics/investigation/lev/tests/om.bgf.baseline
@@ -0,0 +1 @@
LEV = 8
1 change: 1 addition & 0 deletions topics/investigation/lev/tests/read1.bgf.baseline
@@ -0,0 +1 @@
LEV = 97
1 change: 1 addition & 0 deletions topics/investigation/lev/tests/read2.bgf.baseline
@@ -0,0 +1 @@
LEV = 68
1 change: 1 addition & 0 deletions topics/investigation/lev/tests/read3.bgf.baseline
@@ -0,0 +1 @@
LEV = 75
1 change: 1 addition & 0 deletions topics/investigation/lev/tests/sdf.bgf.baseline
@@ -0,0 +1 @@
LEV = 7
1 change: 1 addition & 0 deletions topics/investigation/lev/tests/txl.bgf.baseline
@@ -0,0 +1 @@
LEV = 7
1 change: 1 addition & 0 deletions topics/investigation/lev/tests/xml.bgf.baseline
@@ -0,0 +1 @@
LEV = 7
1 change: 1 addition & 0 deletions topics/investigation/lev/tests/xsd.bgf.baseline
@@ -0,0 +1 @@
LEV = 7
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 196bbda

Please sign in to comment.