// + && - static TreeNode * _simple_exp(void) { TreeNode *t = _term(); while (token == PLUS || token == MINUS) { TreeNode *q = new_exp_node(OpK); q->child[0] = t; q->attr.op = token; t = q; _match(token); t->child[1] = _term(); } return t; }
static struct rx_node *_closure_term(struct parse_sp *ps) { struct rx_node *l, *n; if (!(l = _term(ps))) return NULL; for (;;) { switch (ps->type) { case '*': n = _node(ps->mem, STAR, l, NULL); break; case '+': n = _node(ps->mem, PLUS, l, NULL); break; case '?': n = _node(ps->mem, QUEST, l, NULL); break; default: return l; } if (!n) return_NULL; _rx_get_token(ps); l = n; } return n; }
int value(void * bp, int get(void * bp), int unget(int c, void * bp)) { extern signed c; int n = _term(bp, get, unget); while ((c = get(bp)) != EOF) { if (isblank(c)) continue; else if(c == '+') n += _term(bp, get, unget); else if(c == '-') n -= _term(bp, get, unget); else { unget (c, bp); break; } } return (n); }
int Parser::_expr() { int value = _term(); TokenType t = _token(); while (_success && (t == TT_PLUS || t == TT_MINUS)) { _scanner.advance(); switch (t) { case TT_PLUS: value += _term(); break; case TT_MINUS: value -= _term(); break; default: notifyListeners("ERROR: Unknown error"); _success = false; return 0; } t = _token(); } return value; }
double WidgetCalc::_expr(const std::string& str, unsigned *idx) { double result = _term(str, idx); while (str[*idx] == '+' || str[*idx] == '-') { switch (str[*idx]) { case '+': ++*idx; result += _term(str, idx); break; case '-': ++*idx; result -= _term(str, idx); break; } } return result; }
RegNodePtr _repeat() { auto r = _term(); if (tryConsume('+')) { r.reset(new RegNode_Repeat(r, 1, RegNode_Repeat::MAX_REPEAT)); } else if (tryConsume('*')) { r.reset(new RegNode_Repeat(r, 0, RegNode_Repeat::MAX_REPEAT)); } else if (tryConsume('?')) { r.reset(new RegNode_Repeat(r, 0, 1)); } else {} return r; }