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
70714ec0
Commit
70714ec0
authored
Mar 28, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added logical operators.
Conflicts: line.py
parent
d3feae46
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
7 deletions
+18
-7
line.py
line.py
+11
-7
tests/test_line.py
tests/test_line.py
+7
-0
No files found.
line.py
View file @
70714ec0
from
traverse
import
traverse_depth_first
OPERATORS
=
[
(
'+'
,
'-'
),
(
'*'
,
'/'
,
'mod'
),
(
'^'
,
'_'
)
]
OPERATORS
=
(
(
'vv'
,
),
(
'^^'
,
),
(
'='
,
),
(
'+'
,
'-'
),
(
'*'
,
'/'
,
'mod'
),
(
'^'
,
'_'
),
)
NEG_PRED
=
3
MAX_PRED
=
len
(
OPERATORS
)
...
...
@@ -110,7 +114,7 @@ def generate_line(root):
# -3 * 4
# --a
if
value
.
is_leaf
\
or
not
' '
in
content
[
value
]
or
pred
(
value
)
>
0
:
or
not
' '
in
content
[
value
]
or
pred
(
value
)
>
NEG_PRED
:
return
op
+
content
[
value
]
# -(a + b)
...
...
tests/test_line.py
View file @
70714ec0
...
...
@@ -25,6 +25,13 @@ class TestLine(unittest.TestCase):
times
=
N
(
'*'
,
plus
,
plus
)
self
.
assertEquals
(
generate_line
(
times
),
'(1 + 2)(1 + 2)'
)
def
test_parentheses_no_equal_precedence
(
self
):
a
,
b
,
c
=
L
(
'a'
),
L
(
'b'
),
L
(
'c'
)
line
=
N
(
'vv'
,
a
,
N
(
'^^'
,
b
,
c
))
self
.
assertEquals
(
generate_line
(
line
),
'a vv b ^^ c'
)
line
=
N
(
'^^'
,
a
,
N
(
'vv'
,
b
,
c
))
self
.
assertEquals
(
generate_line
(
line
),
'a ^^ (b vv c)'
)
def
test_parentheses_equal_precedence_right
(
self
):
l0
,
l1
,
l2
,
l3
=
L
(
1
),
L
(
2
),
L
(
3
),
L
(
4
)
plus
=
N
(
'+'
,
l1
,
l2
)
...
...
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