EPNODE * getdefn(void) /* A -> SYM = E1 */ /* SYM : E1 */ /* FUNC(SYM,..) = E1 */ /* FUNC(SYM,..) : E1 */ { EPNODE *ep1, *ep2; if (!isalpha(nextc) && nextc != CNTXMARK) syntax("illegal variable name"); ep1 = newnode(); ep1->type = SYM; ep1->v.name = savestr(getname()); if (esupport&E_FUNCTION && nextc == '(') { ep2 = newnode(); ep2->type = FUNC; addekid(ep2, ep1); ep1 = ep2; do { scan(); if (!isalpha(nextc)) syntax("illegal parameter name"); ep2 = newnode(); ep2->type = SYM; ep2->v.name = savestr(getname()); addekid(ep1, ep2); } while (nextc == ','); if (nextc != ')') syntax("')' expected"); scan(); curfunc = ep1; } if (nextc != '=' && nextc != ':') syntax("'=' or ':' expected"); ep2 = newnode(); ep2->type = nextc; scan(); addekid(ep2, ep1); addekid(ep2, getE1()); if (ep1->type == SYM && ep1->sibling->type != NUM) { ep1 = newnode(); ep1->type = CLKT; ep1->v.tick = 0; addekid(ep2, ep1); ep1 = newnode(); ep1->type = NUM; addekid(ep2, ep1); } curfunc = NULL; return(ep2); }
bool Triangle::containsEdge(const Edge & e) const { try { if (e == getE0() || e == getE1() || e == getE2()) return true; } catch (std::exception &e) { std::cout << e.what() << std::endl; } return false; }
EPNODE * eparse( /* parse an expression string */ char *expr ) { EPNODE *ep; initstr(expr, NULL, 0); curfunc = NULL; ep = getE1(); if (nextc != EOF) syntax("unexpected character"); return(ep); }
EPNODE * getchan(void) /* A -> $N = E1 */ { EPNODE *ep1, *ep2; if (nextc != '$') syntax("missing '$'"); scan(); ep1 = newnode(); ep1->type = CHAN; ep1->v.chan = getinum(); if (nextc != '=') syntax("'=' expected"); scan(); ep2 = newnode(); ep2->type = '='; addekid(ep2, ep1); addekid(ep2, getE1()); return(ep2); }
EPNODE * getE5(void) /* E5 -> (E1) */ /* VAR */ /* NUM */ /* $N */ /* FUNC(E1,..) */ /* ARG */ { int i; char *nam; EPNODE *ep1, *ep2; if (nextc == '(') { scan(); ep1 = getE1(); if (nextc != ')') syntax("')' expected"); scan(); return(ep1); } if (esupport&E_INCHAN && nextc == '$') { scan(); ep1 = newnode(); ep1->type = CHAN; ep1->v.chan = getinum(); return(ep1); } if (esupport&(E_VARIABLE|E_FUNCTION) && (isalpha(nextc) || nextc == CNTXMARK)) { nam = getname(); ep1 = NULL; if ((esupport&(E_VARIABLE|E_FUNCTION)) == (E_VARIABLE|E_FUNCTION) && curfunc != NULL) for (i = 1, ep2 = curfunc->v.kid->sibling; ep2 != NULL; i++, ep2 = ep2->sibling) if (!strcmp(ep2->v.name, nam)) { ep1 = newnode(); ep1->type = ARG; ep1->v.chan = i; break; } if (ep1 == NULL) { ep1 = newnode(); ep1->type = VAR; ep1->v.ln = varinsert(nam); } if (esupport&E_FUNCTION && nextc == '(') { ep2 = newnode(); ep2->type = FUNC; addekid(ep2, ep1); ep1 = ep2; do { scan(); addekid(ep1, getE1()); } while (nextc == ','); if (nextc != ')') syntax("')' expected"); scan(); } else if (!(esupport&E_VARIABLE)) syntax("'(' expected"); if (esupport&E_RCONST && isconstvar(ep1)) ep1 = rconst(ep1); return(ep1); } if (isdecimal(nextc)) { ep1 = newnode(); ep1->type = NUM; ep1->v.num = getnum(); return(ep1); } syntax("unexpected character"); return NULL; /* pro forma return */ }