Multi-pass compiler (forward declarations)

lican <licaner@gmail.com>
Sat, 7 Mar 2009 12:39:03 -0800 (PST)

          From comp.compilers

Related articles
Multi-pass compiler (forward declarations) licaner@gmail.com (lican) (2009-03-07)
| List of all articles for this month |
From: lican <licaner@gmail.com>
Newsgroups: comp.compilers
Date: Sat, 7 Mar 2009 12:39:03 -0800 (PST)
Organization: Compilers Central
Keywords: design, question
Posted-Date: 10 Mar 2009 15:28:04 EDT

Hi!


I've been reading about multi-pass compilers and how they handle class
definitions and declarations. I couldn't find much information about
the implementation though. Can anyone point me to some information
about how to handle thigs like:


class Foo implements Bar
{
        BarPointer some_field;
        BasePointer some_field2;
}


class Bar implements Base
{
}


class Base
{
}


In C++ it would obviously result in a compiler error (wrong order, no
forward declaration), but in C# or Java the compiler resolves such
problems with multi-pass. The question is: how? Do you know any
examples of implementation or any pseudocode? First I thought about a
simple algorithm:


1. Finding class definitions (Foo, Bar, Base)
2. Check the inheritance (implements Bar, Base)
3. Check the class fields types


To be honest I never written a compiler before (just starting, a
simple one) so I don't really know some basic algorithms.


Post a followup to this message

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