Example #1
0
/* Execute a for loop. */
void exec_for(void)
{
  int cond;
  char *temp, *temp2;
  int brace ;

  get_token();
  eval_exp(&cond);  /* initialization expression */
  if(*token != ';') sntx_err(SEMI_EXPECTED);
  prog++; /* get past the ; */
  temp = prog;
  for(;;) {
    eval_exp(&cond);  /* check the condition */
    if(*token != ';') sntx_err(SEMI_EXPECTED);
    prog++; /* get past the ; */
    temp2 = prog;

    /* find the start of the for block */
    brace = 1;
    while(brace) {
      get_token();
      if(*token == '(') brace++;
      if(*token == ')') brace--;
    }

    if(cond) interp_block();  /* if true, interpret */
    else {  /* otherwise, skip around loop */
      find_eob();
      return;
    }
    prog = temp2;
    eval_exp(&cond); /* do the increment */
    prog = temp;  /* loop back to top */
  }
}
Example #2
0
void exec_for()
{
    int cond;
    char *temp, *temp2;
    int brace ;
    get_token();
    eval_exp(&cond); 
    if(*token!=';')
        sntx_err(SEMI_EXPECTED);
    prog++; 
    temp = prog;
    for(;;) {
        eval_exp(&cond); 
        if(*token!=';')
            sntx_err(SEMI_EXPECTED);
        prog++;     
        temp2 = prog;
        brace = 1;
        while(brace) {
            get_token();
            if(*token=='(') brace++;
            if(*token==')') brace--;
        }
        if(cond)
            interp_block();  
        else {   
            find_eob();
            return;
        }
        prog = temp2;
        eval_exp(&cond); 
        prog = temp;   
    } 
}
Example #3
0
void exec_if()
{
    int cond;

    eval_exp(&cond); 
    if(cond) { 
        interp_block();
    } else { 
        find_eob(); 
        get_token();
        if(tok!=ELSE) {
            putback(); 
            return;
        }
        interp_block();
    }
}
Example #4
0
/* Execute an if statement. */
void exec_if(void)
{
  int cond;

  eval_exp(&cond); /* get if expression */

  if(cond) { /* is true so process target of IF */
    interp_block();
  }
  else { /* otherwise skip around IF block and
            process the ELSE, if present */
    find_eob(); /* find start of next line */
    get_token();

    if(tok != ELSE) {
      putback();  /* restore token if
                     no ELSE is present */
      return;
    }
    interp_block();
  }
}
Example #5
0
void exec_do()
{
    int cond;
    char *temp;
    putback();
    temp = prog;    
    get_token();    
    interp_block(); 
    get_token(); 
    if(tok!=WHILE) 
        sntx_err(WHILE_EXPECTED);
    eval_exp(&cond);
    if(cond) 
        prog = temp; 
}
Example #6
0
/* Execute a do loop. */
void exec_do(void)
{
  int cond;
  char *temp;

  putback();
  temp = prog;  /* save location of top of do loop */

  get_token(); /* get start of loop */
  interp_block(); /* interpret loop */
  get_token();
  if(tok != WHILE) sntx_err(WHILE_EXPECTED);
  eval_exp(&cond); /* check the loop condition */
  if(cond) prog = temp; /* if true loop; otherwise,
                           continue on */
}
Example #7
0
/* Execute a while loop. */
void exec_while(void)
{
  int cond;
  char *temp;

  putback();
  temp = prog;  /* save location of top of while loop */
  get_token();
  eval_exp(&cond);  /* check the conditional expression */
  if(cond) interp_block();  /* if true, interpret */
  else {  /* otherwise, skip around loop */
    find_eob();
    return;
  }
  prog = temp;  /* loop back to top */
}
Example #8
0
void exec_while()
{
    int cond;
    char *temp;

    putback();
    temp = prog;   
    get_token();
    eval_exp(&cond);
    if(cond)
        interp_block();
    else {   
        find_eob();
        return;
    }
    prog = temp;  
}
Example #9
0
void call()
{
    char *loc, *temp;
    int lvartemp;
    loc = find_func(token);
    if(loc==NULL)
        sntx_err(FUNC_UNDEF);
    else {
        lvartemp = lvartos;  
        get_args();  
        temp = prog; 
        func_push(lvartemp);
        prog = loc;         
        get_params();       
                            
        interp_block();     
        prog = temp;        
        lvartos = func_pop();
    }
}
Example #10
0
/* Call a function. */
void call(void)
{
  char *loc, *temp;
  int lvartemp;

  loc = find_func(token); /* find entry point of function */
  if(loc == NULL)
    sntx_err(FUNC_UNDEF); /* function not defined */
  else {
    lvartemp = lvartos;  /* save local var stack index */
    get_args();  /* get function arguments */
    temp = prog; /* save return location */
    func_push(lvartemp);  /* save local var stack index */
    prog = loc;  /* reset prog to start of function */
    get_params(); /* load the function's parameters with
                     the values of the arguments */
    interp_block(); /* interpret the function */
    prog = temp; /* reset the program pointer */
    lvartos = func_pop(); /* reset the local var stack */
  }
}