Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
prm2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Mareš
prm2
Commits
e7124f5b
Commit
e7124f5b
authored
5 years ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Výrazy: Ještě objektová verze s dědičností
parent
2289c465
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
06-vyrazy/objektove.py
+66
-0
66 additions, 0 deletions
06-vyrazy/objektove.py
with
66 additions
and
0 deletions
06-vyrazy/objektove.py
0 → 100755
+
66
−
0
View file @
e7124f5b
#!/usr/bin/python3
class
Node
:
def
eval
(
self
):
raise
NotImplemented
()
class
NumNode
(
Node
):
def
__init__
(
self
,
x
):
self
.
value
=
x
def
__str__
(
self
):
return
str
(
self
.
value
)
def
eval
(
self
):
return
self
.
value
class
BinaryNode
(
Node
):
def
__init__
(
self
,
left
,
right
):
self
.
left
=
left
self
.
right
=
right
class
AddNode
(
BinaryNode
):
def
__str__
(
self
):
return
'
(
'
+
str
(
self
.
left
)
+
'
+
'
+
str
(
self
.
right
)
+
'
)
'
def
eval
(
self
):
return
self
.
left
.
eval
()
+
self
.
right
.
eval
()
class
SubNode
(
BinaryNode
):
def
__str__
(
self
):
return
'
(
'
+
str
(
self
.
left
)
+
'
-
'
+
str
(
self
.
right
)
+
'
)
'
def
eval
(
self
):
return
self
.
left
.
eval
()
-
self
.
right
.
eval
()
class
MulNode
(
BinaryNode
):
def
__str__
(
self
):
return
'
(
'
+
str
(
self
.
left
)
+
'
*
'
+
str
(
self
.
right
)
+
'
)
'
def
eval
(
self
):
return
self
.
left
.
eval
()
*
self
.
right
.
eval
()
class
DivNode
(
BinaryNode
):
def
__str__
(
self
):
return
'
(
'
+
str
(
self
.
left
)
+
'
/
'
+
str
(
self
.
right
)
+
'
)
'
def
eval
(
self
):
return
self
.
left
.
eval
()
//
self
.
right
.
eval
()
x
=
AddNode
(
MulNode
(
NumNode
(
3
),
NumNode
(
4
)),
SubNode
(
NumNode
(
5
),
NumNode
(
6
)))
print
(
x
)
print
(
x
.
eval
())
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment