How to get the refernces Stored.

Discussion in 'Python' started by Balaji, Apr 23, 2004.

  1. Balaji

    Balaji Guest

    import __main__

    tempbuffer= None

    permbuffer={}

    class E:
    def __init__(self):
    # print id(self)
    self.hasVar = False


    def doOperation(self,op,rightOperand):
    e = E()
    if self.__class__ == E:
    e.hasVar = self.hasVar
    elif self.__class__ == V or rightOperand.__class__ == V or \
    (rightOperand.__class__ == E and rightOperand.hasVar == True):
    e.hasVar = True
    e.operator = op
    e.left = self
    e.right = rightOperand
    global tempbuffer
    global permbuffer
    print "bll"
    f = copy.copy(e)
    print f
    r =findNonTempBufferRef(tempbuffer)
    print r
    if r != 'tempbuffer':
    print "hello"
    permbuffer[r] =tempbuffer
    tempbuffer = f
    return e


    def relationalOperators(self,op,rightOperand):
    print self,rightOperand
    e=E()
    e.operator =op
    e.left=self
    e.right=rightOperand
    return e

    def __neg__(self):
    return self

    def __radd__(self,e2):
    return self.doOperation('+',e2)

    def __add__(self,e2):
    return self.doOperation('+',e2)

    class V(E):
    """ This is a variable for MPY"""
    def __init__(self):
    print "V",
    E.__init__(self)
    self.hasVar = True
    self.val = None

    def __str__(self):
    if self.val:
    # print "self.val *****"
    return str(self.val)
    else:
    return findRefTo(self) or "MPY Error! Printing unnamed variable."



    def findRefTo(obj):
    import expression # Needed to get access to main.
    vnames = vars(__main__)
    for name in vnames.keys():
    if vnames[name] == obj:
    return name
    return None

    def findNonTempBufferRef(obj):
    import expression # Needed to get access to main.
    vnames = vars(__main__)
    print vnames
    for name in vnames.keys():
    if vnames[name] == obj:
    return name
    return None





    **************************************************

    This my code...

    On interpretor if i

    create x=V() and y=V() creates two instances of class variable which
    inherits from expression class E.

    now if i say

    x+y

    and then c=x+y

    and ce=x+y

    i think i loose the original one...

    i want to store in a permbuffer all asignments made..

    after assigning c and ce i want a copy of both in a permbuffer..

    Iam at my witends .. Please help...

    Balaji
     
    Balaji, Apr 23, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. raymond chiu
    Replies:
    1
    Views:
    5,760
    Tushar Agarwal
    Jan 21, 2006
  2. Jiggaz
    Replies:
    2
    Views:
    2,265
    Todd Casey
    Jul 8, 2004
  3. DC Gringo
    Replies:
    1
    Views:
    2,225
    Scott Allen
    Sep 8, 2004
  4. MS
    Replies:
    5
    Views:
    11,502
    Marc Scheuner [MVP ADSI]
    Jan 31, 2005
  5. scott
    Replies:
    0
    Views:
    934
    scott
    Aug 23, 2005
Loading...

Share This Page