| 1 |
In this directory is the source to the bootstrap tool mc. The tool |
| 2 |
converts PIM4 Modula-2 into C or C++ and it implements some of the GNU |
| 3 |
Modula-2 extensions. It uses the same lexical and grammar as GNU |
| 4 |
Modula-2, but restricts some of the features. |
| 5 |
|
| 6 |
Local modules are not supported and constant aggregate types are not |
| 7 |
supported (with the exception of SET constant aggregate types). It |
| 8 |
has the ability to translate Modula-2 into C/C++, it uses the same |
| 9 |
name space convension as GNU Modula-2 and it issues source file |
| 10 |
directives in the target language which match the original source. |
| 11 |
|
| 12 |
The tool mc uses multiple passes primarily to keep the implementation |
| 13 |
simple. The function of each pass is defined here: |
| 14 |
|
| 15 |
Pass 1 |
| 16 |
define module symbols (def, imp, program, local) and find their source |
| 17 |
files if appropriate. |
| 18 |
parse definition modules and any extended opaque implementation module |
| 19 |
and the implementation/program module. |
| 20 |
define root decls for all CONST, TYPE, PROCEDURE, VAR, symbols |
| 21 |
(the left hand side for all declarations). |
| 22 |
push and pop scope symbols as the source is parsed. |
| 23 |
populate the export lists for the def modules |
| 24 |
|
| 25 |
Pass 2 |
| 26 |
parse definition modules and any extended opaque implementation module |
| 27 |
and the implementation/program module. |
| 28 |
complete declaration of the right hand side of TYPE: |
| 29 |
equivalence: TYPE foo = bar ; |
| 30 |
equivalence: TYPE foo = bar.x ; |
| 31 |
enumerations: TYPE foo = (a, b, c) ; |
| 32 |
completely define enumeration types and place them into |
| 33 |
a per module list of enumerations. |
| 34 |
|
| 35 |
Pass 3 |
| 36 |
parse definition modules and any extended opaque implementation module |
| 37 |
and the implementation/program module. |
| 38 |
process the import lists for the def |
| 39 |
introducing the symbol from another modules export list. |
| 40 |
remembering to populate the enum and all fields if they are imported. |
| 41 |
mark any opaque type (in the definition module). |
| 42 |
create placeholders for expression and constexpression |
| 43 |
and put these into a list. |
| 44 |
complete const/type/var/procedure declarations (using |
| 45 |
expression placeholders). |
| 46 |
|
| 47 |
Pass 4 |
| 48 |
parse definition modules and any extended opaque implementation module |
| 49 |
and the implementation/program module. |
| 50 |
build expressions and constexpressions |
| 51 |
and attach them to their placeholders. |
| 52 |
at this point all definition module symbols are completely finished. |
| 53 |
at this point const/types should be completely declared for the |
| 54 |
implementation/program module |
| 55 |
|
| 56 |
Pass 5 |
| 57 |
only parse the implementation or program module |
| 58 |
build a tree for all procedure and main init code. |
| 59 |
build expressions and constexpressions |
| 60 |
and attach them to their placeholders. |
| 61 |
|
| 62 |
for each exported symbol, s |
| 63 |
topological sort and define s |
| 64 |
|
| 65 |
topological sort and define init code |