Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
racr-mquat
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
René Schöne
racr-mquat
Commits
9c320949
Commit
9c320949
authored
8 years ago
by
René Schöne
Browse files
Options
Downloads
Patches
Plain Diff
First version for generation of graphviz representation of the grammar
parent
7ff40d14
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+2
-0
2 additions, 0 deletions
.gitignore
fabfile.py
+1
-0
1 addition, 0 deletions
fabfile.py
mkdot.py
+52
-0
52 additions, 0 deletions
mkdot.py
with
55 additions
and
0 deletions
.gitignore
+
2
−
0
View file @
9c320949
...
...
@@ -5,6 +5,8 @@ larceny-bin
**/*.scm~
*.class
*.out
*.dot
*.dot.pdf
# Test and measurment directories, files and output
test
...
...
This diff is collapsed.
Click to expand it.
fabfile.py
+
1
−
0
View file @
9c320949
...
...
@@ -6,6 +6,7 @@ import properties, utils, install, sockets
import
ilp_test
as
test
import
ilp_measurement
as
measure
import
ilp_check
as
check
import
mkdot
import
os
from
fabric.api
import
local
,
task
,
get
,
hosts
,
run
...
...
This diff is collapsed.
Click to expand it.
mkdot.py
0 → 100644
+
52
−
0
View file @
9c320949
from
utils
import
local_quiet
try
:
from
fabric.api
import
task
except
ImportError
:
from
fabric_workaround
import
task
header
=
'
digraph G {
\n
node [shape =
"
record
"
]
\n
'
footer
=
'
\n
}
'
@task
(
default
=
True
)
def
convert
(
f
,
output
=
None
):
if
output
is
None
:
output
=
f
+
"
.dot
"
with
open
(
f
)
as
fd
:
lines
=
fd
.
readlines
()
with
open
(
output
,
'
w
'
)
as
fd
:
fd
.
write
(
header
)
for
line
in
[
l
.
strip
()
for
l
in
lines
if
l
.
strip
().
startswith
(
'
(ast-rule
'
)]:
rule
=
line
[
line
.
index
(
'
(ast-rule
\'
'
)
+
11
:
line
.
rindex
(
'
)
'
)]
# inheritance-arrows are "arrowhead = empty"
print
rule
lhand
,
rhand
=
rule
.
split
(
'
->
'
)
superclass
=
lhand
[
lhand
.
index
(
'
:
'
)
+
1
:]
if
'
:
'
in
lhand
else
None
if
superclass
:
lhand
=
lhand
[:
lhand
.
index
(
'
:
'
)]
children
=
rhand
.
split
(
'
-
'
)
if
rhand
.
strip
()
else
[]
terminals
=
filter
(
lambda
x
:
x
.
islower
(),
children
)
nonterminals
=
filter
(
lambda
x
:
not
x
.
islower
(),
children
)
# define the node of the left hand side
fd
.
write
(
'
{0} [label =
"
{{{0} | {1}}}
"
]
\n
'
.
format
(
lhand
,
'
|
'
.
join
(
terminals
)))
# add inheritance
if
superclass
:
fd
.
write
(
'
{0} -> {1} [arrowhead =
"
empty
"
]
\n
'
.
format
(
lhand
,
superclass
))
# add nonterminal children
for
child
in
nonterminals
:
print
'
child:
'
,
child
options
=
''
# handle contexts
if
'
<
'
in
child
:
child
,
context
=
child
.
split
(
'
<
'
)
options
=
'
label =
"
{0}
"'
.
format
(
context
)
# handle lists
if
child
.
endswith
(
'
*
'
):
child
=
child
[:
-
1
]
if
options
:
# it had a context
options
=
'
headlabel =
"
{0}
"
, label =
"
{1}
"'
.
format
(
'
*
'
,
context
)
else
:
options
=
'
headlabel =
"
*
"'
fd
.
write
(
'
{0} -> {1}[{2}]
\n
'
.
format
(
lhand
,
child
,
options
))
fd
.
write
(
footer
)
local_quiet
(
'
dot {0} -Tpdf > {0}.pdf
'
.
format
(
output
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment