Exp * expression(Dictionary dict) { /* Build (and return the root of) the tree for the expression beginning */ /* with the current token. At the end, the token is the first one not part */ /* of this expression. */ Exp * n; if (is_equal(dict, L'(')) { if (!advance(dict)) { return NULL; } n = in_parens(dict); if (!is_equal(dict, L')')) { dict_error(dict, L"Expecting a \")\"."); return NULL; } if (!advance(dict)) { return NULL; } } else if (is_equal(dict, L'{')) { if (!advance(dict)) { return NULL; } n = in_parens(dict); if (!is_equal(dict, L'}')) { dict_error(dict, L"Expecting a \"}\"."); return NULL; } if (!advance(dict)) { return NULL; } n = make_optional_node(dict, n); } else if (is_equal(dict, L'[')) { if (!advance(dict)) { return NULL; } n = in_parens(dict); if (!is_equal(dict, L']')) { dict_error(dict, L"Expecting a \"]\"."); return NULL; } if (!advance(dict)) { return NULL; } n->cost += 1; } else if (!dict->is_special) { n = connector(dict); if (n == NULL) { return NULL; } } else if (is_equal(dict, L')') || is_equal(dict, L']')) { /* allows "()" or "[]" */ n = make_zeroary_node(dict); } else { dict_error(dict, L"Connector, \"(\", \"[\", or \"{\" expected."); return NULL; } return n; }
/** * Build (and return the root of) the tree for the expression beginning * with the current token. At the end, the token is the first one not * part of this expression. */ Exp * expression(Dictionary dict) { Exp * n; if (is_equal(dict, '(')) { if (!link_advance(dict)) { return NULL; } n = in_parens(dict); if (!is_equal(dict, ')')) { dict_error(dict, "Expecting a \")\"."); return NULL; } if (!link_advance(dict)) { return NULL; } } else if (is_equal(dict, '{')) { if (!link_advance(dict)) { return NULL; } n = in_parens(dict); if (!is_equal(dict, '}')) { dict_error(dict, "Expecting a \"}\"."); return NULL; } if (!link_advance(dict)) { return NULL; } n = make_optional_node(dict, n); } else if (is_equal(dict, '[')) { if (!link_advance(dict)) { return NULL; } n = in_parens(dict); if (!is_equal(dict, ']')) { dict_error(dict, "Expecting a \"]\"."); return NULL; } if (!link_advance(dict)) { return NULL; } n->cost += 1.0f; } else if (!dict->is_special) { n = connector(dict); if (n == NULL) { return NULL; } } else if (is_equal(dict, ')') || is_equal(dict, ']')) { /* allows "()" or "[]" */ n = make_zeroary_node(dict); } else { dict_error(dict, "Connector, \"(\", \"[\", or \"{\" expected."); return NULL; } return n; }