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
fc774582
Commit
fc774582
authored
Dec 08, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of kompiler.org:trs
parents
513c04f3
7c83ea25
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
28 additions
and
8 deletions
+28
-8
external/graph_drawing
external/graph_drawing
+1
-1
external/pybison
external/pybison
+1
-1
external/rules.mk
external/rules.mk
+1
-0
src/parser.py
src/parser.py
+8
-5
tests/parser.py
tests/parser.py
+1
-1
tests/test_exception.py
tests/test_exception.py
+16
-0
No files found.
graph_drawing
@
ec0a7e59
Subproject commit
45bee0e4fe53619176d85fc0bc5ae3b40d99716d
Subproject commit
ec0a7e59d3251d1e11d2efc877a77f236a7885b5
pybison
@
d83b7274
Subproject commit
260359e31ceeaa46d26a26303e08cda37c7578f5
Subproject commit
d83b7274f5a331c7c5611974c9576495d929c234
external/rules.mk
View file @
fc774582
...
...
@@ -28,4 +28,5 @@ endif
$(b)pybison/%.c
:
$(d)pybison/src/pyrex/%.pyx
$(py2c)
-o
$@
$<
$(RM)
$
(
@D
)
/
*
.so
src/parser.py
View file @
fc774582
...
...
@@ -63,6 +63,9 @@ class Parser(BisonParser):
# override default read method with a version that prompts for input
# ------------------------------------------------------------------
def
read
(
self
,
nbytes
):
if
self
.
file
==
sys
.
stdin
and
self
.
file
.
closed
:
return
''
try
:
return
raw_input
(
'>>> '
)
+
'
\
n
'
except
EOFError
:
...
...
@@ -187,24 +190,24 @@ class Parser(BisonParser):
"""
if
option
in
[
0
,
1
]:
# rule: exp IDENTIFIER | exp NUMBER
#
NOTE
: xy -> x*y
#
NOTE
: (x)4 -> x*4
#
example
: xy -> x*y
#
example
: (x)4 -> x*4
val
=
int
(
values
[
1
])
if
option
==
1
else
values
[
1
]
return
Node
(
'*'
,
*
(
combine
(
'*'
,
values
[
0
])
+
[
Leaf
(
val
)]))
if
option
==
2
:
# rule: exp LPAREN exp RPAREN
#
NOTE
: x(y) -> x*(y)
#
example
: x(y) -> x*(y)
return
Node
(
'*'
,
*
(
combine
(
'*'
,
values
[
0
])
+
combine
(
'*'
,
values
[
2
])))
if
option
==
3
:
#
NOTE: x4 -> x
^4
#
example: xy4 -> x*y
^4
identifier
,
exponent
=
list
(
values
[
1
])
node
=
Node
(
'^'
,
Leaf
(
identifier
),
Leaf
(
int
(
exponent
)))
return
Node
(
'*'
,
values
[
0
],
node
)
if
option
==
4
:
#
NOTE
: x4 -> x^4
#
example
: x4 -> x^4
identifier
,
exponent
=
list
(
values
[
0
])
return
Node
(
'^'
,
Leaf
(
identifier
),
Leaf
(
int
(
exponent
)))
...
...
tests/parser.py
View file @
fc774582
...
...
@@ -83,7 +83,7 @@ def run_expressions(base_class, expressions, keepfiles=1, fail=True,
try
:
res
=
parser
.
run
([
exp
])
assert
res
==
out
except
:
except
:
# pragma: nocover
if
not
silent
:
print
>>
sys
.
stderr
,
'error: %s = %s, but expected: %s'
\
%
(
exp
,
str
(
res
),
str
(
out
))
...
...
tests/test_exception.py
0 → 100644
View file @
fc774582
# vim: set fileencoding=utf-8 :
import
unittest
from
src.parser
import
Parser
from
tests.parser
import
ParserWrapper
,
run_expressions
class
TestException
(
unittest
.
TestCase
):
def
test_raise
(
self
):
try
:
ParserWrapper
(
Parser
).
run
([
'raise'
])
except
RuntimeError
:
return
# pragma: nocover
raise
AssertionError
(
'Expected a raised RuntimeError!'
)
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