How to implement anonymous classes?

Matthias Mann <MatthiasMann@gmx.de>
27 Oct 2003 16:06:42 -0500

          From comp.compilers

Related articles
How to implement anonymous classes? MatthiasMann@gmx.de (Matthias Mann) (2003-10-27)
Re: How to implement anonymous classes? vbdis@aol.com (2003-10-31)
| List of all articles for this month |

From: Matthias Mann <MatthiasMann@gmx.de>
Newsgroups: comp.compilers
Date: 27 Oct 2003 16:06:42 -0500
Organization: T-Online
Keywords: OOP, design, question
Posted-Date: 27 Oct 2003 16:06:42 EST

Hello,


I'm working on a script language which should support anonymous class
like java:


class MyClass {
private:
SomeClass myVar;
string myString;


public:
MyClass() {
myVar.addListener(new SomeListener() {
void onSomeEvent(string someText) {
myString = someText;
}
});
}
}




Now my question is how to implement access to the member variables of
the containing class (I don't want access to the stack variables of
the calling function). I've already written the class grammer for the
whole language and the code generator for the classes (the function
code generator is not finished yet). My idea was to suply a hidden
variable in the anonymous class (they can only overwrite already
defined function and can't declare member variables or a
constructor). But the problem is that the code generator needs to
access everything throw the hidden variable (that's initialized throw
the constructor to the pointer of the calling class). How can I do
this without writing a seperate code generator for the anonymous class
? Or are there better ways to implement this ?


Ciao Matthias Mann


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.