Exemplo n.º 1
0
/******************************************************************************
    num_op := num rest_num_op
              ( expr ) rest_num_op
 *****************************************************************************/
void
parse_num_op( val_t* val )
{
    printtab();
    dprintf("parse_num_op()\n");
    level++;

    if ( match_num( val ) ) {
        parse_rest_num_op( val );
    } else if ( match_variable( val ) ) {
        resolve_variable( val );
        parse_rest_num_op( val );
    } else if ( match_char( '(' ) ) {
        parse_expr( val );
        if ( !match_char( ')' ) ) {
            buffer[bpos] = 0;
            printf("Missing bracket: %s\n", buffer);
            longjmp( env, 1 );
        }
        parse_rest_num_op( val );
    } else {
        buffer[bpos] = 0;
        printf("Parse error: %s\n", buffer);
        longjmp( env, 1 );
    }
    
    level--;

    return;
}
Exemplo n.º 2
0
/******************************************************************************
    expr := term rest_expr
 *****************************************************************************/
void
parse_expr(val_t* val)
{
    printtab();
    dprintf("parse_expr()\n");
    
    level++;
    if ( match_variable( val ) ) {
        parse_rest_var( val );
    } else {
        parse_term( val );
        parse_rest_expr( val );
    }

    level--;

    return;
}
Exemplo n.º 3
0
/*
 * match_object
 * INPUT:
 *   string    Input string to match
 *   co        cligen object
 * OUTPUT
 *   exact:    1 if match is exact (CO_COMMANDS). VARS is 0.
 *   reason:   if not match and co type is 0, reason points to a (malloced) string 
 *             containing an error explanation string. If reason is NULL no such
 *             string will be malloced. This string needs to be freed.
 * RETURNS:
 *   -1        Error
 *   0         Not match
 *   1         Match
 * Given a string and one cligen object, return if the string matches
 * the object. Note, if string = NULL it is a match. 
 */
static int 
match_object(char *string, cg_obj *co, int *exact, char **reason)
{
  int match = 0;

  if (string==NULL)
      return 1;
  if (co==NULL)
      return 0;
  switch (co->co_type){
  case CO_COMMAND:
    match = (strncmp(co->co_command, string, strlen(string)) == 0);
    *exact = strlen(co->co_command) == strlen(string);
    break;
  case CO_VARIABLE:
      if ((match = match_variable(co, string, reason)) < 0)
	  return -1;
      *exact = 0; /* N/A */ 
    break;
  case CO_REFERENCE:
      break;
  }
  return match!=0 ? 1 : 0;
}