Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
trs
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
trs
Commits
3c9a4762
Commit
3c9a4762
authored
Jan 24, 2012
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of kompiler.org:trs
parents
1a7cebab
805a9166
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
7 additions
and
4 deletions
+7
-4
src/rules/fractions.py
src/rules/fractions.py
+4
-3
src/rules/numerics.py
src/rules/numerics.py
+1
-1
tests/test_node.py
tests/test_node.py
+1
-0
tests/test_rules_numerics.py
tests/test_rules_numerics.py
+1
-0
No files found.
src/rules/fractions.py
View file @
3c9a4762
...
...
@@ -140,9 +140,10 @@ MESSAGES[equalize_denominators] = _('Equalize the denominators of division'
def
add_nominators
(
root
,
args
):
"""
a / b + c / b -> (a + c) / b
a / -b + c / -b -> (a + c) / -b
a / -b - c / -b -> (a - c) / -b
a / b + c / b -> (a + c) / b
a / b - c / b -> (a - c) / b
-(a / b) + c / b -> -((a + c) / b)
-(a / b) - c / b -> (c - a) / -b
"""
# TODO: is 'add' Appropriate when rewriting to "(a + (-c)) / b"?
ab
,
cb
=
args
...
...
src/rules/numerics.py
View file @
3c9a4762
...
...
@@ -18,7 +18,7 @@ def add_numerics(root, args):
n0
,
n1
,
c0
,
c1
=
args
if
c0
.
is_op
(
OP_NEG
):
c0
=
(
-
c0
[
0
].
value
)
c0
=
-
c0
[
0
].
value
else
:
c0
=
c0
.
value
...
...
tests/test_node.py
View file @
3c9a4762
...
...
@@ -34,6 +34,7 @@ class TestNode(RulesTestCase):
self
.
assertTrue
(
N
(
'+'
,
*
self
.
l
[:
2
]).
is_op_or_negated
(
OP_ADD
))
self
.
assertTrue
(
N
(
'-'
,
N
(
'+'
,
*
self
.
l
[:
2
])).
is_op_or_negated
(
OP_ADD
))
self
.
assertFalse
(
N
(
'-'
,
*
self
.
l
[:
2
]).
is_op_or_negated
(
OP_ADD
))
self
.
assertFalse
(
self
.
l
[
0
].
is_op_or_negated
(
OP_ADD
))
def
test_is_leaf
(
self
):
self
.
assertTrue
(
L
(
2
).
is_leaf
())
...
...
tests/test_rules_numerics.py
View file @
3c9a4762
...
...
@@ -17,6 +17,7 @@ class TestRulesNumerics(RulesTestCase):
def
test_add_numerics_negations
(
self
):
l0
,
a
,
l1
=
tree
(
'1,a,2'
)
self
.
assertEqual
(
add_numerics
(
-
l0
+
l1
,
(
-
l0
,
l1
,
-
L
(
1
),
L
(
2
))),
1
)
self
.
assertEqual
(
add_numerics
(
l0
+
-
l1
,
(
l0
,
-
l1
,
L
(
1
),
-
L
(
2
))),
-
1
)
self
.
assertEqual
(
add_numerics
(
l0
+
a
+
-
l1
,
(
l0
,
-
l1
,
L
(
1
),
-
L
(
2
))),
L
(
-
1
)
+
a
)
...
...
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