Example #1
0
int m_break_num(char a)		//return 1 if the char is not a num
{
	int i=0;
	if(match_num(a)!=0)
		return 0;
	return 1;
}
/******************************************************************************
    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;
}
Example #3
0
/*CREATE LIST OF TOKENS*/
void Createlist(char *exp,List infix_l)
{
	char p[MAXNAME];	//store var name
	int cnt;		
	

	while((*exp == ' ' || *exp == '\t')  && *exp!='\0')	//remove spaces
		exp++;
	if(*exp=='\'')				//override check eval symbol.
		exp++;
	
	if(*exp == '\0')
		return;
	while(*exp!='\0')			//read till end of line
	{
		while((*exp == ' ' || *exp == '\t') && *exp!='\0')
                exp++;

		if(match_char(*exp)==0)		//if variable
		{
			exp = Extract_word(exp,p);	
			cnt = Count(infix_l);
			InsertAfter(p,infix_l,cnt);
		}
		else if(match_num(*exp)==0)	//if number
		{
			exp = Extract_num(exp,p);
			cnt = Count(infix_l);
			InsertAfter(p,infix_l,cnt);
			add_value(p,0,p);
		}
		else if(match_bool(*exp)==0)	//if boolean op
		{
			exp = Extract_bool(exp,p);
			cnt = Count(infix_l);
			InsertAfter(p,infix_l,cnt);
		}
		else
		{
			p[0] = *exp;		//else single letter operator
			p[1]='\0';
			cnt = Count(infix_l);
			InsertAfter(p,infix_l,cnt);
			exp++;
		}
	}
}