Re: Implementing OO

Ido.Yehieli@gmail.com
27 Mar 2006 01:31:06 -0500

          From comp.compilers

Related articles
Implementing OO xnooga@gmail.com (2006-03-22)
Re: Implementing OO roboticdesigner@gmail.com (MainStem) (2006-03-27)
Re: Implementing OO oliverhunt@gmail.com (oliverhunt@gmail.com) (2006-03-27)
Re: Implementing OO Ido.Yehieli@gmail.com (2006-03-27)
Re: Implementing OO mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2006-03-29)
Re: Implementing OO oliverhunt@gmail.com (oliverhunt@gmail.com) (2006-04-03)
Re: Implementing OO mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2006-04-08)
Re: Implementing OO henry@spsystems.net (2006-04-17)
Re: Implementing OO mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2006-04-21)
| List of all articles for this month |

From: Ido.Yehieli@gmail.com
Newsgroups: comp.compilers
Date: 27 Mar 2006 01:31:06 -0500
Organization: http://groups.google.com
References: 06-03-072
Keywords: OOP
Posted-Date: 27 Mar 2006 01:31:06 EST

Do you have/know how to implement something similar C ltructs?
If not, take a look here:
http://www.lysator.liu.se/c/ANSI-C-grammar-l.html
and here:
http://www.lysator.liu.se/c/ANSI-C-grammar-y.html


Once your done with that, you can specify a simple OO mechanism that
uses the features you have in your langauge (I assume you also have
functions & types, if not they are easy to implement) like that (i will
write it in a c like language):


struct myClass {
        someType someField;
        someOtherType someOtherField;
        ...
}


myClassMethod1(myClass* self, arg1, arg2, ... , argn){
        ...
}


You can add inheritance, for instance, by extending your struct-like
structures to be inharitable- that shouldn't be to difficult to get
from C like structs to something that can do this:


struct myNewClass:myClass {
        /*the declaration above will automatically add a final field called
super
        of type myClass */
        someType someNewField;
        ...
}


myNewClassMethod1(myNewClass* self, arg1, arg2, ... , argn){
        ...
}


and myClassMethod1 will be defined to accept myClass* as it's first
parameter or any struct who's super is of type myClass.


After you have that going you can hide some of the mechanism from the
user, for example- by using a new keyword "class" that will define
these things (like the prefix of the functions and self as the first
parameter) automatically.


Hope that helped a bit,
Ido Yehieli.



Post a followup to this message

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