|
|
@ -32,6 +32,12 @@ extern long dynsubst; /* see inpcom.c */ |
|
|
#define ACT_CHARACTS 17 /* actual string length to be inserted and replaced */ |
|
|
#define ACT_CHARACTS 17 /* actual string length to be inserted and replaced */ |
|
|
#define EXP_LENGTH 5 |
|
|
#define EXP_LENGTH 5 |
|
|
|
|
|
|
|
|
|
|
|
#define S_init 0 |
|
|
|
|
|
#define S_atom 1 |
|
|
|
|
|
#define S_binop 2 |
|
|
|
|
|
#define S_unop 3 |
|
|
|
|
|
#define S_stop 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static double |
|
|
static double |
|
|
ternary_fcn(int conditional, double if_value, double else_value) |
|
|
ternary_fcn(int conditional, double if_value, double else_value) |
|
|
@ -924,27 +930,27 @@ fetchoperator(tdico *dico, |
|
|
} else if ((c == '|') && (d == '|')) { |
|
|
} else if ((c == '|') && (d == '|')) { |
|
|
i++; |
|
|
i++; |
|
|
} if ((c == '+') || (c == '-')) { |
|
|
} if ((c == '+') || (c == '-')) { |
|
|
state = 2; /* pending operator */ |
|
|
|
|
|
|
|
|
state = S_binop; /* pending operator */ |
|
|
level = 4; |
|
|
level = 4; |
|
|
} else if ((c == '*') || (c == '/') || (c == '%') || (c == '\\')) { |
|
|
} else if ((c == '*') || (c == '/') || (c == '%') || (c == '\\')) { |
|
|
state = 2; |
|
|
|
|
|
|
|
|
state = S_binop; |
|
|
level = 3; |
|
|
level = 3; |
|
|
} else if (c == '^') { |
|
|
} else if (c == '^') { |
|
|
state = 2; |
|
|
|
|
|
|
|
|
state = S_binop; |
|
|
level = 2; |
|
|
level = 2; |
|
|
} else if (cpos(c, "=<>#GL") >= 0) { |
|
|
} else if (cpos(c, "=<>#GL") >= 0) { |
|
|
state = 2; |
|
|
|
|
|
|
|
|
state = S_binop; |
|
|
level = 5; |
|
|
level = 5; |
|
|
} else if (c == '&') { |
|
|
} else if (c == '&') { |
|
|
state = 2; |
|
|
|
|
|
|
|
|
state = S_binop; |
|
|
level = 6; |
|
|
level = 6; |
|
|
} else if (c == '|') { |
|
|
} else if (c == '|') { |
|
|
state = 2; |
|
|
|
|
|
|
|
|
state = S_binop; |
|
|
level = 7; |
|
|
level = 7; |
|
|
} else if (c == '!') { |
|
|
} else if (c == '!') { |
|
|
state = 3; |
|
|
|
|
|
|
|
|
state = S_unop; |
|
|
} else { |
|
|
} else { |
|
|
state = 0; |
|
|
|
|
|
|
|
|
state = S_init; |
|
|
if (c > ' ') |
|
|
if (c > ' ') |
|
|
error = message(dico, "Syntax error: letter [%c]", c); |
|
|
error = message(dico, "Syntax error: letter [%c]", c); |
|
|
} |
|
|
} |
|
|
@ -975,36 +981,36 @@ opfunctkey(tdico *dico, |
|
|
/* & | ~ DIV MOD Defined */ |
|
|
/* & | ~ DIV MOD Defined */ |
|
|
case 1: |
|
|
case 1: |
|
|
c = '&'; |
|
|
c = '&'; |
|
|
state = 2; |
|
|
|
|
|
|
|
|
state = S_binop; |
|
|
level = 6; |
|
|
level = 6; |
|
|
break; |
|
|
break; |
|
|
case 2: |
|
|
case 2: |
|
|
c = '|'; |
|
|
c = '|'; |
|
|
state = 2; |
|
|
|
|
|
|
|
|
state = S_binop; |
|
|
level = 7; |
|
|
level = 7; |
|
|
break; |
|
|
break; |
|
|
case 3: |
|
|
case 3: |
|
|
c = '!'; |
|
|
c = '!'; |
|
|
state = 3; |
|
|
|
|
|
|
|
|
state = S_unop; |
|
|
level = 1; |
|
|
level = 1; |
|
|
break; |
|
|
break; |
|
|
case 4: |
|
|
case 4: |
|
|
c = '\\'; |
|
|
c = '\\'; |
|
|
state = 2; |
|
|
|
|
|
|
|
|
state = S_binop; |
|
|
level = 3; |
|
|
level = 3; |
|
|
break; |
|
|
break; |
|
|
case 5: |
|
|
case 5: |
|
|
c = '%'; |
|
|
c = '%'; |
|
|
state = 2; |
|
|
|
|
|
|
|
|
state = S_binop; |
|
|
level = 3; |
|
|
level = 3; |
|
|
break; |
|
|
break; |
|
|
case Defd: |
|
|
case Defd: |
|
|
c = '?'; |
|
|
c = '?'; |
|
|
state = 1; |
|
|
|
|
|
|
|
|
state = S_atom; |
|
|
level = 0; |
|
|
level = 0; |
|
|
break; |
|
|
break; |
|
|
default: |
|
|
default: |
|
|
state = 0; |
|
|
|
|
|
|
|
|
state = S_init; |
|
|
error = message(dico, " Unexpected Keyword"); |
|
|
error = message(dico, " Unexpected Keyword"); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
@ -1153,11 +1159,11 @@ formula(tdico *dico, char *s, bool *perror) |
|
|
while ((ls > 0) && (s[ls - 1] <= ' ')) |
|
|
while ((ls > 0) && (s[ls - 1] <= ' ')) |
|
|
ls--; /* clean s */ |
|
|
ls--; /* clean s */ |
|
|
|
|
|
|
|
|
state = 0; |
|
|
|
|
|
|
|
|
state = S_init; |
|
|
natom = 0; |
|
|
natom = 0; |
|
|
ustack = 0; |
|
|
ustack = 0; |
|
|
topop = 0; |
|
|
topop = 0; |
|
|
oldstate = 0; |
|
|
|
|
|
|
|
|
oldstate = S_init; |
|
|
fu = 0; |
|
|
fu = 0; |
|
|
error = 0; |
|
|
error = 0; |
|
|
level = 0; |
|
|
level = 0; |
|
|
@ -1212,7 +1218,7 @@ formula(tdico *dico, char *s, bool *perror) |
|
|
} |
|
|
} |
|
|
pscopy(&tstr, s, i, k - i - 1); |
|
|
pscopy(&tstr, s, i, k - i - 1); |
|
|
u = formula(dico, spice_dstring_value(&tstr), &error); |
|
|
u = formula(dico, spice_dstring_value(&tstr), &error); |
|
|
state = 1; /* atom */ |
|
|
|
|
|
|
|
|
state = S_atom; |
|
|
if (fu > 0) { |
|
|
if (fu > 0) { |
|
|
if ((fu == 18)) |
|
|
if ((fu == 18)) |
|
|
u = ternary_fcn((int) v, w, u); |
|
|
u = ternary_fcn((int) v, w, u); |
|
|
@ -1234,7 +1240,7 @@ formula(tdico *dico, char *s, bool *perror) |
|
|
fu = 0; |
|
|
fu = 0; |
|
|
} else if (alfa(c)) { |
|
|
} else if (alfa(c)) { |
|
|
i = fetchid(s, &tstr, ls, i); /* user id, but sort out keywords */ |
|
|
i = fetchid(s, &tstr, ls, i); /* user id, but sort out keywords */ |
|
|
state = 1; |
|
|
|
|
|
|
|
|
state = S_atom; |
|
|
i--; |
|
|
i--; |
|
|
kw = keyword(&keyS, &tstr); /* debug ws('[',kw,']'); */ |
|
|
kw = keyword(&keyS, &tstr); /* debug ws('[',kw,']'); */ |
|
|
if (kw == 0) { |
|
|
if (kw == 0) { |
|
|
@ -1242,7 +1248,7 @@ formula(tdico *dico, char *s, bool *perror) |
|
|
if (fu == 0) |
|
|
if (fu == 0) |
|
|
u = fetchnumentry(dico, spice_dstring_value(&tstr), &error); |
|
|
u = fetchnumentry(dico, spice_dstring_value(&tstr), &error); |
|
|
else |
|
|
else |
|
|
state = 0; /* state==0 means: ignore for the moment */ |
|
|
|
|
|
|
|
|
state = S_init; /* S_init means: ignore for the moment */ |
|
|
} else { |
|
|
} else { |
|
|
c = opfunctkey(dico, kw, c, &state, &level, &error); |
|
|
c = opfunctkey(dico, kw, c, &state, &level, &error); |
|
|
} |
|
|
} |
|
|
@ -1255,7 +1261,7 @@ formula(tdico *dico, char *s, bool *perror) |
|
|
u = -1 * u; |
|
|
u = -1 * u; |
|
|
negate = 0; |
|
|
negate = 0; |
|
|
} |
|
|
} |
|
|
state = 1; |
|
|
|
|
|
|
|
|
state = S_atom; |
|
|
} else { |
|
|
} else { |
|
|
c = fetchoperator(dico, s, ls, &i, &state, &level, &error); |
|
|
c = fetchoperator(dico, s, ls, &i, &state, &level, &error); |
|
|
} |
|
|
} |
|
|
@ -1263,11 +1269,11 @@ formula(tdico *dico, char *s, bool *perror) |
|
|
/* may change c to some other operator char! */ |
|
|
/* may change c to some other operator char! */ |
|
|
/* control chars <' ' ignored */ |
|
|
/* control chars <' ' ignored */ |
|
|
|
|
|
|
|
|
ok = (oldstate == 0) || (state == 0) || |
|
|
|
|
|
((oldstate == 1) && (state == 2)) || |
|
|
|
|
|
((oldstate != 1) && (state != 2)); |
|
|
|
|
|
|
|
|
ok = (oldstate == S_init) || (state == S_init) || |
|
|
|
|
|
((oldstate == S_atom) && (state == S_binop)) || |
|
|
|
|
|
((oldstate != S_atom) && (state != S_binop)); |
|
|
|
|
|
|
|
|
if (oldstate == 2 && state == 2 && c == '-') { |
|
|
|
|
|
|
|
|
if (oldstate == S_binop && state == S_binop && c == '-') { |
|
|
ok = 1; |
|
|
ok = 1; |
|
|
negate = 1; |
|
|
negate = 1; |
|
|
continue; |
|
|
continue; |
|
|
@ -1276,15 +1282,15 @@ formula(tdico *dico, char *s, bool *perror) |
|
|
if (!ok) |
|
|
if (!ok) |
|
|
error = message(dico, " Misplaced operator"); |
|
|
error = message(dico, " Misplaced operator"); |
|
|
|
|
|
|
|
|
if (state == 3) { |
|
|
|
|
|
|
|
|
if (state == S_unop) { |
|
|
/* push unary operator */ |
|
|
/* push unary operator */ |
|
|
ustack++; |
|
|
ustack++; |
|
|
uop[ustack] = c; |
|
|
uop[ustack] = c; |
|
|
} else if (state == 1) { |
|
|
|
|
|
|
|
|
} else if (state == S_atom) { |
|
|
/* atom pending */ |
|
|
/* atom pending */ |
|
|
natom++; |
|
|
natom++; |
|
|
if (i >= ls) { |
|
|
if (i >= ls) { |
|
|
state = 4; |
|
|
|
|
|
|
|
|
state = S_stop; |
|
|
level = topop; |
|
|
level = topop; |
|
|
} /* close all ops below */ |
|
|
} /* close all ops below */ |
|
|
|
|
|
|
|
|
@ -1295,7 +1301,7 @@ formula(tdico *dico, char *s, bool *perror) |
|
|
accu[0] = u; /* done: all pending unary operators */ |
|
|
accu[0] = u; /* done: all pending unary operators */ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ((state == 2) || (state == 4)) { |
|
|
|
|
|
|
|
|
if ((state == S_binop) || (state == S_stop)) { |
|
|
/* do pending binaries of priority Upto "level" */ |
|
|
/* do pending binaries of priority Upto "level" */ |
|
|
for (k = 1; k <= level; k++) { |
|
|
for (k = 1; k <= level; k++) { |
|
|
/* not yet speed optimized! */ |
|
|
/* not yet speed optimized! */ |
|
|
@ -1309,11 +1315,11 @@ formula(tdico *dico, char *s, bool *perror) |
|
|
topop = level; |
|
|
topop = level; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (state != 0) |
|
|
|
|
|
|
|
|
if (state != S_init) |
|
|
oldstate = state; |
|
|
oldstate = state; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ((natom == 0) || (oldstate != 4)) |
|
|
|
|
|
|
|
|
if ((natom == 0) || (oldstate != S_stop)) |
|
|
error = message(dico, " Expression err: %s", s); |
|
|
error = message(dico, " Expression err: %s", s); |
|
|
|
|
|
|
|
|
if (negate == 1) |
|
|
if (negate == 1) |
|
|
|