Re: Code Generators (Gene Wirchenko)
24 Aug 1998 13:34:22 -0400

          From comp.compilers

Related articles
Code Generators (Kenn Heinrich) (1991-04-12)
Code Generators (Mike Lichak) (1998-08-22)
Re: Code Generators (Chris F Clark) (1998-08-24)
Re: Code Generators (1998-08-24)
Re: Code Generators (Joachim Durchholz) (1998-08-25)
Re: Code Generators (1998-08-25)
Re: Code Generators (1998-08-25)
| List of all articles for this month |

From: (Gene Wirchenko)
Newsgroups: comp.compilers
Date: 24 Aug 1998 13:34:22 -0400
Organization: Compilers Central
References: 98-08-157
Keywords: tools

Mike Lichak <> wrote:
>Here's the problems I always run into. The code can be compiled and
>delivered, as is, to the end-user, about 80% of the time. The rest of
>the time, I have to hand-edit parts of the code.
>Once I do that, and find a bug in my code-generator, or add a nifty
>new feature to the code-generator, I have to hand modify or cut and
>pasted that 20% of customized code.
>The hand-edited parts are usually quite site-specific to fufill a
>contract, and too intense to justify adding them to the
>code-generator. Or all the hacks I've added make it too hard or
>time-consuming to modify at all. Or the growth of the poorly designed
>input syntax catches up to me. And it's nice to be backward compatible
>with early projects that need mods and additions.

          I wrote a tiny compiler for generating much of the general code
that I need in my Visual FoxPro 5 forms. Maybe you can steal an idea
or two from me.

          There are two files: a .sgi (Say Get Input (since my form class
implements the basics of @-say-get)) and the .prg.

          Pass one of the compiler deals with validating the .sgi file. I
have constrained the language so it can be dealt with in one pass.

          The .sgi file is basically a table with each control's parameters
are on one line. The are also comment lines and some modifier
commands. These are such things as that input is compulsory for the
previous control and that a #defined constant is required for the
previous control so the program can refer to the control regardless of
how the .sgi may be modified.

          Pass two of the compiler merges the generated code into the .prg.

          To do this, I defined merge directives. Each directive is a VFP
comment so VFP won't complain about it. It is followed by the
generated code and then by an end directive. When a merge directive
is encountered, the compiler reads to an end directive and then writes
out the directive, the new code, and the end directive.

          There is additional checking for missing end directives.

          The compiler is totally ignorant of any other code and simply
passes it through uninterpreted.

          To create a form, I usually take an existing .sgi and .prg and
make my changes. The compiler will generate the appropriate code from
the .sgi and there it is.



Gene Wirchenko

Post a followup to this message

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