//static int factor(void) int factor(void) { int r; switch(tokenizer_token()) { case TOKENIZER_NUMBER: r = tokenizer_num(); accept(TOKENIZER_NUMBER); break; case TOKENIZER_LEFTPAREN: accept(TOKENIZER_LEFTPAREN); r = expr(); accept(TOKENIZER_RIGHTPAREN); break; default: r = varfactor(); break; } return r; }
/*---------------------------------------------------------------------------*/ static int factor(void) { int r; DEBUG_PRINTF("factor: token %d\n", tokenizer_token()); switch(tokenizer_token()) { case TOKENIZER_NUMBER: r = tokenizer_num(); DEBUG_PRINTF("factor: number %d\n", r); accept(TOKENIZER_NUMBER); break; case TOKENIZER_LEFTPAREN: accept(TOKENIZER_LEFTPAREN); r = expr(); accept(TOKENIZER_RIGHTPAREN); break; default: r = varfactor(); break; } return r; }
/*---------------------------------------------------------------------------*/ static void factor(struct typevalue *v) { uint8_t t = current_token; int len; struct typevalue arg[3]; DEBUG_PRINTF("factor: token %d\n", current_token); switch(t) { case TOKENIZER_STRING: v->type = TYPE_STRING; len = tokenizer_string_len(); v->d.p = string_temp(len); memcpy(v->d.p + 1, tokenizer_string(), len); DEBUG_PRINTF("factor: string %p\n", v->d.p); accept_tok(TOKENIZER_STRING); break; case TOKENIZER_NUMBER: v->d.i = tokenizer_num(); v->type = TYPE_INTEGER; DEBUG_PRINTF("factor: number %d\n", v->d.i); accept_tok(TOKENIZER_NUMBER); break; case TOKENIZER_LEFTPAREN: accept_tok(TOKENIZER_LEFTPAREN); expr(v); accept_tok(TOKENIZER_RIGHTPAREN); break; case TOKENIZER_INTVAR: case TOKENIZER_STRINGVAR: varfactor(v); break; default: if (TOKENIZER_NUMEXP(t)) { accept_tok(t); switch(t) { case TOKENIZER_PEEK: funcexpr(arg,"I"); v->d.i = peek_function(arg[0].d.i); break; case TOKENIZER_ABS: funcexpr(arg,"I"); v->d.i = arg[0].d.i; if (v->d.i < 0) v->d.i = -v->d.i; break; case TOKENIZER_INT: funcexpr(arg,"I"); v->d.i = arg[0].d.i; break; case TOKENIZER_SGN: funcexpr(arg,"I"); v->d.i = arg[0].d.i; if (v->d.i > 1 ) v->d.i = 1; if (v->d.i < 0) v->d.i = -1; break; case TOKENIZER_LEN: funcexpr(arg,"S"); v->d.i = *arg[0].d.p; break; case TOKENIZER_CODE: funcexpr(arg,"S"); if (*arg[0].d.p) v->d.i = arg[0].d.p[1]; else v->d.i = 0; break; case TOKENIZER_VAL: funcexpr(arg,"S"); v->d.i = string_val(&arg[0]); break; default: syntax_error(); } v->type = TYPE_INTEGER; } else if (TOKENIZER_STRINGEXP(t)) { accept_tok(t); switch(t) { case TOKENIZER_LEFTSTR: funcexpr(arg, "SI"); string_cut(v, &arg[0], 1, arg[1].d.i); break; case TOKENIZER_RIGHTSTR: funcexpr(arg, "SI"); string_cut_r(v, &arg[0], arg[1].d.i); break; case TOKENIZER_MIDSTR: funcexpr(arg, "SII"); string_cut(v, &arg[0], arg[1].d.i, arg[2].d.i); break; case TOKENIZER_CHRSTR: funcexpr(arg, "I"); v->d.p = string_temp(2); v->d.p[1] = arg[0].d.i; v->type = TYPE_STRING; break; default: syntax_error(); } } else syntax_error(); } }