atari email archive

a collection of messages sent at Atari from 1983 to 1992.

YAPP - yet another pre-processor

(1 / 1)


I did a Macro PreProcessor for Mike to use as a front end to AS68K until
MAC68K is up and running. It is essentially MAC65 with 40% of its guts
cut out. It occurs to me that it might be useful for other things. The
first thing I thought of was to have it generate the initialiser code for
a large array of structures in one of my C modules. For example, the
C source currently looks something like this:

struct whatever name[] = {
	{ init,init,init,etc...},
	{ init,init,init,etc...},
	etc...
};

where struct whatever is a rather large structure with (in my case) 13
items. I found it rather a pain to code it up and especially a pain to
change the struct. The C macros are no help since one cannot apply
defaults, skip arguments or make any decisions about any argument.
The source code before sending it through MACPP would look like:

    .macro init opt=0,def=1,value=0,name="some_string",comma=1
    .if ne,comma
    { opt,def,value,name },
    .iif
    { opt,def,value,name }
    .endc

    struct whatever name[] = {
	    init value=100,name="this string"
	    init opt=2,def=8
	    init
	    init name="some other string"
	    init value=99,comma=0
    };

The default values (strings actually) for each item are placed on the
macro definition after an equal sign behind its cooresponding keyword.
The macro is called with arguments specified by keyword for only those
arguments that are relevant. This makes it a whole lot easier to read
and maintain.

Since MACPP was really meant for an assembly language source code, 
there'll be cases where it'll screw up on C code (such as with semicolons
in macro arguments). But you might find it useful for some things.

There's a brief documentation file in DOK:MACPP.DOC that you can
look at for more details. It'll help if you already know MAC65 
statement syntax.

ds
Message 1 of 1

Oct 26, 1988