This page is dedicated to gathering useful information for designing the architecture of OTIL compilers.
Symbol Tables
In the following there will be extensive use of the term Symbol. This means anything that is referred to by a programmer decided name such as a variable or a function. This is a term of art in compiler construction rather than a language feature of OTIL as such. Likewise a Symbol Table is a collection of known symbols that the compiler is presently keeping track of.
OTIL draws heavily from the extremely rigid approach to declarations used in Pascal. There is limited support for local scope, limited places in which symbols maybe declared and everything must be declared prior to being used.
Scope
OTIL does not support arbitrarily nested scopes. Instead there are a fixed number of acceptable scopes as follows:
- A program's global scope, including symbols imported from modules and libraries.
- A module or library's interface (AKA public scope). As previously mentioned this will be imported into the program-level scope of any program that uses it.
- A module or library's implementation (AKA private scope). These symbols are invisible to any programs that use said modules and libraries.
- A function or procedure's local scope.
Locations and order of declarations
There are a handful of designated places for declaring symbols prior to their use:
- The beginning of a program (between its name and its main BEGIN ... END body)
- The Interface section of a module or library (between the INTERFACE and IMPLEMENTATION keywords)
- The implementation section of a module or library (between the IMPLEMENTATION keyword and final END keyword)
- Between the name/type header of a function/procedure and the BEGIN keyword that begins its body (only applicable to variables and constants)
All symbols must be declared prior to being invoked. To this end OTIL supports forward-declaration so that procedures and functions can be quickly listed without their lengthy definitions. In fact procedures and functions listed in the INTERFACE section of a module or library are required to be forward declarations.
Putting it all together
Because of the strictly limited number of scopes, strict rules regarding where things may be declared and requirement that everything is declared prior to use an OTIL compiler can do the entire task of building a symbol table prior to analysing the main body of a program or the body of a procedure/subroutine. There is no need for the symbol table to include entries with missing details. This markedly reduces how complex the compiler's middle-end needs to be.