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
358e632e
Commit
358e632e
authored
May 02, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved n-ary operator definition to a constant list.
parent
dfd85838
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
4 deletions
+8
-4
src/node.py
src/node.py
+5
-2
src/strategy.py
src/strategy.py
+3
-2
No files found.
src/node.py
View file @
358e632e
...
@@ -31,6 +31,9 @@ OP_SUBSCRIPT = 8
...
@@ -31,6 +31,9 @@ OP_SUBSCRIPT = 8
OP_AND
=
9
OP_AND
=
9
OP_OR
=
10
OP_OR
=
10
# Binary operators that are considered n-ary
NARY_OPERATORS
=
[
OP_ADD
,
OP_SUB
,
OP_MUL
]
# N-ary (functions)
# N-ary (functions)
OP_INT
=
11
OP_INT
=
11
OP_INT_INDEF
=
12
OP_INT_INDEF
=
12
...
@@ -200,7 +203,7 @@ class ExpressionBase(object):
...
@@ -200,7 +203,7 @@ class ExpressionBase(object):
return
exponent
==
None
or
self
[
1
]
==
exponent
return
exponent
==
None
or
self
[
1
]
==
exponent
def
is_nary
(
self
):
def
is_nary
(
self
):
return
not
self
.
is_leaf
and
self
.
op
in
[
OP_ADD
,
OP_SUB
,
OP_MUL
]
return
not
self
.
is_leaf
and
self
.
op
in
NARY_OPERATORS
def
is_identifier
(
self
,
identifier
=
None
):
def
is_identifier
(
self
,
identifier
=
None
):
return
self
.
type
==
TYPE_IDENTIFIER
\
return
self
.
type
==
TYPE_IDENTIFIER
\
...
@@ -457,7 +460,7 @@ class ExpressionNode(Node, ExpressionBase):
...
@@ -457,7 +460,7 @@ class ExpressionNode(Node, ExpressionBase):
if not isinstance(other, ExpressionNode) or other.op != self.op:
if not isinstance(other, ExpressionNode) or other.op != self.op:
return False
return False
if self.op in
(OP_ADD, OP_MUL)
:
if self.op in
NARY_OPERATORS
:
s0 = Scope(self)
s0 = Scope(self)
s1 = set(Scope(other))
s1 = set(Scope(other))
...
...
src/strategy.py
View file @
358e632e
from
node
import
OP_NEG
from
node
import
OP_NEG
,
NARY_OPERATORS
from
rules
import
RULES
from
rules
import
RULES
from
rules.precedences
import
HIGH
,
LOW
,
RELATIVE
from
rules.precedences
import
HIGH
,
LOW
,
RELATIVE
...
@@ -70,7 +70,8 @@ def depth_possibilities(node, depth=0, parent_op=None):
...
@@ -70,7 +70,8 @@ def depth_possibilities(node, depth=0, parent_op=None):
# Add operator-specific handlers. Prevent duplicate possibilities in
# Add operator-specific handlers. Prevent duplicate possibilities in
# n-ary nodes by only executing the handlers on the outermost node of
# n-ary nodes by only executing the handlers on the outermost node of
# related nodes with the same operator
# related nodes with the same operator
if
node
.
op
!=
parent_op
and
node
.
op
in
RULES
:
if
node
.
op
in
RULES
and
(
node
.
op
!=
parent_op
\
or
node
.
op
not
in
NARY_OPERATORS
):
handlers
+=
RULES
[
node
.
op
]
handlers
+=
RULES
[
node
.
op
]
# Add negation handlers after operator-specific handlers to obtain an
# Add negation handlers after operator-specific handlers to obtain an
...
...
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