Sunday, December 2, 2018

The guts of my syntax interpreter

Below the fold are the forty lines of partly implemented code for my syntax execution routing. It does the while, define and expression operations. The execution unit is simple because it is written in c itself, making it inefficient. When complete I expect 450 lines of code.

The parser itself is a net additional 50 lines of code, consisting mainly of assembling the argument list and executing complete statements. So this shell, opaque to everything is passes, is about 350 lines of c code, able to load sub system commands and executes while loops and variable expressions, and includes stubs for the remainder of syntax needed. Compatible with any subsystem using the standard linux command format, in an argument list array form.



// Execute a while loop in argument syntax
int WhileCommand(int *argc,void * args[]) {
long count = (long) args[1];
*argc += 2;
while(count--)
ExecCommand(argc,args);
}
// mostly not imp[lemented
int binop(int l,char op,int r) {
switch(op) {
case '+':
case '-':
case '/':
case '*':
break;
}
}
// Format: expre arg1,arg2,...
// he args in reverse polish
int ExpressionCommand(int *argc,void * args[]) {
long accum = (long) args[1];
char op =0;
*argc += 2;
while(op != ';'){
op = args[*argc];
(*argc)++;
if(optype(op) == binary)
accum = binop(accum,op,args[argc]);
else(optype(op) == compound)
accum = binop(accum,op, ExpressionCommand(argc,args));
}
}
// Just int and char *
int DefineExpressionint * argc, void * args[]) {
if(stgrcmp("int)) {}
if(strcmp(char*)] {}
}

No comments: