Tools for Flexible Scripting
by Sergei Savchenko


Listing One
const char* syntax(int type,int& tag)
{
 switch(type)
 {
  case SNTX_FILTER:     return(" \n");
  case SNTX_TERMINATOR: return(" !|&+-*/(),\n");
  case SNTX_UNARY:      return("-!");
  case SNTX_BINARY:     return("|&+-*/");
 }
}

Listing Two
void evaluate(int type,int op,TEXT& txt,int *c)
{
 switch(type)
 {
  case EVAL_VARIABLE: c[0]=atoi(txt.contents()); break;
  case EVAL_UNARY:    switch(op)
                      {
                       case '!': c[0]=!c[0]; break;
                       case '-': c[0]=-c[0]; break;
                      }
                      break;
  case EVAL_BINARY:   switch(op)
                      {
                       case '*': c[0]=c[0]*c[1];  break;
                       case '/': c[0]=c[0]/c[1];  break;
                       case '+': c[0]=c[0]+c[1];  break;
                       case '-': c[0]=c[0]-c[1];  break;
                       case '&': c[0]=c[0]&&c[1]; break;
                       case '|': c[0]=c[0]||c[1]; break;
                      }
                      break;
  case EVAL_MULTY:    if(txt=="funct") { c[0]=c[0]+2*c[1]; break; }

 }
}

Listing Three
main()
{
 FORMULA<int> expr;
 expr="(funct(1,2)+4)*2";
 printf(" %d\n",expr.value());
}

Listing Four
type datastruct { int int [3]float ptr }

var [2]int arr [ 1 2 ]
var [4]datastruct ds
[
 { 1 2 [3 4 5] arr }
 { 6 7 [8 9 10] arr }
 { 11 12 [13 14 15] arr }
 { 0 0 [0 0 0] arr }
]
export ds


Listing Five
#include "data.h"
struct datastruct
{
 int a,b;
 float k[3];
 int *pt;
};
main()
{
 int i;
 struct datastruct *ds=D_data("test.dat");
}


Figure 1: Grammar for the data description scripting language.

type ::= <char> | <short> | <int> | <float> | <ptr> |
         <[>number<]>type | <{>type {type...}<}>

variable ::= name | number | <[>variable {variable...}<]> |
             <{>variable {variable...}<}>

statement ::= <type> name type | <var> type name variable |
              <export> name

language ::= statement {statement...}




2


