Skip to content

Commit

Permalink
a new component that generates a dependency graph for a given BGF
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@482 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Feb 20, 2009
1 parent 3f06033 commit 8e8be3a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
19 changes: 19 additions & 0 deletions shared/tools/plotbgf
@@ -0,0 +1,19 @@
#!/bin/sh
LOCAL=${PWD}
cd `dirname $0`
cd ../..
SLPS=${PWD}
cd ${LOCAL}

if [ $# -lt 1 ]; then
echo "This tool plots a nonterminal dependency graph for a BGF."
echo "Usage: plotbgf <input-bgf-document> [<ignore-nonterminal> ...]"
exit 1
elif [ ! -r $1 ]; then
echo "Oops: $1 not found or not readable."
exit 1
fi

python ${SLPS}/topics/presentation/analyses/bgf_dependency.py $* >`basename $1 .bgf`.dot
dot -Tpdf `basename $1 .bgf`.dot -o `basename $1 .bgf`.pdf
rm -f `basename $1 .bgf`.dot
7 changes: 0 additions & 7 deletions topics/convergence/bdt/Makefile

This file was deleted.

30 changes: 30 additions & 0 deletions topics/presentation/analyses/bgf_dependency.py
@@ -0,0 +1,30 @@
#!/usr/bin/python
import sys
import elementtree.ElementTree as ET

bgfns = 'http://planet-sl.org/bgf'
ET._namespace_map[bgfns] = 'bgf'

if __name__ == "__main__":
if len(sys.argv) < 2:
print 'This tool plots a dependency graph of a BGF grammar.'
print 'Usage:'
print ' plotbgf <bgf-file> [<ignore-nonterminal> ...]'
sys.exit(1)
bgf = ET.parse(sys.argv[1])
ignore = []
for int in sys.argv[2:]:
ignore.append(int)
depgraph = []
for p in bgf.findall('//{'+bgfns+'}production'):
n1 = p.findtext('nonterminal')
for nt in p.findall('{'+bgfns+'}expression//nonterminal'):
n2 = nt.text
if (n1,n2) not in depgraph:
if n1 not in ignore and n2 not in ignore:
depgraph.append((n1,n2))
print 'digraph generated{'
for ns in depgraph:
print ns[0],'->',ns[1],';'
print '}'
sys.exit(0)

0 comments on commit 8e8be3a

Please sign in to comment.