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
7b75040e
Commit
7b75040e
authored
Jan 25, 2012
by
Sander Mathijs van Veen
Committed by
Sander Mathijs van Veen
Feb 15, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use 'negated' attribute instead of a negation node.
Negation of node or leaf increases negated value.
parent
6c450559
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
8 deletions
+11
-8
src/node.py
src/node.py
+6
-2
src/parser.py
src/parser.py
+5
-6
No files found.
src/node.py
View file @
7b75040e
...
@@ -60,6 +60,10 @@ def to_expression(obj):
...
@@ -60,6 +60,10 @@ def to_expression(obj):
class
ExpressionBase
(
object
):
class
ExpressionBase
(
object
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
negated
=
0
def
clone
(
self
):
def
clone
(
self
):
return
copy
.
deepcopy
(
self
)
return
copy
.
deepcopy
(
self
)
...
@@ -165,7 +169,8 @@ class ExpressionBase(object):
...
@@ -165,7 +169,8 @@ class ExpressionBase(object):
return
ExpressionNode
(
'^'
,
self
,
to_expression
(
other
))
return
ExpressionNode
(
'^'
,
self
,
to_expression
(
other
))
def
__neg__
(
self
):
def
__neg__
(
self
):
return
ExpressionNode
(
'-'
,
self
)
self
.
negated
+=
1
return
self
class
ExpressionNode
(
Node
,
ExpressionBase
):
class
ExpressionNode
(
Node
,
ExpressionBase
):
...
@@ -309,7 +314,6 @@ class ExpressionNode(Node, ExpressionBase):
...
@@ -309,7 +314,6 @@ class ExpressionNode(Node, ExpressionBase):
class
ExpressionLeaf
(
Leaf
,
ExpressionBase
):
class
ExpressionLeaf
(
Leaf
,
ExpressionBase
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
ExpressionLeaf
,
self
).
__init__
(
*
args
,
**
kwargs
)
super
(
ExpressionLeaf
,
self
).
__init__
(
*
args
,
**
kwargs
)
self
.
type
=
TYPE_MAP
[
type
(
args
[
0
])]
self
.
type
=
TYPE_MAP
[
type
(
args
[
0
])]
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
...
...
src/parser.py
View file @
7b75040e
...
@@ -343,7 +343,9 @@ class Parser(BisonParser):
...
@@ -343,7 +343,9 @@ class Parser(BisonParser):
"""
"""
if
option
==
0
:
# rule: NEG exp
if
option
==
0
:
# rule: NEG exp
return
Node
(
'-'
,
values
[
1
])
node
=
values
[
1
]
node
.
negated
+=
1
return
node
raise
BisonSyntaxError
(
'Unsupported option %d in target "%s".'
raise
BisonSyntaxError
(
'Unsupported option %d in target "%s".'
%
(
option
,
target
))
# pragma: nocover
%
(
option
,
target
))
# pragma: nocover
...
@@ -361,11 +363,8 @@ class Parser(BisonParser):
...
@@ -361,11 +363,8 @@ class Parser(BisonParser):
return
Node
(
values
[
1
],
values
[
0
],
values
[
2
])
return
Node
(
values
[
1
],
values
[
0
],
values
[
2
])
if
option
==
4
:
# rule: exp MINUS exp
if
option
==
4
:
# rule: exp MINUS exp
# It is necessary to call the hook_handler here explicitly, since
node
=
values
[
2
]
# the minus operator is internally represented as two nodes (unary
node
.
negated
+=
1
# negation and binary plus).
node
=
Node
(
'-'
,
values
[
2
])
node
=
self
.
hook_handler
(
target
,
option
,
names
,
values
,
node
)
return
Node
(
'+'
,
values
[
0
],
node
)
return
Node
(
'+'
,
values
[
0
],
node
)
raise
BisonSyntaxError
(
'Unsupported option %d in target "%s".'
raise
BisonSyntaxError
(
'Unsupported option %d in target "%s".'
...
...
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