Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
graph_drawing
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
graph_drawing
Commits
bfd64e64
Commit
bfd64e64
authored
Dec 09, 2011
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed 'assoc' to 'prec', because it's precedence.
parent
a34e4894
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
6 deletions
+7
-6
line.py
line.py
+7
-6
No files found.
line.py
View file @
bfd64e64
...
@@ -36,7 +36,8 @@ def generate_line(root):
...
@@ -36,7 +36,8 @@ def generate_line(root):
(
'*'
,
'/'
,
'mod'
),
(
'*'
,
'/'
,
'mod'
),
(
'^'
,
)
(
'^'
,
)
]
]
max_assoc
=
len
(
operators
)
max_pred
=
len
(
operators
)
def
is_operator
(
node
):
def
is_operator
(
node
):
"""
"""
...
@@ -47,9 +48,9 @@ def generate_line(root):
...
@@ -47,9 +48,9 @@ def generate_line(root):
return
reduce
(
either
,
map
(
lambda
x
:
label
in
x
,
operators
))
return
reduce
(
either
,
map
(
lambda
x
:
label
in
x
,
operators
))
def
assoc
(
node
):
def
pred
(
node
):
"""
"""
Get the
associativity
of an operator node.
Get the
precedence
of an operator node.
"""
"""
# Check binary and n-ary operators
# Check binary and n-ary operators
if
not
isinstance
(
node
,
Leaf
)
and
len
(
node
)
>
1
:
if
not
isinstance
(
node
,
Leaf
)
and
len
(
node
)
>
1
:
...
@@ -60,7 +61,7 @@ def generate_line(root):
...
@@ -60,7 +61,7 @@ def generate_line(root):
return
i
return
i
# Unary operator and leaves have highest precedence
# Unary operator and leaves have highest precedence
return
max_
assoc
return
max_
pred
def
traverse
(
node
):
def
traverse
(
node
):
"""
"""
...
@@ -84,7 +85,7 @@ def generate_line(root):
...
@@ -84,7 +85,7 @@ def generate_line(root):
s
+=
traverse
(
node
[
0
])
s
+=
traverse
(
node
[
0
])
else
:
else
:
# N-ary operator
# N-ary operator
node_
assoc
=
assoc
(
node
)
node_
pred
=
pred
(
node
)
e
=
[]
e
=
[]
for
child
in
node
:
for
child
in
node
:
...
@@ -92,7 +93,7 @@ def generate_line(root):
...
@@ -92,7 +93,7 @@ def generate_line(root):
# Check if there is an precedence conflict.
# Check if there is an precedence conflict.
# If so, add parentheses
# If so, add parentheses
if
assoc
(
child
)
<
node_assoc
:
if
pred
(
child
)
<
node_pred
:
exp
=
'('
+
exp
+
')'
exp
=
'('
+
exp
+
')'
e
.
append
(
exp
)
e
.
append
(
exp
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment