object oriented compiler... question
Posted: Mon Sep 23, 2002 11:00 pm
Ok... I made first an Scanner... after that an Parser, which return an parse tree. Noew I have to do the part wich tranlate to machine code. I have a problem:
It is an object oriented compiler... I don't know in an hierarchy of classes how to store the offsets of metods...
This problem is very big for me... I don't know how C++ or Java handles it...
For example:
class A {
public void print() {
// some code
}
}
class B extends A {
public void print() {
// some ather code
}
}
void function(A object) {
object.print();
}
So I have two classes with the method print.
I don't understand how can I handle this case:
public static void main(String args[]) {
A a=new A();
B b=new B();
function(a); // should be called print from class A
function(b); // should be called print from class B
}
Does anyone have an ideea how can I know witch method print should I call in this case?
It is an object oriented compiler... I don't know in an hierarchy of classes how to store the offsets of metods...
This problem is very big for me... I don't know how C++ or Java handles it...
For example:
class A {
public void print() {
// some code
}
}
class B extends A {
public void print() {
// some ather code
}
}
void function(A object) {
object.print();
}
So I have two classes with the method print.
I don't understand how can I handle this case:
public static void main(String args[]) {
A a=new A();
B b=new B();
function(a); // should be called print from class A
function(b); // should be called print from class B
}
Does anyone have an ideea how can I know witch method print should I call in this case?