Compiling AWK/C subset to intermediate code (Francis Burton)
Wed, 11 Aug 1993 12:48:03 GMT

          From comp.compilers

Related articles
Compiling AWK/C subset to intermediate code (1993-08-11)
Re: Compiling AWK/C subset to intermediate code (1993-08-13)
| List of all articles for this month |

Newsgroups: comp.compilers,comp.programming
From: (Francis Burton)
Keywords: C, interpreter, question, comment
Organization: University of Denver, Dept. of Math & Comp. Sci.
Date: Wed, 11 Aug 1993 12:48:03 GMT


I am writing an (image processing) application that can be driven with a
program or script. The script language would mix C-like arithmetic and
flow-control constructs, function definitions, and calls to these and
built-in functions. A language resembling AWK would probably be nicer than
pure C.

Because of real-time constraints the script must be compiled into an
intermediate code (call it i-code) which can be executed fast.
Interpreting the script is not fast enough, I know.

Furthermore, I would like to separate the functions of compilation and
execution into two processes (.EXE files) and have the compiler half write
i-code and symbol table information to a file. This is because 1) I want
to maximize space available for program execution in cramped DOS memory
and 2) I can use the compiler with a another project I have in mind which
does something quite different (controls some motors) with almost no
further effort. The only other linkage between the programs will be at
compile time, via a table which lists built-in function names, their
i-code numbers and their addresses, e.g.

typedef struct {
        char *name; /* function name */
        PF *func; /* pointer to function */
        } FUNCTAB;

static FUNCTAB function_table[] = {
        "exit", do_exit,
        "foo", do_foo,
        "bletch", do_bletch,

or something quite like it. The compiler is not interested in
function addresses so these would be made invisible with some
define/macro hackery.

The question is this: does anyone have/know how to obtain C source
which performs this kind of compilation. A Lex/YACC specification
would be the obvious way to do this, and would have the benefit of
being easily modified.

What I have done so far:

* Looked at the chapter on "Program Development" in Kernighan & Pike.
    This would need some work to extend it e.g. to use integer and
    string data types. I would also need to type it all in by hand :-(

* Thought about simplifying Rob Duffs implementation of PC AWK, by
    cutting stuff away. Initially, this looked quite a nice way to
    solve the problem. However, I am unsure whether I can use the code
    as it is copyright. (Does anyone know Rob Duffs e-mail address?)
    Furthermore, I cannot recreate a working awklex.c file from
    awklex.l using any Lex I have access to. BTW, I got a working
    awkyacc.c from awkyacc.y using Bison plus a couple of minor hacks.

* Looked at GNU AWK. This is no use because it stores the compiled
    program in a tree - the whole thing looks much more complicated
    than Rob Duff's AWK, and I really would prefer my i-code arranged
    linearly to keep the execution side as simple as possible.

* Wrote this post.

I am sure someone must have done this before. I have looked in the
SIMTEL archives... nothing. Archie isn't much help without a name.

Help! Please.

Francis Burton
[Have you considered using the p-code option with
Microsoft C? It's fairly compact, and a lot easier than writing your
own compiler and interpreter. -John]

Post a followup to this message

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