Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Please Help with references

Reply
Thread Tools

Please Help with references

 
 
Balaji
Guest
Posts: n/a
 
      04-24-2004
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
 
Reply With Quote
 
 
 
 
Oktay Safak
Guest
Posts: n/a
 
      04-24-2004
test


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.667 / Virus Database: 429 - Release Date: 23.04.2004




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Snake references just as ok as Monty Python jokes/references in python community? :) seberino@spawar.navy.mil Python 8 12-12-2006 11:21 PM
Typedef A references struct B which references struct A which... DanielEKFA C++ 8 05-16-2005 10:26 AM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
how to understand references to variables and references to constants are distinguished? baumann.Pan@gmail.com C++ 3 11-10-2004 04:16 AM
Pointers and References (and References to Pointers) Roger Leigh C++ 8 11-17-2003 10:14 AM



Advertisments