tinytool-v1:

Suppose we find ourselves writing hundreds of boring and
repetitive "pattern instances", differing only in small details.

For example:

int plus( int a, int b ) { return (a+b); }
int minus( int a, int b ) { return (a-b); }
int times( int a, int b ) { return (a*b); }
...

all that varies from line to line is (funcname,operator),
perhaps the input and return type 'int' is also a parameter?

Why not generate them automatically using an ad-hoc tool,
scaffolding that you build, use a few times, then discard?
especially if you could write the tool in 5-10 minutes!

Specify the inputs (as a `little language') and corresponding outputs:

  INPUT:
    foreach line: F, Op pairs
  OUTPUT:
    foreach line: "int F( int a, int b ) { return (a Op b); }"

(See file 'fullinput' for an example of input in this format).

Ok, first observe that this is a simple job for a scripting language like Perl,
as a Perl oneliner I composed in about two minutes:

  perl -nle '($f,$op)=split(/,/); print "int ${f}( int a, int b ) { return (a${op}b); }"' < fullinput

Even if we insist on doing this in C, it's not that hard, might take about
30 minutes using low-level string manipulation.  still worth it?

what about the standard library function <strtok>?  does the token splitting
for us.  might reduce the time to 15 minutes, especially if we already have
a readline() function that chomps the trailing newline.

Give it a go.  result: 45 line cgen1.c, written in 10 minutes
in 3 write a bit + debug a bit stages (debug prints left it to show you
where each stage ended).  worked first time round!

Compile and run it via:

	make
	./cgen1 < fullinput

Note: cgen1.c has some rudimentary error checking, but not as much as
a "professional tool" needs.   Tools have to be "good enough", not "perfect".
