bool filter_fold(sfilter * sf, stoken_t * sout) { stoken_t *last = &sf->fold_last; stoken_t *current = &sf->fold_current; //printf("state = %d\n", sf->fold_state); if (sf->fold_state == 4 && !st_is_empty(last)) { //printf("LINE = %d\n", __LINE__); st_copy(sout, last); //printf("%d emit = %c, %s\n", __LINE__, sout->type, sout->val); sf->fold_state = 2; st_clear(last); return true; } while (filter_syntax(sf, current)) { //printf("state = %d\n", sf->fold_state); //printf("current = %c, %s\n", current->type, current->val); if (sf->fold_state == 0) { if (current->type == '(') { continue; } if (st_is_unary_op(current)) { continue; } sf->fold_state = 1; } if (st_is_empty(last)) { //printf("LINE = %d\n", __LINE__); if (current->type == '1') { //printf("LINE = %d\n", __LINE__); sf->fold_state = 2; st_copy(last, current); } //printf("LINE = %d\n", __LINE__); st_copy(sout, current); //printf("emit = %c, %s\n", sout->type, sout->val); return true; } else if (last->type == '1' && st_is_arith_op(current)) { //printf("LINE = %d\n", __LINE__); st_copy(last, current); //sf->fold_state = 1; } else if (last->type == 'o' && current->type == '1') { //printf("LINE = %d\n", __LINE__); //continue; st_copy(last, current); } else { //printf("LINE = %d\n", __LINE__); if (sf->fold_state == 2) { if (last->type != '1') { st_copy(sout, last); st_copy(last, current); // printf("%d emit = %c, %s\n", __LINE__, sout->type, sout->val); sf->fold_state = 4; } else { st_copy(sout, current); st_clear(last); } return true; } else { //printf("LINE = %d\n", __LINE__); if (last->type == 'o') { //printf("STATE = %d, LINE = %d\n", sf->fold_state, __LINE__); st_copy(sout, last); st_copy(last, current); sf->fold_state = 4; } else { //printf("LINE = %d\n", __LINE__); sf->fold_state = 2; st_copy(sout, current); st_clear(last); } //printf("emit = %c, %s\n", sout->type, sout->val); return true; } } } if (!st_is_empty(last)) { if (st_is_arith_op(last)) { //printf("\nstate = %d, emit = %c, %s\n", sf->fold_state, last->type, last->val); st_copy(sout, last); st_clear(last); return true; } else { st_clear(last); } } return false; }
static uint _rt_test(struct _rt_stack* sp) { return ((sp->type != STACK_NULL) || (sp->type == STACK_NUM && sp->num != 0) || ((sp->type == STACK_PTR || sp->type == STACK_RO_PTR) && (st_is_empty(&sp->single_ptr) == 0))); }