/** * connector() -- make a node for a connector or dictionary word. * * Assumes the current token is a connector or dictionary word. */ static Exp * connector(Dictionary dict) { Exp * n; Dict_node *dn, *dn_head; int i; i = strlen(dict->token) - 1; /* this must be + or - if a connector */ if ((dict->token[i] != '+') && (dict->token[i] != '-')) { /* If we are here, token is a word */ dn_head = abridged_lookup_list(dict, dict->token); dn = dn_head; while ((dn != NULL) && (strcmp(dn->string, dict->token) != 0)) { dn = dn->right; } if (dn == NULL) { free_lookup_list(dn_head); dict_error(dict, "\nPerhaps missing + or - in a connector.\n" "Or perhaps you forgot the suffix on a word.\n" "Or perhaps a word is used before it is defined.\n"); return NULL; } n = make_unary_node(dict, dn->exp); free_lookup_list(dn_head); } else { /* If we are here, token is a connector */ if (!check_connector(dict, dict->token)) { return NULL; } n = Exp_create(dict); n->dir = dict->token[i]; dict->token[i] = '\0'; /* get rid of the + or - */ if (dict->token[0] == '@') { n->u.string = string_set_add(dict->token+1, dict->string_set); n->multi = TRUE; } else { n->u.string = string_set_add(dict->token, dict->string_set); n->multi = FALSE; } n->type = CONNECTOR_type; n->cost = 0.0f; } if (!link_advance(dict)) { exp_free(n); return NULL; } return n; }
Exp * connector(Dictionary dict) { /* the current token is a connector (or a dictionary word) */ /* make a node for it */ Exp * n; Dict_node * dn; int i; i = wcslen(dict->token)-1; /* this must be + or - if a connector */ if ((dict->token[i] != L'+') && (dict->token[i] != L'-')) { dn = abridged_lookup(dict, dict->token); while((dn != NULL) && (wcscmp(dn->string, dict->token) != 0)) { dn = dn->right; } if (dn == NULL) { dict_error(dict, L"\nPerhaps missing + or - in a connector.\n" L"Or perhaps you forgot the suffix on a word.\n" L"Or perhaps a word is used before it is defined.\n"); return NULL; } n = make_unary_node(dict, dn->exp); } else { if (!check_connector(dict, dict->token)) { return NULL; } n = Exp_create(dict); n->dir = dict->token[i]; dict->token[i] = L'\0'; /* get rid of the + or - */ if (dict->token[0] == L'@') { n->u.string = string_set_add(dict->token+1, dict->string_set); n->multi = TRUE; } else { n->u.string = string_set_add(dict->token, dict->string_set); n->multi = FALSE; } n->type = CONNECTOR_type; n->cost = 0; } if (!advance(dict)) { return NULL; } return n; }