D
David Turner
Not really. What you're doing is what I'd call "virtual stack" by
virtue of the fact that the heap objects are being managed by stack
objects.
Having read this through a second time, I'm not sure that you
understood the C++ code I posted. So here is an equivalent in Python:
class File:
def __init__(self, name):
self.fh = open(name, "r")
def __del__(self):
self.fh.close()
file_list = []
file_list.append(File(file_to_compile))
while len(file_list):
f = file_list[len(file_list)-1]
t = Token(f)
if t == Token.EOF:
file_list.pop()
else:
parse(t)
No stack objects in sight, yet this code is semantically equivalent to
the C++ code.
Don't let red herrings like std::stack confuse you .
Regards
David Turner