// Parse a postfix expr. // // postfix-expr ::= applicaiton-expr Tree* parse_postfix_expr(Parser& p) { if (Tree* t1 = parse_primary_expr(p)) { while (t1) { if (Tree* t2 = parse_dot_expr(p, t1)) t1 = t2; else if (Tree* t2 = parse_application_expr(p, t1)) t1 = t2; else if (Tree* t2 = parse_and_expr(p, t1)) t1 = t2; else if (Tree* t2 = parse_or_expr(p, t1)) t1 = t2; else if (Tree* t2 = parse_eq_comp_expr(p, t1)) t1 = t2; else if (Tree* t2 = parse_less_expr(p, t1)) t1 = t2; else if (Tree* t2 = parse_union(p, t1)) t1 = t2; else if (Tree* t2 = parse_intersect(p, t1)) t1 = t2; else if (Tree* t2 = parse_except(p, t1)) t1 = t2; else if (Tree* t2 = parse_join(p, t1)) t1 = t2; else if (Tree* t2 = parse_as(p, t1)) t1 = t2; else break; } return t1; } return parse_primary_expr(p); }
static int parse_expr (pfstate_t *pf) { int result; result = parse_or_expr (pf); return (result); }
ParsingErrors parse(const char input[], var_t *result) { expr_t expr_root; assert(initialized && "Parser must be initialized before use."); last_error = PE_NO_ERROR; last_token.type = BEGIN; last_position = input; get_next(&last_position); expr_root = parse_or_expr(&last_position); last_parsed_char = last_position; if(last_token.type != END) { if(last_parsed_char > input) { last_parsed_char--; } if(last_error == PE_NO_ERROR) { if(last_token.type == DQ && strchr(last_position, '"') == NULL) { /* This is a comment, just ignore it. */ last_position += strlen(last_position); } else if(eval_expr(&expr_root) == 0) { var_free(res_val); res_val = var_clone(expr_root.value); last_error = PE_INVALID_EXPRESSION; } } } if(last_error == PE_NO_ERROR) { if(eval_expr(&expr_root) == 0) { var_free(res_val); res_val = var_clone(expr_root.value); *result = var_clone(expr_root.value); } } if(last_error == PE_INVALID_EXPRESSION) { last_position = skip_whitespace(input); } free_expr(&expr_root); return last_error; }