Friday, November 30, 2018

The guts of my macro capability

Here on git hubKai Sun, wrote this, a thousand lines of code, but it treats simple c syntax as a scripting language.  Why not dump this into my shell? Then all the macro facilities will be simple c like loops and testing. The code actually removes some of my spaghetti and replaces it with new spaghetti, so the total load on bloat is about 800 lines.

This parser has capability of variable definition, I can modify that slightly to define variable interfaces tlike the argument list, like data storage.  The interpreter is independent of any object code, and unknown cmds need not be errors if they obey the command syntax. When the interpreter will see something like:

if(true)  gcc -c joinloop.c;

That statement in normal c generates an undefined for gcc, here are no operators on the arguments, everything fails.  But noting stops me from modifying the language to include the SPACE as a valid operator, separating arguments which are a new fundamental type.  The one or more spaces is a binary operator that concatenates undefines into the argument list. Any correct command line sequence is valid script syntax, undefines in that context are first class vars..

Easy changes, and remember, this is not meant to be a c interpreter, just a macro expansion capability and users are aware of the argument grammar, they are experienced Power Sell users.

This code is well written, and there are others.  Can I reformat c code into linux argument syntax?

The syntax gives us type flags as in:

gcc -c join.c -o join

Good enough to reformat a while statement for example:
while(a==) { do code }


becones

  
while -var a;  // test a then interpret the enclosed statements,exit on the '}' char.

This is a just in time compile, the while statement expanded properly as soon as it is reached..


I use the flag to identify types as in

var    - in the symbol table
const - immediate value
local  - index into arg_list

Note:  At run time the macro shell actually has all arguments in an array, essentially a linear array of tokens  which we can call the executable format.

Then add a binary and unary cmds for expressions.  Thus, we can intermix cmd, args, and macro control in the same format, just obey the context specific grammar.  Context specific means the cmd may re-interpret flags in the current cmd sequence.  gcc -c uses the flag -c different than any other command sequence. Nor is any cmd restricted on how local variables are identifies, and it can keep its own set of variable names, or make assumptions about all its arguments.  The contract is between user and cmd, the shell does not participate in context specific grammar within the cmd line.






No comments: