Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
a new component that generates a dependency graph for a given BGF
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@482 ab42f6e0-554d-0410-b580-99e487e6eeb2
- Loading branch information
1 parent
3f06033
commit 8e8be3a
Showing
3 changed files
with
49 additions
and
7 deletions.
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,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 |
This file was deleted.
Oops, something went wrong.
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,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) |