DEFINITION MODULE CodeGen; (* Backend for SimpleMod2: pretty-prints the parsed program as a complete, ready-to-compile Modula-2 program module. OpenModule(name) creates "gen/.mod" (directory "gen" must exist). Grammar actions then call Emit / Brk / Ind / Ded while parsing; Close finishes the file. Since the source language is a Modula-2 subset, re-emitted code compiles with e.g. gm2 -fiso. *) PROCEDURE OpenModule (name: ARRAY OF CHAR); (* Opens gen/.mod for writing, resets indentation. *) PROCEDURE Close; (* Closes the output file (no-op if not open). *) PROCEDURE Emit (s: ARRAY OF CHAR); (* Writes raw text (keyword, identifier, literal, punctuation). *) PROCEDURE Brk; (* Newline + current indentation. *) PROCEDURE Ind; (* Indentation level + 1. *) PROCEDURE Ded; (* Indentation level - 1 (floored at 0). *) END CodeGen.