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
76b7149d
Commit
76b7149d
authored
Feb 18, 2012
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Trying to fix the negation AssertionError (work in progress).
parent
28644d89
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
8 deletions
+27
-8
src/node.py
src/node.py
+0
-3
src/parser.py
src/parser.py
+13
-3
src/rules/negation.py
src/rules/negation.py
+4
-2
tests/test_parser.py
tests/test_parser.py
+10
-0
No files found.
src/node.py
View file @
76b7149d
...
@@ -165,9 +165,6 @@ class ExpressionNode(Node, ExpressionBase):
...
@@ -165,9 +165,6 @@ class ExpressionNode(Node, ExpressionBase):
self
.
type
=
TYPE_OPERATOR
self
.
type
=
TYPE_OPERATOR
self
.
op
=
OP_MAP
[
args
[
0
]]
self
.
op
=
OP_MAP
[
args
[
0
]]
if
hasattr
(
self
.
op
,
'__call__'
):
self
.
op
=
self
.
op
(
args
)
def
__str__
(
self
):
# pragma: nocover
def
__str__
(
self
):
# pragma: nocover
return
generate_line
(
self
)
return
generate_line
(
self
)
...
...
src/parser.py
View file @
76b7149d
...
@@ -74,13 +74,20 @@ class Parser(BisonParser):
...
@@ -74,13 +74,20 @@ class Parser(BisonParser):
BisonParser
.
__init__
(
self
,
**
kwargs
)
BisonParser
.
__init__
(
self
,
**
kwargs
)
self
.
interactive
=
kwargs
.
get
(
'interactive'
,
0
)
self
.
interactive
=
kwargs
.
get
(
'interactive'
,
0
)
self
.
timeout
=
kwargs
.
get
(
'timeout'
,
0
)
self
.
timeout
=
kwargs
.
get
(
'timeout'
,
0
)
self
.
possibilities
=
self
.
last_possibilities
=
[]
self
.
reset
()
def
reset
(
self
):
self
.
read_buffer
=
''
self
.
read_buffer
=
''
self
.
read_queue
=
Queue
.
Queue
()
self
.
read_queue
=
Queue
.
Queue
()
self
.
subtree_map
=
{}
self
.
subtree_map
=
{}
self
.
root_node
=
None
self
.
root_node
=
None
self
.
possibilities
=
self
.
last_possibilities
=
[]
def
run
(
self
,
*
args
,
**
kwargs
):
self
.
reset
()
return
super
(
Parser
,
self
).
run
(
*
args
,
**
kwargs
)
# Override default read method with a version that prompts for input.
# Override default read method with a version that prompts for input.
def
read
(
self
,
nbytes
):
def
read
(
self
,
nbytes
):
...
@@ -201,6 +208,7 @@ class Parser(BisonParser):
...
@@ -201,6 +208,7 @@ class Parser(BisonParser):
handlers
=
[]
handlers
=
[]
if
retval
.
negated
:
if
retval
.
negated
:
print
retval
,
'OP_NEG'
,
retval
.
negated
handlers
+=
RULES
[
OP_NEG
]
handlers
+=
RULES
[
OP_NEG
]
for
handler
in
handlers
:
for
handler
in
handlers
:
...
@@ -372,6 +380,10 @@ class Parser(BisonParser):
...
@@ -372,6 +380,10 @@ class Parser(BisonParser):
if
option
==
4
:
# rule: exp MINUS exp
if
option
==
4
:
# rule: exp MINUS exp
node
=
values
[
2
]
node
=
values
[
2
]
node
.
negated
+=
1
node
.
negated
+=
1
# Explicit call the hook handler on the created unary negation.
node
=
self
.
hook_handler
(
'binary'
,
4
,
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".'
...
@@ -415,8 +427,6 @@ class Parser(BisonParser):
...
@@ -415,8 +427,6 @@ class Parser(BisonParser):
yylloc.first_column = yycolumn; \
yylloc.first_column = yycolumn; \
yylloc.last_column = yycolumn + yyleng; \
yylloc.last_column = yycolumn + yyleng; \
yycolumn += yyleng;
yycolumn += yyleng;
/*[a-zA-Z][0-9]+ { returntoken(CONCAT_POW); }*/
%}
%}
%option yylineno
%option yylineno
...
...
src/rules/negation.py
View file @
76b7149d
from
..node
import
Scope
,
nary_node
,
OP_ADD
,
OP_MUL
,
OP_DIV
from
..node
import
Scope
,
OP_ADD
,
OP_MUL
,
OP_DIV
,
TYPE_OPERATOR
from
..possibilities
import
Possibility
as
P
,
MESSAGES
from
..possibilities
import
Possibility
as
P
,
MESSAGES
from
..translate
import
_
from
..translate
import
_
...
@@ -46,7 +46,9 @@ def match_negate_polynome(node):
...
@@ -46,7 +46,9 @@ def match_negate_polynome(node):
--a -> a
--a -> a
-(a + b) -> -a - b
-(a + b) -> -a - b
"""
"""
assert
node
.
negated
if
not
node
.
negated
and
node
.
type
==
TYPE_OPERATOR
:
print
'operator
\
'
s negated childs:'
,
[
n
.
negated
for
n
in
node
]
assert
node
.
negated
,
str
(
node
.
negated
)
+
'; '
+
str
(
node
)
p
=
[]
p
=
[]
...
...
tests/test_parser.py
View file @
76b7149d
...
@@ -23,3 +23,13 @@ class TestParser(unittest.TestCase):
...
@@ -23,3 +23,13 @@ class TestParser(unittest.TestCase):
def
test_line
(
self
):
def
test_line
(
self
):
self
.
assertEqual
(
line
(
Parser
,
'4-a'
),
'4 - a'
)
self
.
assertEqual
(
line
(
Parser
,
'4-a'
),
'4 - a'
)
def
test_reset_after_failure
(
self
):
parser
=
ParserWrapper
(
Parser
)
parser
.
run
([
'-(3a+6b)'
])
possibilities
=
parser
.
parser
.
possibilities
print
possibilities
parser
.
run
([
'5+2*6'
])
possibilities
=
parser
.
parser
.
possibilities
print
possibilities
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