Hello Everybody...
I have a problem..
This is the code...
--------------------------------------
class Stack:
def __init__(self,e xpr):
self.stackP=[]
self.stackF=1
self.a = {}
# self.stackManag ement(expr)
if not self.a.has_key( 'rhs'):
self.a['rhs'] = 0
# self.a['rhs'] += self.popP()*sel f.popF()
def pushP(self,obj) :
self.stackP.app end(obj)
def pushF(self,obj) :
stackF=stackF*o bj
return stackF
def popP(self):
rval=0
rval=self.stack P.pop()
return rval
def popF(self,obj):
stackF/=obj
return stackF
def peekP(self):
rval=0
rval= self.stackP[-1]
return rval
def peekF(self):
rval=0
rval= self.stackF[-1]
return rval
def stackManagement (self,expr):
#Determine the next symbol
if expr.__class__= =E:
self.pushP(expr .operator)
self.stackManag ement(expr.left )
self.stackManag ement(expr.righ t)
else:
self.pushP(expr )
if len(self.stackP ) > 1:
s = self.peekP()
prev = self.stackP[-2]
if prev in ('*','+','/','-'):
if prev in ('*','/'):
self.pushF(self .peekF()*s)
else:#stackP[-3] must be an operator.
top=self.popP()
mid =self.popP()
op=self.popP()
if op == '*':
if top.__class__== V:
self.a += self.popF(self. stackF)
self.stackManag ement(0)
else:
self.popF(self. stackF)
self.stackManag ement(mid*top)
if op == '+':
if top.__class__== V:
self.a+= self.peekF()
self.stackManag ement(0)
else:
self.stackManag ement(mid+top)
if op == '-':
if top.__class__== V:
self.a -= self.peekF()
self.stackManag ement(0)
else:
self.stackManag ement(mid-top)
if op == '/':
if top.__class__== V:
self.a /= self.popF(self. stackF)/(mid**2)
self.stackManag ement(0)
else:
self.popF(self. stackF)
self.stackManag ement(top/mid)
else:
self.a['rhs'] += self.popP(self. stackP)*self.po pF(self.stackF)
and I'm giveing the following calls...
---------------------------
from expression import *
from generation import*
(x,y,z) = (V(),V(),V()) # making instances of Variable class
e1=x+y+z
s=Stack(e1)
s.stackManageme nt(e1)
----------------------------------------------
I'm getting the following error TypeError: unsubscriptable object...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "generation.py" , line 175, in stackManagement
self.stackManag ement(expr.left )
File "generation.py" , line 176, in stackManagement
self.stackManag ement(expr.righ t)
File "generation.py" , line 199, in stackManagement
self.a+= self.peekF()
File "generation.py" , line 168, in peekF
rval= self.stackF[-1]
-------------------------------------
I 'm at my wit ends..
Can anyone help...
Thx in advance
I have a problem..
This is the code...
--------------------------------------
class Stack:
def __init__(self,e xpr):
self.stackP=[]
self.stackF=1
self.a = {}
# self.stackManag ement(expr)
if not self.a.has_key( 'rhs'):
self.a['rhs'] = 0
# self.a['rhs'] += self.popP()*sel f.popF()
def pushP(self,obj) :
self.stackP.app end(obj)
def pushF(self,obj) :
stackF=stackF*o bj
return stackF
def popP(self):
rval=0
rval=self.stack P.pop()
return rval
def popF(self,obj):
stackF/=obj
return stackF
def peekP(self):
rval=0
rval= self.stackP[-1]
return rval
def peekF(self):
rval=0
rval= self.stackF[-1]
return rval
def stackManagement (self,expr):
#Determine the next symbol
if expr.__class__= =E:
self.pushP(expr .operator)
self.stackManag ement(expr.left )
self.stackManag ement(expr.righ t)
else:
self.pushP(expr )
if len(self.stackP ) > 1:
s = self.peekP()
prev = self.stackP[-2]
if prev in ('*','+','/','-'):
if prev in ('*','/'):
self.pushF(self .peekF()*s)
else:#stackP[-3] must be an operator.
top=self.popP()
mid =self.popP()
op=self.popP()
if op == '*':
if top.__class__== V:
self.a += self.popF(self. stackF)
self.stackManag ement(0)
else:
self.popF(self. stackF)
self.stackManag ement(mid*top)
if op == '+':
if top.__class__== V:
self.a+= self.peekF()
self.stackManag ement(0)
else:
self.stackManag ement(mid+top)
if op == '-':
if top.__class__== V:
self.a -= self.peekF()
self.stackManag ement(0)
else:
self.stackManag ement(mid-top)
if op == '/':
if top.__class__== V:
self.a /= self.popF(self. stackF)/(mid**2)
self.stackManag ement(0)
else:
self.popF(self. stackF)
self.stackManag ement(top/mid)
else:
self.a['rhs'] += self.popP(self. stackP)*self.po pF(self.stackF)
and I'm giveing the following calls...
---------------------------
from expression import *
from generation import*
(x,y,z) = (V(),V(),V()) # making instances of Variable class
e1=x+y+z
s=Stack(e1)
s.stackManageme nt(e1)
----------------------------------------------
I'm getting the following error TypeError: unsubscriptable object...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "generation.py" , line 175, in stackManagement
self.stackManag ement(expr.left )
File "generation.py" , line 176, in stackManagement
self.stackManag ement(expr.righ t)
File "generation.py" , line 199, in stackManagement
self.a+= self.peekF()
File "generation.py" , line 168, in peekF
rval= self.stackF[-1]
-------------------------------------
I 'm at my wit ends..
Can anyone help...
Thx in advance
Comment