Esempio n. 1
0
File: syntax.c Progetto: loiso/scalc
static void
list_expr(void)
{	
	number res;
		
start:
	while (token.type == TOKEN_INTEGER ||token.type == TOKEN_LPARENTH || token.type == TOKEN_EOL || token.type == TOKEN_EOF) {

		if (token.type == TOKEN_EOL) {
			get_next_token();
			continue;
		}
		if (token.type == TOKEN_EOF) {
			return ;
		}		
		add_expr();

		if (err == SYN_ERR || err == MEM_ERR) {
			if (err == SYN_ERR)
				printf("syntax error\n");
			if (err == MEM_ERR)
				printf("memory error\n");
			sync_stream();
			sp.n = 0;
			err = 0;
			goto start;
		}
		pop_item(&sp, &res);
		print_value(res);
	}

	printf("syntax error\n");
	sync_stream();
	goto start;
}
Esempio n. 2
0
	// Queue item pop/remove.
	char *pop ( int *port, jack_nframes_t *time, size_t *size )
	{
		char *item = pop_item(time, size);
		if (item) {
			if (port) *port = *(unsigned short *) item;
			if (size) *size -= sizeof(unsigned short);
			item += sizeof(unsigned short);
		}
		return item;
	}
Esempio n. 3
0
int
main()
{
  struct stack sp;
	
	stk_init(&sp);
	mpl_int a, b, c, d, e, f;
	char as[] = "12";
	char bs[] = "128";
	char cs[] = "5";
	
	char str[10];
	int i;
	
	mpl_init(&a);
	mpl_init(&b);
	mpl_init(&c);
	
	mpl_set_str(&a, as, 10);	
	mpl_set_str(&b, bs, 10);
	mpl_set_str(&c, cs, 10);
	
	push_item(&sp, &a);
	push_item(&sp, &b);
	push_item(&sp, &c);
	
	print_stk(&sp);
	
	pop_item(&sp, &d);
	pop_item(&sp, &e);
	pop_item(&sp, &f);
	
	mpl_add(&d, &f, &e);
	mpl_to_str(&d, str, 10, 10);
	for (i = 0; str[i] != '\0'; i++)
		printf("%c", str[i]);
	printf("\n");
	return 0;
}
Esempio n. 4
0
int main(){
    int indent = 0;
    int iter = 0;

    list_size = 0;
    BUF_LEN = 127;
    file_desc = open(DEVICE_FILE_NAME, 0);
    init_list();
    move_current();

    set_buflen();
    do{
        int pid;
        char *name;
        int res;

        pid = get_currpid();
        name = get_currname();
        add_item(pid, name);
        if(pid == 0) break;
    }while(move_parent() != FAIL);

    while(list_size){
        int i, pid;
        char *name;
        for(i=0; i<indent; i++) printf(" ");
        if(iter){
            printf("\\-");
            indent += 2;
        }

        pid = item_pid();
        name = item_name();

        printf("%s(%d)\n", name, pid);
        pop_item();
        iter ++;
    }

    return 0;
}
Esempio n. 5
0
File: syntax.c Progetto: loiso/scalc
static void
rest_mul_expr(void)
{
	int tmp, rv, i;
	number op1, op2;
		
	while(token.type == TOKEN_ASTERISK || token.type == TOKEN_SLASH) {	
		tmp = token.type;
		get_next_token();
		
		pr_expr();
		if (err == SYN_ERR) {
			goto out;
		}
		
		rv = pop_item(&sp, &op2);
		if (rv != OK) {
			err = MEM_ERR;
			goto out;
		}
		
		rv = pop_item(&sp, &op1);
		if (rv != OK) {
			err = MEM_ERR;
			goto out;
		}
		
		if (tmp == TOKEN_ASTERISK) {
			rv = mpl_mul(&op1.value, &op1.value, &op2.value);
			if (rv != MPL_OK) {
				err = MEM_ERR; 
				goto out;
			}
			
			op1.frac += op2.frac;

		} else if (tmp == TOKEN_SLASH) {
			if (op1.frac == 0 && op2.frac == 0)
				goto main_part;
				
			op1.frac -= op2.frac;
			for (i = 0; i < PRECISION; i++) {
				rv = mpl_mul_dig(&op1.value, &op1.value, 10);
				if (rv != MPL_OK) {
					err = MEM_ERR;
					goto out;
				}
				op1.frac++;
			}
main_part:			
			rv = mpl_div(&op1.value, NULL, &op1.value, &op2.value);
			if (rv != MPL_OK) {
				err = MEM_ERR;
				goto out;
			}
		}
		rv = push_item(&sp, &op1);
		if (rv != OK) {
			err = MEM_ERR;
			goto out;
		}
		mpl_clear(&op2.value);			
	}
	
	if (token.type != TOKEN_PLUS && token.type != TOKEN_MINUS &&
	    token.type != TOKEN_RPARENTH && token.type != TOKEN_EOL) {
			err = SYN_ERR;
			goto out;
	}
	
out:
	return ;
}
Esempio n. 6
0
File: syntax.c Progetto: loiso/scalc
static void
rest_add_expr(void)
{
	number op1, op2;
	unsigned int tmp, rv, i;
		
	while (token.type == TOKEN_PLUS || token.type == TOKEN_MINUS) {
		tmp = token.type;
		
		get_next_token();
		mul_expr();
		if (err == SYN_ERR) {
			goto out;
		}
		
		rv = pop_item(&sp, &op2);
		if (rv != OK) {
			err = MEM_ERR;
			goto out;
		}
		
		rv = pop_item(&sp, &op1);
		if (rv != OK) {
			err = MEM_ERR;
			goto out;
		}
		
		if (op1.frac == op2.frac)
			goto main_part;
			
		if (op1.frac > op2.frac) {
			for (i = 0; i < (op1.frac - op2.frac); i++)
				rv = mpl_mul_dig(&op2.value, &op2.value, 10);
				if (rv != MPL_OK) {
					err = MEM_ERR;
					goto out;
				}
			op2.frac = op1.frac;
		} else {
			for (i = 0; i < (op2.frac - op1.frac); i++)
				rv = mpl_mul_dig(&op1.value, &op1.value, 10);
				if (rv != MPL_OK) {
					err = MEM_ERR;
					goto out;
				}
			op1.frac = op2.frac;
		}
main_part:
		if (tmp == TOKEN_PLUS) {
			rv = mpl_add(&op1.value, &op1.value, &op2.value);
			if (rv != MPL_OK) {
				err = MEM_ERR;
				goto out;
			}

		} else if (tmp == TOKEN_MINUS) {
			rv = mpl_sub(&op1.value, &op1.value, &op2.value);
			if (rv != MPL_OK) {
				err = MEM_ERR;
				goto out;
			}
		}
		rv = push_item(&sp, &op1);
		if (rv != OK) {
			err = MEM_ERR;
			goto out;
		}
		
		mpl_clear(&op2.value);
	}
	
	if (token.type != TOKEN_EOL && token.type != TOKEN_RPARENTH) {
		err = SYN_ERR;
		goto out;
	}
out:
	return ;
}