loic.delpui
10 months ago
commit
3c175eed69
1 changed files with 33 additions and 0 deletions
@ -0,0 +1,33 @@ |
|||||
|
from Pile import Pile_chaine |
||||
|
|
||||
|
class Expression: |
||||
|
def __init__(self, valeur, gauche, droit): |
||||
|
self.valeur = valeur |
||||
|
self.gauche = gauche |
||||
|
self.droit = droit |
||||
|
|
||||
|
def evalue(self): |
||||
|
if self == None: |
||||
|
return |
||||
|
if self.gauche != None: |
||||
|
self.gauche.evalue() |
||||
|
if self.droit != None: |
||||
|
self.droit.evalue() |
||||
|
if self.valeur == "+": |
||||
|
self.valeur = self.gauche.valeur + self.droit.valeur |
||||
|
if self.valeur == "*": |
||||
|
self.valeur = self.gauche.valeur * self.droit.valeur |
||||
|
|
||||
|
def __str__(self): |
||||
|
pass |
||||
|
|
||||
|
exp = Expression('*', |
||||
|
Expression(6, None, None), |
||||
|
Expression('+', |
||||
|
Expression(4, None, None), |
||||
|
Expression(3, None, None) |
||||
|
) |
||||
|
) |
||||
|
|
||||
|
exp.evalue() |
||||
|
print(exp.valeur) |
Loading…
Reference in new issue