91 #define issep(c) ((c)==' '||(c)=='\t'||(c)=='='||(c)=='('||(c)==')'||\ 92 (c)==','||(c)=='-'||(c)=='+'||(c)=='*'||(c)=='/'||(c)=='^') 122 *line += strlen(*line) - strlen(tl);
135 (*pt)->p.varTypes =
types;
166 char *newline, *nl, *tl;
167 int len, olen,
count = 0;
173 len = strlen(newline);
177 while (*tl &&
issep(*tl)) {
178 if ((olen = (nl - newline)) >= len) {
191 while (*tl && !
issep(*tl))
200 if ((s = strchr(tok,
'#')) !=
NULL && !strcmp(s+1,
"branch")) {
203 buf =
tmalloc(strlen(tok) + 4);
204 sprintf(buf,
"i(%s)",tok);
209 if (*tok ==
'x' && !*(tok+1) && ft_sim->
ptXalias) {
217 if ((olen = (nl - newline)) >= len) {
255 newp =
mkcon((
double) 0);
260 if (p->valueIndex == varnum)
261 newp =
mkcon((
double) 1);
263 newp =
mkcon((
double) 0);
282 newp =
mkb(p->type, arg1, arg2);
331 mkcon(p->right->constant),
333 mkcon(p->right->constant - 1))),
362 switch (p->funcnum) {
383 mkcon((
double) 1))));
398 mkcon((
double) 1))));
404 2)),
mkcon((
double) 1)));
410 p->left,
mkcon((
double) 2))));
460 arg1 =
mkcon((
double) - 1.0);
464 fprintf(stderr,
"Internal Error: bad function # %d\n",
490 fprintf(stderr,
"Internal error: bad node type %d\n", p->type);
522 (
double*)
tmalloc(new->numtrancoeffs*
sizeof(
double));
523 memcpy(new->trancoeffs,p->trancoeffs,new->numtrancoeffs*
sizeof(
double));
525 new->trancache = (
double*)
tmalloc(2*
sizeof(
double));
527 else if (new->funcnum ==
PTF_tPWL) {
528 num =
new->numtrancoeffs/2 - 1;
529 new->trancache = (
double*)
tmalloc(num*
sizeof(
double));
530 memcpy(new->trancache,p->trancache,num*
sizeof(
double));
626 if (
PTops[i].number == type)
629 fprintf(stderr,
"Internal Error: bad type %d\n", type);
659 fprintf(stderr,
"Internal Error: bad type %d\n", type);
665 return (
mkcon(constval));
709 fprintf(stderr,
"Internal error: bad node type %d\n", p->type);
724 {
R,
L,
L,
L,
L,
L,
L,
L,
R,
L, R },
725 {
G,
G,
G,
L,
L,
L,
L,
L,
G,
L, G },
726 {
G,
G,
G,
L,
L,
L,
L,
L,
G,
L, G },
727 {
G,
G,
G,
G,
G,
L,
L,
L,
G,
L, G },
728 {
G,
G,
G,
G,
G,
L,
L,
L,
G,
L, G },
729 {
G,
G,
G,
G,
G,
L,
L,
L,
G,
L, G },
730 {
G,
G,
G,
G,
G,
G,
G,
L,
G,
L, R },
731 {
R,
L,
L,
L,
L,
L,
L,
L,
E,
L, L },
732 {
G,
G,
G,
G,
G,
G,
G,
R,
G,
R, G },
733 {
G,
G,
G,
G,
G,
G,
G,
G,
G,
R, G },
734 {
G,
L,
L,
L,
L,
L,
L,
L,
G,
L, G }
769 bcopy((
char *) next, (
char *) &stack[++sp],
792 [stack[sp].token] ==
L)
825 else if ((stack[sp + 1].token ==
TOK_LPAREN) &&
838 pn =
mkbnode(stack[sp + 1].token, lpn, rpn);
866 switch (elem->type) {
868 return (
mksnode(elem->value.string));
871 return (
mknnode(elem->value.real));
874 return (elem->value.pnode);
877 fprintf(stderr,
"Internal Error: bad token type\n");
894 if (
PTops[i].number == opnum)
898 fprintf(stderr,
"Internal Error: no such op num %d\n", opnum);
929 if (!strcmp(fname,
"v")) {
936 (void) sprintf(name,
"%d", (
int) arg->
constant);
956 if (i == numvalues) {
960 (numvalues + 1) *
sizeof (
IFvalue));
963 (numvalues + 1) *
sizeof (
int));
978 else if (!strcmp(fname,
"i")) {
985 (void) sprintf(name,
"%d", (
int) arg->
constant);
998 if (i == numvalues) {
1002 (numvalues + 1) *
sizeof (
IFvalue));
1005 (numvalues + 1) *
sizeof (
int));
1021 if (!strcmp(
PTfuncs[i].name, fname))
1027 sprintf(
errMsg,
"no such function '%s'",fname);
1091 if (!strcmp(ft_sim->
specSigs[i],
string))
1093 if (i < ft_sim->numSpecSigs) {
1131 static char *specials =
" \t()^+-*/,";
1140 while ((*sbuf ==
' ') || (*sbuf ==
'\t') || (*sbuf ==
'='))
1205 while (isalpha(*sbuf))
1218 lasttoken = el.
token;
1235 char **
s, *specials;
1241 for (t = *s, i = 0; *t; t++, i++) {
1242 if (strchr(specials,*t))
1256 for ( ; *t; t++, i++) {
1271 for (t = buf; *t; t++)
1272 if (isupper(*t)) *t = tolower(*t);
1294 if (strcmp(name,
"sin") && strcmp(name,
"exp"))
1297 for (n = 0, s = str; *s !=
')'; n++,s++) ;
1318 if (!error && n >= 2)
1347 while (*tt && !isspace(*tt)) tt++;
1355 fprintf(stderr,
"Internal Error: no such tran function '%s'", s);
1362 list = (
double *)
tmalloc(
sizeof(
double));
1364 while (error == 0) {
1367 trealloc((
char *)list,num*
sizeof(double));
1368 *(list+num-1) = tmp;
1386 for (i = 0; i < num; i++) {
1425 return (pnodes[nodes-1]);
1428 for (i = 0; i < nodes; i++) {
1438 txfree((
char*)pnodes[i]);
1441 for (i = 0; i < nodes; i++) {
1443 txfree((
char*)pnodes[i]);
1476 *res = vals[tree->valueIndex];
1489 *res = parms[tree->valueIndex];
1505 err = (*tree->left->evfunc)(tree->left, &r1, vals, parms);
1508 *res = (*tree->function)(r1);
1531 err = (*tree->left->evfunc)(tree->left, &r1, vals, parms);
1535 if (tree->funcnum == 0)
1552 *res = (*tree->function)(tree,parms);
1568 err = (*tree->left->evfunc)(tree->left, &r1, vals, parms);
1571 err = (*tree->right->evfunc)(tree->right, &r2, vals, parms);
1574 *res = (*tree->function)(r1, r2);
1603 printf(
"%s\n\t", str);
1606 for (i = 0; i < ptree->
numVars; i++) {
1607 printf(
"d / d v%d : ", i);
1624 printf(
"%g", pt->constant);
1628 printf(
"v%d", pt->valueIndex);
1632 printf(
"%s", ft_sim->
specSigs[pt->valueIndex]);
1676 printf(
"%s (", pt->funcname);
1682 printf(
"%s (", pt->funcname);
1683 for (i = 0; i < pt->numtrancoeffs; i++)
1684 printf(
" %g",pt->trancoeffs[i]);
static char buf[MAXPROMPT]
union PTelement::@15 value
struct sPTfunc PTtFuncs[]
static struct tab table[512]
static INPparseNode * mknnode()
static INPparseNode * PTdifferentiate()
double INPtablEvalDeriv(GENERIC *tab, double x)
static INPparseNode * mkcon()
static INPparseNode * allocate_pnode()
static INPparseNode * mkbnode()
static INPparseNode * makepnode()
static char * get_stringvar()
struct INPparseNode * right
static INPtables * tables
struct INPparseNode * left
static INPparseNode * mkf()
static INPparseNode * mkb()
static INPparseNode * mkfnode()
static INPparseNode * copy_node()
static INPparseNode * mksnode()
void INPptPrint(char *str, IFparseTree *ptree)
static char prectable[11][11]
void INPgetTree(char **line, INPparseTree **pt, GENERIC *ckt, INPtables *tab)
static INPparseNode * PTparse()
void bcopy(char *from, char *to, int num)
static struct constant constants[]
static PTelement * PTlexer()