56#define CHECKPOLY {if(polyflag)MesPrint("&Illegal use of polynomial function"); polyflag = 0; }
58int tokenize(UBYTE *in, WORD leftright)
60 int error = 0, object, funlevel = 0, bracelevel = 0, explevel = 0, numexp;
64 SBYTE *out, *outtop, num[MAXNUMSIZE], *t;
66 if ( AC.tokens == 0 ) {
67 SBYTE **ppp = &(AC.tokens);
68 SBYTE **pppp = &(AC.toptokens);
69 DoubleBuffer((
void **)ppp,(
void **)pppp,
sizeof(SBYTE),
"start tokens");
72 outtop = AC.toptokens - MAXNUMSIZE;
77 LONG oldsize = (LONG)(out - AC.tokens);
78 SBYTE **ppp = &(AC.tokens);
79 SBYTE **pppp = &(AC.toptokens);
80 DoubleBuffer((
void **)ppp,(
void **)pppp,
sizeof(SBYTE),
"expand tokens");
81 out = AC.tokens + oldsize;
82 outtop = AC.toptokens - MAXNUMSIZE;
84 switch ( FG.cTable[*in] ) {
88 while ( FG.cTable[*in] == 0 || FG.cTable[*in] == 1
90dovariable: c = *in; *in = 0;
92 MesPrint(
"&Illegal position for %s",s);
93 if ( !error ) error = 1;
95 if ( out > AC.tokens && ( out[-1] == TWILDCARD || out[-1] == TNOT ) ) {
96 type = GetName(AC.varnames,s,&number,NOAUTO);
99 type = GetName(AC.varnames,s,&number,WITHAUTO);
102 type = GetName(AC.exprnames,s,&number,NOAUTO);
104 case CSYMBOL: *out++ = TSYMBOL;
break;
106 if ( number >= (AM.IndDum-AM.OffsetIndex) ) {
108 MesPrint(
"&Generated indices should be of the type Nnumber_?");
112 *in++ = c; c = *in; *in = 0;
118 case CVECTOR: *out++ = TVECTOR;
break;
129 if ( AP.PreAssignFlag || AP.PreInsideLevel ) {
130 switch ( number + FUNCTION ) {
133 AC.RhsExprInModuleFlag = 1;
139 case CSET: *out++ = TSET;
break;
140 case CEXPRESSION: *out++ = TEXPRESSION;
141 if ( leftright == LHSIDE ) {
142 if ( !error ) error = 1;
143 MesPrint(
"&Expression not allowed in LH-side of substitution: %s",s);
151 AC.RhsExprInModuleFlag = 1;
153 if ( !AP.PreAssignFlag && !AP.PreInsideLevel )
154 Expressions[number].vflags |= ISINRHS;
157 if ( AC.exprfillwarning == 0 ) {
158 AC.exprfillwarning = 1;
161 case CDELTA: *out++ = TDELTA; *in = c;
162 object = 1;
continue;
163 case CDUBIOUS: *out++ = TDUBIOUS;
break;
164 default: *out++ = TDUBIOUS;
165 if ( !error ) error = 1;
166 MesPrint(
"&Undeclared variable %s",s);
167 number = AddDubious(s);
172 do { num[i++] = (SBYTE)(number & 0x7F); number >>= 7; }
while ( number );
173 while ( --i >= 0 ) *out++ = num[i];
184 while ( *s ==
'0' && FG.cTable[s[1]] == 1 ) s++;
186 while ( FG.cTable[*in] == 1 ) { in++; i++; }
189 MesPrint(
"&Illegal position for %s",s);
191 if ( !error ) error = 1;
193 if ( i == 1 && *in ==
'_' && ( *s ==
'5' || *s ==
'6'
195 in++; *out++ = TSGAMMA; *out++ = (SBYTE)(*s -
'4');
200 in2 = CheckFloat(in,&spec);
203 MesPrint(
"&The floating point system has not been started: %s",in);
204 if ( !error ) error = 1;
209 while ( out + (in-s) >= AC.toptokens ) {
210 LONG oldsize = (LONG)(out - AC.tokens);
211 SBYTE **ppp = &(AC.tokens);
212 SBYTE **pppp = &(AC.toptokens);
213 DoubleBuffer((
void **)ppp,(
void **)pppp,
sizeof(SBYTE),
"more tokens");
214 out = AC.tokens + oldsize;
215 outtop = AC.toptokens - MAXNUMSIZE;
218 while ( s < in ) *out++ = *s++;
225 if ( ( i & 1 ) != 0 ) *out++ = (SBYTE)(*s++ -
'0');
226 while ( out + (in-s)/2 >= AC.toptokens ) {
227 LONG oldsize = (LONG)(out - AC.tokens);
228 SBYTE **ppp = &(AC.tokens);
229 SBYTE **pppp = &(AC.toptokens);
230 DoubleBuffer((
void **)ppp,(
void **)pppp,
sizeof(SBYTE),
"more tokens");
231 out = AC.tokens + oldsize;
232 outtop = AC.toptokens - MAXNUMSIZE;
235 *out++ = (SBYTE)(( *s -
'0' ) * 10 + ( s[1] -
'0' ));
245 if ( leftright == LHSIDE ) {
247 in++; *out++ = TWILDCARD;
248 if ( FG.cTable[in[0]] == 0 || in[0] ==
'[' || in[0] ==
'{' )
object = 0;
250 else if (
object == -1 ) {
252 while ( FG.cTable[*in] == 0 || FG.cTable[*in] == 1 ) in++;
254 if ( FG.cTable[*s] != 0 ) {
255 MesPrint(
"&Illegal name for argument list variable %s",s);
259 i = AddWildcardName((UBYTE *)s);
267 MesPrint(
"&Illegal position for ?");
273 if (
object != -1 )
goto IllPos;
275 if ( FG.cTable[*in] == 0 || FG.cTable[*in] == 1 ) {
277 while ( FG.cTable[*in] == 0 || FG.cTable[*in] == 1 ) in++;
279 i = GetWildcardName((UBYTE *)s);
281 MesPrint(
"&Undefined argument list variable %s",s);
289 if ( AC.vectorlikeLHS == 0 ) {
290 MesPrint(
"&Generated index ? only allowed in vector substitution",s);
298 else if ( *in ==
'.' ) {
305 else if (
object == 0 ||
object == -1 ) {
310 s = CheckFloat(in,&spec);
313 MesPrint(
"&The floating point system has not been started: %s",in);
314 if ( !error ) error = 1;
318 UBYTE *a = s; s = in; in = a;
327 else if ( *in ==
'$' ) {
330 if ( FG.cTable[*in] == 0 ) {
331 while ( FG.cTable[*in] == 0 || FG.cTable[*in] == 1 ) in++;
332 if ( *in ==
'_' && AP.PreAssignFlag == 2 ) in++;
335 if (
object != 1 || leftright == RHSIDE ) {
336 MesPrint(
"&Illegal position for $%s",s);
337 if ( !error ) error = 1;
340 if ( ( number = GetDollar(s) ) < 0 ) {
341 number = AddDollar(s,0,0,0);
345 else if ( ( number = GetDollar(s) ) < 0 ) {
346 MesPrint(
"&Undefined variable $%s",s);
347 if ( !error ) error = 1;
348 number = AddDollar(s,0,0,0);
352 if ( ( AC.exprfillwarning == 0 ) &&
353 ( ( out > AC.tokens+1 ) && ( out[-2] != TWILDCARD ) ) ) {
354 AC.exprfillwarning = 1;
359 MesPrint(
"Illegal name for $ variable after %s",in);
360 if ( !error ) error = 1;
363 else if ( *in ==
'#' ) {
369 MesPrint(
"&Illegal position for %#");
380 if ( *t == RPARENTHESIS ) {
381 *out++ = LBRACE; *out++ = LPARENTHESIS;
382 bracelevel++; explevel = bracelevel;
385 while ( *t >= 0 && t > AC.tokens ) t--;
386 if ( *t == TEXPRESSION ) {
387 *out++ = LBRACE; *out++ = LPARENTHESIS;
388 bracelevel++; explevel = bracelevel;
390 else {*out++ = LBRACE; bracelevel++; }
401 if ( explevel > 0 && explevel == bracelevel ) {
402 *out++ = RPARENTHESIS; explevel = 0;
404 *out++ = RBRACE;
object = 1; bracelevel--;
410 if ( funlevel >= AM.MaxParLevel ) {
411 MesPrint(
"&More than %d levels of parentheses",AM.MaxParLevel);
415 AC.tokenarglevel[funlevel++] = TYPEISFUN;
418 if ( in[1] !=
')' && in[1] !=
',' ) {
419 *out++ = TNUMBER; *out++ = (SBYTE)(polyflag);
421 *out++ = LPARENTHESIS;
424 *out++ = LPARENTHESIS;
425 *out++ = TNUMBER; *out++ = (SBYTE)(polyflag);
429 else if ( in[1] !=
')' && in[1] !=
',' ) {
430 *out++ = LPARENTHESIS;
433 else if (
object <= 0 ) {
435 AC.tokenarglevel[funlevel++] = TYPEISSUB;
436 *out++ = LPARENTHESIS;
440 AC.tokenarglevel[funlevel++] = TYPEISMYSTERY;
441 MesPrint(
"&Illegal position for (: %s",in);
442 if ( error >= 0 ) error = -1;
446 else if ( *in ==
')' ) {
448 if ( funlevel < 0 ) {
450 MesPrint(
"&There is an unmatched parenthesis");
451 if ( error >= 0 ) error = -1;
454 else if (
object <= 0
455 && ( AC.tokenarglevel[funlevel] != TYPEISFUN
456 || out[-1] != TFUNOPEN ) ) {
457 MesPrint(
"&Illegal position for closing parenthesis.");
458 if ( error >= 0 ) error = -1;
459 if ( AC.tokenarglevel[funlevel] == TYPEISFUN )
object = 1;
463 if ( AC.tokenarglevel[funlevel] == TYPEISFUN ) {
464 if ( out[-1] == TFUNOPEN ) out--;
466 if ( out[-1] != TCOMMA ) *out++ = RPARENTHESIS;
471 else if ( AC.tokenarglevel[funlevel] == TYPEISSUB ) {
472 *out++ = RPARENTHESIS;
477 else if ( *in ==
',' ) {
479 AC.tokenarglevel[funlevel-1] == TYPEISFUN ) {
480 if ( out[-1] != TFUNOPEN && out[-1] != TCOMMA )
481 *out++ = RPARENTHESIS;
482 else { *out++ = TNUMBER; *out++ = 0; }
484 if ( in[1] !=
',' && in[1] !=
')' )
485 *out++ = LPARENTHESIS;
486 else if ( in[1] ==
')' ) {
487 *out++ = TNUMBER; *out++ = 0;
495 MesPrint(
"&Illegal position for comma: %s",in);
496 MesPrint(
"&Forgotten ; ?");
497 if ( error >= 0 ) error = -1;
506 if ( *in ==
':' || *in ==
'%' )
goto IllPos;
507 if ( *in ==
'*' || *in ==
'/' || *in ==
'^' ) {
509 MesPrint(
"&Illegal position for operator: %s",in);
510 if ( error >= 0 ) error = -1;
512 else if ( *in ==
'*' ) *out++ = TMULTIPLY;
513 else if ( *in ==
'/' ) *out++ = TDIVIDE;
514 else *out++ = TPOWER;
519 while ( *in ==
'+' || *in ==
'-' ) {
520 if ( *in ==
'-' ) i = -i;
524 if ( out > AC.tokens && out[-1] != TFUNOPEN &&
525 out[-1] != LPARENTHESIS && out[-1] != TCOMMA
526 && out[-1] != LBRACE )
529 else *out++ = TMINUS;
539 MesPrint(
"&Illegal position for %s",in);
540 if ( !error ) error = 1;
544 number = DoTempSet(s,in);
549 do { num[i++] = (SBYTE)(number & 0x7F); number >>= 7; }
while ( number );
550 while ( --i >= 0 ) *out++ = num[i];
552 else if ( error == 0 ) error = 1;
559 if ( *in !=
'!' || leftright == RHSIDE
560 ||
object != 1 || out[-1] != TWILDCARD )
goto IllPos;
562 if ( FG.cTable[in[1]] == 0 || in[1] ==
'[' || in[1] ==
'{' )
object = 0;
566IllPos: MesPrint(
"&Illegal character at this position: %s",in);
567 if ( error >= 0 ) error = -1;
574 AC.endoftokens = out;
575 if ( funlevel > 0 || bracelevel != 0 ) {
576 if ( funlevel > 0 ) MesPrint(
"&Unmatched parentheses");
577 if ( bracelevel != 0 ) MesPrint(
"&Unmatched braces");
580 if ( AC.TokensWriteFlag ) WriteTokens(AC.tokens);
584 if ( error == 0 && simp1token(AC.tokens) ) error = 1;
588 if ( error == 0 && leftright == LHSIDE && simpwtoken(AC.tokens) )
593 if ( error == 0 && leftright == RHSIDE && simp4token(AC.tokens) )
598 if ( error == 0 && simp2token(AC.tokens) ) error = 1;
607 if ( error == 0 && ( numexp = simp3atoken(AC.tokens,leftright) ) < 0 )
613 while ( *out != TENDOFIT ) out++;
614 while ( out+numexp*9 > outtop ) {
615 LONG oldsize = (LONG)(out - AC.tokens);
616 SBYTE **ppp = &(AC.tokens);
617 SBYTE **pppp = &(AC.toptokens);
618 DoubleBuffer((
void **)ppp,(
void **)pppp,
sizeof(SBYTE),
"out tokens");
619 out = AC.tokens + oldsize;
620 outtop = AC.toptokens - MAXNUMSIZE;
623 while ( out >= AC.tokens ) { *tt-- = *out--; }
624 while ( tt >= AC.tokens ) { *tt-- = TEMPTY; }
625 if ( error == 0 && simp3btoken(AC.tokens,leftright) ) error = 1;
626 if ( error == 0 && simp2token(AC.tokens) ) error = 1;
632 if ( error == 0 && simp5token(AC.tokens,leftright) ) error = 1;
637 if ( error == 0 && simp6token(AC.tokens,leftright) ) error = 1;
647char *ttypes[] = {
"\n",
"S",
"I",
"V",
"F",
"set",
"E",
"dotp",
"#",
648 "sub",
"d_",
"$",
"dub",
"(",
")",
"?",
"??",
".",
"[",
"]",
649 ",",
"((",
"))",
"*",
"/",
"^",
"+",
"-",
"!",
"end",
"{{",
"}}",
650 "N_?",
"conj",
"()",
"#d",
"^d",
"_",
"snum" };
652void WriteTokens(SBYTE *in)
654 int numinline = 0, x, n =
sizeof(ttypes)/
sizeof(
char *);
655 char outbuf[81], *s, *out, c;
657 while ( *in != TENDOFIT ) {
661 while ( *s ) { *out++ = *s++; numinline++; }
664 *out++ =
'-'; x = -*in; numinline++;
673 *out++ = (char)(( x % 10 ) +
'0');
677 c = out[-1]; out[-1] = *s; *s = c;
679 if ( numinline > 70 ) {
681 MesPrint(
"%s",outbuf);
682 out = outbuf; numinline = 0;
685 *out++ =
' '; numinline++;
689 if ( numinline > 0 ) { *out = 0; MesPrint(
"%s",outbuf); }
700int simp1token(SBYTE *s)
702 int error = 0, n, i, base;
704 SBYTE *fill = s, *start, *t, numtab[10];
706 while ( *s != TENDOFIT ) {
707 if ( *s == RBRACE ) {
709 while ( *start != LBRACE ) start--;
711 while ( *t >= 0 ) t--;
712 if ( *t == TSET && ( start[1] == TNUMBER || start[1] == TNUMBER1 ) ) {
713 base = start[1] == TNUMBER ? 100: 128;
716 while ( *start >= 0 && start < fill )
717 { numsub = base*numsub + *start++; }
718 if ( start == fill ) {
720 t++; n = *t++;
while ( *t >= 0 ) { n = 128*n + *t++; }
722 if ( ( set->type != CRANGE )
723 && ( numsub > 0 && numsub <= set->last-set->first ) ) {
725 n = SetElements[set->first+numsub-1];
728 if ( n > MAXPOWER ) {
730 if ( n < 0 ) { n = -n; *fill++ = TMINUS; }
733 else *fill++ = TSYMBOL;
736 if ( n < AM.OffsetIndex ) *fill++ = TNUMBER1;
742 case CVECTOR: *fill++ = TVECTOR;
743 n -= AM.OffsetVector;
break;
744 case CFUNCTION: *fill++ = TFUNCTION;
745 n -= FUNCTION;
break;
746 case CNUMBER: *fill++ = TNUMBER1;
break;
747 case CDUBIOUS: *fill++ = TDUBIOUS; n = 1;
break;
751 MesPrint(
"Value of n = %d",n);
753 do { numtab[i++] = (SBYTE)(n & 0x7F); n >>= 7; }
while ( n );
754 while ( --i >= 0 ) *fill++ = numtab[i];
757 MesPrint(
"&Illegal element %d in set",numsub);
789int simpwtoken(SBYTE *s)
791 int error = 0, first = 1, notflag;
792 WORD num, numto, numdollar, *w = AC.WildC, *wstart, *wtop;
793 SBYTE *fill = s, *t, *v, *s0 = s;
794 while ( *s != TENDOFIT ) {
795 if ( *s == TWILDCARD ) {
796 notflag = 0; t = fill;
797 while ( t > s0 && t[-1] >= 0 ) t--;
798 v = t; num = 0; *fill++ = *s++;
799 while ( *v >= 0 ) num = 128*num + *v++;
802 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
806 *w++ = SYMTOSYM; *w++ = 4; *w++ = num; *w++ = num;
break;
808 num += AM.OffsetIndex;
809 *w++ = INDTOIND; *w++ = 4; *w++ = num; *w++ = num;
break;
811 num += AM.OffsetVector;
812 *w++ = VECTOVEC; *w++ = 4; *w++ = num; *w++ = num;
break;
815 *w++ = FUNTOFUN; *w++ = 4; *w++ = num; *w++ = num;
break;
817 MesPrint(
"&Illegal type of wildcard in LHS");
819 *w++ = SYMTOSYM; *w++ = 4; *w++ = num; *w++ = num;
break;
826 if ( *s == TNOT && s[1] == TSET ) { notflag = 1; s++; }
828 s++; num = 0;
while ( *s >= 0 ) num = 128*num + *s++;
829 if ( notflag == 0 && *s == TWILDCARD && s[1] == TSET ) {
830 s += 2; numto = 0;
while ( *s >= 0 ) numto = 128*numto + *s++;
831 if ( num < AM.NumFixedSets || numto < AM.NumFixedSets
832 || Sets[num].type == CRANGE || Sets[numto].type == CRANGE ) {
833 MesPrint(
"&This type of set not allowed in this wildcard construction");
838 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
839 *w++ = FROMSET; *w++ = 4; *w++ = num; *w++ = numto;
843 else if ( notflag == 0 && *s == LBRACE && s[1] == TSYMBOL ) {
844 if ( num < AM.NumFixedSets || Sets[num].type == CRANGE ) {
845 MesPrint(
"&This type of set not allowed in this wildcard construction");
849 numto = 0;
while ( *s >= 0 ) numto = 128*numto + *s++;
850 if ( *s == TWILDCARD ) s++;
851 if ( *s == RBRACE ) {
854 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
855 *w++ = SETTONUM; *w++ = 4; *w++ = num; *w++ = numto;
857 *w++ = SYMTOSYM; *w++ = 4; *w++ = numto; *w++ = 0;
859 else if ( *s == TDOLLAR ) {
861 while ( *s >= 0 ) numdollar = 128*numdollar + *s++;
862 if ( *s == RBRACE ) {
865 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
866 *w++ = SETTONUM; *w++ = 4; *w++ = num; *w++ = numto;
868 *w++ = SYMTOSYM; *w++ = 4; *w++ = numto; *w++ = 0;
869 *w++ = LOADDOLLAR; *w++ = 4; *w++ = numdollar;
872 else { s = v;
goto singlewild; }
874 else { s = v;
goto singlewild; }
877singlewild: num += notflag * 2*WILDOFFSET;
879 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
880 *w++ = FROMSET; *w++ = 4; *w++ = num; *w++ = -WILDOFFSET;
884 else if ( *s != TDOLLAR && *s != TENDOFIT && *s != RPARENTHESIS
885 && *s != RBRACE && *s != TCOMMA && *s != TFUNCLOSE && *s != TMULTIPLY
886 && *s != TPOWER && *s != TDIVIDE && *s != TPLUS && *s != TMINUS
887 && *s != TPOWER1 && *s != TEMPTY && *s != TFUNOPEN && *s != TDOT ) {
888 MesPrint(
"&Illegal type of wildcard in LHS");
891 if ( *s == TDOLLAR ) {
893 while ( *s >= 0 ) numdollar = 128*numdollar + *s++;
895 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
898 while ( w > wstart ) { w[4] = w[0]; w--; }
900 *w++ = LOADDOLLAR; *w++ = 4; *w++ = numdollar; *w++ = numdollar;
904 else if ( *s == TWILDARG ) {
907 while ( *s >= 0 ) { num = 128*num + *s; *fill++ = *s++; }
909 if ( AC.NwildC > 4*AM.MaxWildcards ) {
910firsterr:
if ( first ) {
911 MesPrint(
"&More than %d wildcards",AM.MaxWildcards);
916 else { *w++ = ARGTOARG; *w++ = 4; *w++ = num; *w++ = -1; }
917 if ( *s == TDOLLAR ) {
918 s++; num = 0;
while ( *s >= 0 ) num = 128*num + *s++;
920 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
921 *w++ = LOADDOLLAR; *w++ = 4; *w++ = num; *w++ = num;
943int simp2token(SBYTE *s)
945 SBYTE *to, *fill, *t, *v, *w, *s0 = s, *vv;
951 while ( *s != TENDOFIT ) {
952 if ( *s == LPARENTHESIS && s[1] == LPARENTHESIS ) {
956 if ( *t == LPARENTHESIS ) n++;
957 else if ( *t == RPARENTHESIS ) n--;
959 if ( t[1] == RPARENTHESIS ) {
964 else if ( *s == TEMPTY ) s++;
965 else if ( *s == AM.facnum && ( fill > (s0+1) ) && fill[-2] == TDIVIDE
966 && fill[-1] == TFUNCTION ) {
967 fill[-2] = TMULTIPLY; *fill++ = (SBYTE)(AM.invfacnum); s++;
969 else if ( *s == AM.invfacnum && ( fill > (s0+1) ) && fill[-2] == TDIVIDE
970 && fill[-1] == TFUNCTION ) {
971 fill[-2] = TMULTIPLY; *fill++ = (SBYTE)(AM.facnum); s++;
982 while ( *s != TENDOFIT ) {
983 if ( *s == LPARENTHESIS ) {
987 if ( *t == LPARENTHESIS ) n++;
988 else if ( *t == RPARENTHESIS ) n--;
990 if ( t[1] == TFUNCLOSE && s[1] != TWILDARG ) {
992 while ( n >= 0 && v >= to ) {
993 if ( *v == TFUNOPEN ) n--;
994 else if ( *v == TFUNCLOSE ) n++;
998 while ( *v >= 0 ) v--;
999 if ( *v == TFUNCTION ) { v++;
1000 n = 0;
while ( *v >= 0 && v < fill ) n = 128*n + *v++;
1001 if ( n == AM.sumnum || n == AM.sumpnum ) {
1002 *fill++ = *s++;
continue;
1004 else if ( ( n == (FIRSTBRACKET-FUNCTION)
1005 || n == (TERMSINEXPR-FUNCTION)
1006 || n == (SIZEOFFUNCTION-FUNCTION)
1007 || n == (NUMFACTORS-FUNCTION)
1008 || n == (GCDFUNCTION-FUNCTION)
1009 || n == (DIVFUNCTION-FUNCTION)
1010 || n == (REMFUNCTION-FUNCTION)
1011 || n == (INVERSEFUNCTION-FUNCTION)
1012 || n == (MULFUNCTION-FUNCTION)
1013 || n == (FACTORIN-FUNCTION)
1014 || n == (FIRSTTERM-FUNCTION)
1015 || n == (CONTENTTERM-FUNCTION) )
1016 && fill[-1] == TFUNOPEN ) {
1018 if ( *v == TEXPRESSION ) {
1020 n = 0;
while ( *v >= 0 ) n = 128*n + *v++;
1030 && ( ( fill[-1] == TFUNOPEN || fill[-1] == TCOMMA )
1031 && ( t[1] == TFUNCLOSE || t[1] == TCOMMA ) ) ) {
1036 if ( *v == TVECTOR ) {
1037 w = v+1;
while ( *w >= 0 ) w++;
1043 if ( *v == TNUMBER || *v == TNUMBER1 ) {
1044 if ( BITSINWORD == 16 ) { ULONG x; WORD base;
1045 base = ( *v == TNUMBER ) ? 100: 128;
1046 vv = v+1; x = 0;
while ( *vv >= 0 ) { x = x*base + *vv++; }
1047 if ( ( vv != t ) || ( ( vv - v ) > 4 ) || ( x > (MAXPOSITIVE+1) ) )
1049 else { *t = TEMPTY; s++;
break; }
1051 else if ( BITSINWORD == 32 ) { ULONG x; WORD base;
1052 base = ( *v == TNUMBER ) ? 100: 128;
1053 vv = v+1; x = 0;
while ( *vv >= 0 ) { x = x*base + *vv++; }
1054 if ( ( vv != t ) || ( ( vv - v ) > 6 ) || ( x > (MAXPOSITIVE+1) ) )
1056 else { *t = TEMPTY; s++;
break; }
1059 if ( ( v+2 == t ) || ( v+3 == t && v[2] >= 0 ) )
1060 { *t = TEMPTY; s++;
break; }
1061 else *fill++ = *s++;
1064 else if ( *v == LPARENTHESIS && t[-1] == RPARENTHESIS ) {
1068 if ( *w == LPARENTHESIS ) n++;
1069 else if ( *w == RPARENTHESIS ) n--;
1071 if ( w == ( t-1 ) ) { *t = TEMPTY; s++; }
1072 else *fill++ = *s++;
1074 else *fill++ = *s++;
1079 v++;
while ( *v >= 0 ) v++;
1082 if ( ( v[1] == COEFFSYMBOL || v[1] == NUMERATORSYMBOL
1083 || v[1] == DENOMINATORSYMBOL ) && v[2] < 0 ) {
1084 *fill++ = *s++;
break;
1094tcommon: v++;
while ( *v >= 0 ) v++;
1095 if ( v == t || ( v[0] == TWILDCARD && v+1 == t ) )
1096 { *t = TEMPTY; s++; }
1097 else *fill++ = *s++;
1101 if ( v == t ) { *t = TEMPTY; s++; }
1102 else *fill++ = *s++;
1106 if ( BITSINWORD == 16 ) { ULONG x; WORD base;
1107 base = ( *v == TNUMBER ) ? 100: 128;
1108 vv = v+1; x = 0;
while ( *vv >= 0 ) { x = x*base + *vv++; }
1109 if ( ( vv != t ) || ( ( vv - v ) > 4 ) || ( x > MAXPOSITIVE ) )
1111 else { *t = TEMPTY; s++;
break; }
1113 else if ( BITSINWORD == 32 ) { ULONG x; WORD base;
1114 base = ( *v == TNUMBER ) ? 100: 128;
1115 vv = v+1; x = 0;
while ( *vv >= 0 ) { x = x*base + *vv++; }
1116 if ( ( vv != t ) || ( ( vv - v ) > 6 ) || ( x > MAXPOSITIVE ) )
1118 else { *t = TEMPTY; s++;
break; }
1121 if ( ( v+2 == t ) || ( v+3 == t && v[2] >= 0 ) )
1122 { *t = TEMPTY; s++;
break; }
1123 else *fill++ = *s++;
1127 v++;
while ( *v >= 0 ) v++;
1128 if ( v == t ) { *t = TEMPTY; s++; }
1129 else *fill++ = *s++;
1138 if ( *vv != TEXPRESSION )
break;
1139 vv++;
while ( *vv >= 0 ) vv++;
1141 if ( vv < t ) { *fill++ = *s++;
break; }
1146 while ( n >= 0 && w >= to ) {
1147 if ( *w == TFUNOPEN ) n--;
1148 else if ( *w == TFUNCLOSE ) n++;
1151 w--;
while ( w > to && *w >= 0 ) w--;
1152 if ( *w != TFUNCTION ) { *fill++ = *s++;
break; }
1154 while ( *w >= 0 ) { n = 128*n + *w++; }
1155 if ( n == GCDFUNCTION-FUNCTION
1156 || n == DIVFUNCTION-FUNCTION
1157 || n == REMFUNCTION-FUNCTION
1158 || n == INVERSEFUNCTION-FUNCTION
1159 || n == MULFUNCTION-FUNCTION ) {
1162 else *fill++ = *s++;
1164 default: *fill++ = *s++;
break;
1167 else *fill++ = *s++;
1169 else if ( *s == TEMPTY ) s++;
1170 else *fill++ = *s++;
1191int simp3atoken(SBYTE *s,
int mode)
1193 int error = 0, n, numexp = 0, denom, base, numprot, i;
1197 if ( mode == RHSIDE ) {
1198 prot = AC.ProtoType;
1199 numprot = prot[1] - SUBEXPSIZE;
1202 else { prot = 0; numprot = 0; }
1203 while ( *s != TENDOFIT ) {
1205 if ( *s == TDIVIDE ) { denom = -1; s++; }
1211 s++;
while ( *s >= 0 ) s++;
1212 if ( *s == TWILDCARD ) s++;
1214 if ( *s != TPOWER )
continue;
1216 if ( *s == TMINUS ) s++;
1217 if ( *s == TNUMBER || *s == TNUMBER1 ) {
1218 base = *s == TNUMBER ? 100: 128;
1222 if ( num > MAXPOWER )
break;
1223 num = base*num + *s++;
1225 while ( *s >= 0 ) s++;
1226 if ( *s == TPOWER )
goto doublepower;
1227 if ( num <= MAXPOWER )
continue;
1229 else if ( *s == TSYMBOL && c != TNUMBER && c != TNUMBER1 ) {
1230 s++; n = 0;
while ( *s >= 0 ) { n = 128*n + *s++; }
1231 if ( *s == TWILDCARD ) { s++;
1232 if ( *s == TPOWER )
goto doublepower;
1237 if ( mode == RHSIDE ) {
1239 for ( i = 0; i < numprot; i += 4 ) {
1240 if ( prot[i+2] == n && prot[i] == SYMTOSYM )
break;
1242 if ( i < numprot )
break;
1244 if ( *s == TPOWER )
goto doublepower;
1249 s++;
while ( *s >= 0 ) s++;
1250 if ( *s == TWILDCARD ) s++;
1252 if ( denom < 0 || *s == TPOWER ) {
1253 MesPrint(
"&Index to a power or in denominator is illegal");
1258 s++;
while ( *s >= 0 ) s++;
1259 if ( *s == TWILDCARD ) s++;
1261 if ( *s == TFUNOPEN ) {
1264 if ( *s == TFUNOPEN ) {
1266 MesPrint(
"&Illegal vector index");
1269 else if ( *s == TFUNCLOSE ) {
1271 if ( n <= 0 )
break;
1277 else if ( *s == TDOT )
goto dodot;
1278 if ( denom < 0 || *s == TPOWER || *s == TPOWER1 ) numexp++;
1281 s++;
while ( *s >= 0 ) s++;
1282 if ( *s == TWILDCARD ) s++;
1285 if ( *t == TFUNOPEN ) {
1288 if ( *t == TFUNOPEN ) n++;
1289 else if ( *t == TFUNCLOSE ) {
if ( --n <= 0 )
break; }
1294 if ( denom < 0 || *t == TPOWER || *t == TPOWER1 ) numexp++;
1298 s++;
while ( *s >= 0 ) s++;
1299 if ( denom < 0 || *s == TPOWER || *s == TPOWER1 ) numexp++;
1303 s++;
while ( *s >= 0 ) s++;
1305 if ( *t == TFUNOPEN ) {
1308 if ( *t == TFUNOPEN ) n++;
1309 else if ( *t == TFUNCLOSE ) {
if ( --n <= 0 )
break; }
1314 if ( *t == LBRACE ) {
1317 if ( *t == LBRACE ) n++;
1318 else if ( *t == RBRACE ) {
if ( --n <= 0 )
break; }
1323 if ( denom < 0 || ( ( *t == TPOWER || *t == TPOWER1 )
1324 && t[1] == TMINUS ) ) numexp++;
1327 s++;
while ( *s >= 0 ) s++;
1328 if ( denom < 0 || ( ( *s == TPOWER || *s == TPOWER1 )
1329 && s[1] == TMINUS ) ) numexp++;
1334 if ( *t == LPARENTHESIS ) n++;
1335 else if ( *t == RPARENTHESIS ) {
if ( --n <= 0 )
break; }
1339 if ( denom > 0 && ( *t == TPOWER || *t == TPOWER1 ) ) {
1340 if ( ( t[1] == TNUMBER || t[1] == TNUMBER1 ) && t[2] >= 0
1341 && t[3] < 0 )
break;
1344 else if ( denom < 0 && ( *t == TPOWER || *t == TPOWER1 ) ) {
1345 if ( t[1] == TMINUS && ( t[2] == TNUMBER
1346 || t[2] == TNUMBER1 ) && t[3] >= 0
1347 && t[4] < 0 )
break;
1350 else if ( denom < 0 || ( ( *t == TPOWER || *t == TPOWER1 )
1351 && ( t[1] == TMINUS || t[1] == LPARENTHESIS ) ) ) numexp++;
1354 s++; n = *s++;
while ( *s >= 0 ) { n = 128*n + *s++; }
1357 case CSYMBOL:
goto dosymbol;
1358 case CINDEX:
goto doindex;
1359 case CVECTOR:
goto dovector;
1360 case CFUNCTION:
goto dofunction;
1361 case CNUMBER:
goto dosymbol;
1363 if ( denom < 0 || *s == TPOWER ) {
1364 MesPrint(
"&A model to a power or in denominator is illegal");
1369 if ( denom < 0 || *s == TPOWER ) {
1370 MesPrint(
"&A set without type to a power or in denominator is illegal");
1374 default: error = 1;
break;
1379 if ( *s == TVECTOR ) { s++;
while ( *s >= 0 ) s++; }
1380 else if ( *s == TSET ) {
1381 s++; n = *s++;
while ( *s >= 0 ) { n = 128*n + *s++; }
1382 if ( Sets[n].type != CVECTOR ) {
1383 MesPrint(
"&Set in dotproduct is not a set of vectors");
1386 if ( *s == LBRACE ) {
1389 if ( *s == LBRACE ) n++;
1390 else if ( *s == RBRACE ) {
if ( --n <= 0 )
break; }
1396 MesPrint(
"&Set without argument in dotproduct");
1400 else if ( *s == TSETNUM ) {
1401 s++; n = *s++;
while ( *s >= 0 ) { n = 128*n + *s++; }
1402 if ( *s != TVECTOR )
goto nodot;
1403 s++; n = *s++;
while ( *s >= 0 ) { n = 128*n + *s++; }
1404 if ( Sets[n].type != CVECTOR ) {
1405 MesPrint(
"&Set in dotproduct is not a set of vectors");
1410nodot: MesPrint(
"&Illegal second element in dotproduct");
1412 s++;
while ( *s >= 0 ) s++;
1416 s++;
while ( *s >= 0 ) s++;
1420 if ( error )
return(-1);
1423 MesPrint(
"&Dubious notation with object^power1^power2");
1432int simp3btoken(SBYTE *s,
int mode)
1434 int error = 0, i, numprot, n, denom, base, inset = 0, dotp, sube = 0;
1435 SBYTE *t, c, *fill, *ff, *ss;
1440 SBYTE *tmptokens = (SBYTE*)Malloc1((AC.toptokens-AC.tokens)*
sizeof(SBYTE),
"simp3btoken scratch");
1441 SBYTE* tmptoptokens = tmptokens + (AC.toptokens-AC.tokens);
1444 if ( mode == RHSIDE ) {
1445 prot = AC.ProtoType;
1446 numprot = prot[1] - SUBEXPSIZE;
1449 else { prot = 0; numprot = 0; }
1450 while ( *s == TEMPTY ) s++;
1451 while ( *s != TENDOFIT ) {
1456 while ( tmptoptokens - fill < 20 ) {
1458 tmppos = s - AC.tokens;
1459 DoubleBuffer((
void**)&(AC.tokens), (
void**)&(AC.toptokens),
sizeof(SBYTE),
"simp3btoken double");
1460 s = AC.tokens + tmppos;
1461 tmppos = fill - tmptokens;
1462 DoubleBuffer((
void**)&tmptokens, (
void**)&tmptoptokens,
sizeof(SBYTE),
"simp3btoken scratch double");
1463 fill = tmptokens + tmppos;
1465 if ( *s == TEMPTY ) { s++;
continue; }
1467 if ( *s == TDIVIDE ) { denom = -1; *fill++ = *s++; }
1468 ff = fill; ss = s; c = *s;
1469 if ( c == TSETNUM ) {
1470 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1479 while ( *s >= 0 ) *fill++ = *s++;
1480 if ( *s == TWILDCARD ) *fill++ = *s++;
1483 if ( *s != TPOWER )
continue;
1485 if ( *s == TMINUS ) *fill++ = *s++;
1486 if ( *s == TPLUS ) s++;
1487 if ( *s == TSETNUM ) {
1488 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1492 if ( *s == TNUMBER || *s == TNUMBER1 ) {
1493 base = *s == TNUMBER ? 100: 128;
1495 num = *s++; *fill++ = num;
1497 if ( num > MAXPOWER )
break;
1499 num = base*num + *s++;
1501 while ( *s >= 0 ) *fill++ = *s++;
1502 if ( num <= MAXPOWER )
continue;
1505 else if ( *s == TSYMBOL && c != TNUMBER && c != TNUMBER1 ) {
1507 n = 0;
while ( *s >= 0 ) { n = 128*n + *s; *fill++ = *s++; }
1508 if ( *s == TWILDCARD ) { *fill++ = *s++;
1509 if ( *s == TPOWER )
goto doublepower;
1514 if ( mode == RHSIDE && inset == 0 ) {
1516 for ( i = 0; i < numprot; i += 4 ) {
1517 if ( prot[i+2] == n && prot[i] == SYMTOSYM )
break;
1519 if ( i < numprot )
break;
1523 if ( denom < 0 ) fill[-1] = TMULTIPLY;
1524 *fill++ = TFUNCTION; *fill++ = (SBYTE)(AM.expnum); *fill++ = TFUNOPEN;
1525 if ( dotp ) *fill++ = LPARENTHESIS;
1526 while ( ss < t ) *fill++ = *ss++;
1527 if ( dotp ) *fill++ = RPARENTHESIS;
1530 if ( *ss == TMINUS ) { denom = -denom; ss++; }
1532 *fill++ = LPARENTHESIS;
1534 while ( ss < s ) *fill++ = *ss++;
1535 *fill++ = RPARENTHESIS;
1538 while ( ss < s ) *fill++ = *ss++;
1540 *fill++ = TFUNCLOSE;
1541 if ( *ss == TPOWER )
goto doublepower;
1548 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1549 if ( *s == TWILDCARD ) *fill++ = *s++;
1552 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1553 if ( *s == TWILDCARD ) *fill++ = *s++;
1555 if ( *s == TFUNOPEN ) {
1556 while ( *s != TFUNCLOSE ) *fill++ = *s++;
1559 else if ( *s == TDOT )
goto dodot;
1564 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1570 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1571 if ( *s == TWILDCARD ) *fill++ = *s++;
1574 if ( *t == TFUNOPEN ) {
1577 if ( *t == TFUNOPEN ) n++;
1578 else if ( *t == TFUNCLOSE ) {
if ( --n <= 0 )
break; }
1581 t++; *fill++ = *s++;
1585 if ( *t == TPOWER || *t == TPOWER1 ) {
1587 if ( ( t[1] == TNUMBER || t[1] == TNUMBER1 )
1589 if ( t[2] >= 0 && t[3] < 0 ) { sube = 0;
break; }
1591 else if ( t[1] == TMINUS && denom < 0 &&
1592 ( t[2] == TNUMBER || t[2] == TNUMBER1 ) ) {
1593 if ( t[2] >= 0 && t[3] < 0 ) { sube = 0;
break; }
1598 *fill++ = TFUNCTION; *fill++ = (SBYTE)(AM.expnum); *fill++ = TFUNOPEN;
1599 *fill++ = LPARENTHESIS;
1600 while ( ss < t ) *fill++ = *ss++;
1602 *fill++ = RPARENTHESIS; *fill++ = TCOMMA;
1603 if ( *t == TMINUS ) { t++; denom = -denom; }
1604 *fill++ = LPARENTHESIS;
1605 if ( denom < 0 ) *fill++ = TMINUS;
1606 if ( *t == LPARENTHESIS ) {
1607 *fill++ = *t++; n = 0;
1609 if ( *t == LPARENTHESIS ) n++;
1610 else if ( *t == RPARENTHESIS ) n--;
1614 else if ( *t == TFUNCTION || *t == TDUBIOUS ) {
1615 *fill++ = *t++;
while ( *t >= 0 ) *fill++ = *t++;
1616 if ( *t == TWILDCARD ) *fill++ = *t++;
1617 if ( *t == TFUNOPEN ) {
1618 *fill++ = *t++; n = 0;
1620 if ( *t == TFUNOPEN ) n++;
1621 else if ( *t == TFUNCLOSE ) n--;
1626 else if ( *t == TSET ) {
1627 *fill++ = *t++; n = 0;
1628 while ( *t >= 0 ) { n = 128*n + *t; *fill++ = *t++; }
1629 if ( *t == LBRACE ) {
1630 if ( n < AM.NumFixedSets || Sets[n].type == CRANGE ) {
1631 MesPrint(
"&This type of usage of sets is not allowed");
1634 *fill++ = *t++; n = 0;
1636 if ( *t == LBRACE ) n++;
1637 else if ( *t == RBRACE ) n--;
1642 else if ( *t == TEXPRESSION ) {
1643 *fill++ = *t++;
while ( *t >= 0 ) *fill++ = *t++;
1644 if ( *t == TFUNOPEN ) {
1645 *fill++ = *t++; n = 0;
1647 if ( *t == TFUNOPEN ) n++;
1648 else if ( *t == TFUNCLOSE ) n--;
1652 if ( *t == LBRACE ) {
1653 *fill++ = *t++; n = 0;
1655 if ( *t == LBRACE ) n++;
1656 else if ( *t == RBRACE ) n--;
1661 else if ( *t == TVECTOR ) {
1662 *fill++ = *t++;
while ( *t >= 0 ) *fill++ = *t++;
1663 if ( *t == TFUNOPEN ) {
1664 *fill++ = *t++; n = 0;
1666 if ( *t == TFUNOPEN ) n++;
1667 else if ( *t == TFUNCLOSE ) n--;
1671 else if ( *t == TDOT ) {
1673 if ( *t == TVECTOR || *t == TDUBIOUS ) {
1674 *fill++ = *t++;
while ( *t >= 0 ) *fill++ = *t++;
1676 else if ( *t == TSET ) {
1677 *fill++ = *t++; num = 0;
1678 while ( *t >= 0 ) { num = 128*num + *t; *fill++ = *t++; }
1679 if ( Sets[num].type != CVECTOR ) {
1680 MesPrint(
"&Illegal set type in dotproduct");
1683 if ( *t == LBRACE ) {
1684 *fill++ = *t++; n = 0;
1686 if ( *t == LBRACE ) n++;
1687 else if ( *t == RBRACE ) n--;
1692 else if ( *t == TSETNUM ) {
1694 while ( *t >= 0 ) { *fill++ = *t++; }
1696 while ( *t >= 0 ) { *fill++ = *t++; }
1700 MesPrint(
"&Illegal second element in dotproduct");
1705 *fill++ = *t++;
while ( *t >= 0 ) *fill++ = *t++;
1706 if ( *t == TWILDCARD ) *fill++ = *t++;
1708 *fill++ = RPARENTHESIS; *fill++ = TFUNCLOSE;
1709 if ( *t == TPOWER )
goto doublepower;
1710 while ( fill > ff ) *--t = *--fill;
1713 else if ( denom < 0 ) {
1714 fill = ff; ff[-1] = TMULTIPLY;
1715 *fill++ = TFUNCTION; *fill++ = (SBYTE)(AM.denomnum);
1716 *fill++ = TFUNOPEN; *fill++ = LPARENTHESIS;
1717 while ( ss < t ) *fill++ = *ss++;
1718 *fill++ = RPARENTHESIS; *fill++ = TFUNCLOSE;
1719 while ( fill > ff ) *--t = *--fill;
1720 s = t; denom = 1; sube = 0;
1726 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1728 if ( *t == TFUNOPEN ) {
1731 if ( *t == TFUNOPEN ) n++;
1732 else if ( *t == TFUNCLOSE ) {
if ( --n <= 0 )
break; }
1737 if ( *t == LBRACE ) {
1740 if ( *t == LBRACE ) n++;
1741 else if ( *t == RBRACE ) {
if ( --n <= 0 )
break; }
1746 if ( t > s || denom < 0 || ( ( *t == TPOWER || *t == TPOWER1 )
1747 && t[1] == TMINUS ) )
goto dofunpower;
1750 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1753 *fill++ = *s++; n = 1; t = s;
1755 if ( *t == LPARENTHESIS ) n++;
1756 else if ( *t == RPARENTHESIS ) {
if ( --n <= 0 )
break; }
1762 *fill++ = *s++; n = *s++; *fill++ = (SBYTE)n;
1763 while ( *s >= 0 ) { *fill++ = *s; n = 128*n + *s++; }
1766 case CSYMBOL:
goto dosymbol;
1768 case CVECTOR:
goto dovector;
1769 case CFUNCTION:
goto dofunction;
1770 case CNUMBER:
goto dosymbol;
1772 case ANYTYPE:
break;
1773 default: error = 1;
break;
1777dodot: *fill++ = *s++;
1778 if ( *s == TVECTOR ) {
1779 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1781 else if ( *s == TSET ) {
1782 *fill++ = *s++; n = *s++; *fill++ = (SBYTE)n;
1783 while ( *s >= 0 ) { *fill++ = *s; n = 128*n + *s++; }
1784 if ( *s == LBRACE ) {
1785 if ( n < AM.NumFixedSets || Sets[n].type == CRANGE ) {
1786 MesPrint(
"&This type of usage of sets is not allowed");
1789 *fill++ = *s++; n = 1;
1791 if ( *s == LBRACE ) n++;
1792 else if ( *s == RBRACE ) {
if ( --n <= 0 )
break; }
1798 MesPrint(
"&Set without argument in dotproduct");
1802 else if ( *s == TSETNUM ) {
1803 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1804 if ( *s != TVECTOR )
goto nodot;
1805 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1808nodot: MesPrint(
"&Illegal second element in dotproduct");
1811 while ( *s >= 0 ) *fill++ = *s++;
1817 while ( *s >= 0 ) *fill++ = *s++;
1827 }
while ( *fill++ != TENDOFIT );
1828 M_free(tmptokens,
"simp3btoken scratch");
1831 MesPrint(
"&Dubious notation with power of power");
1832 M_free(tmptokens,
"simp3btoken scratch");
1843int simp4token(SBYTE *s)
1845 int error = 0, n, nsym, settype;
1846 WORD i, *w, *wstop, level;
1847 SBYTE *
const s0 = s;
1848 SBYTE *fill = s, *s1, *s2, *s3, type, s1buf[10];
1849 SBYTE *tbuf = s, *t, *t1;
1851 while ( *s != TENDOFIT ) {
1853 if ( *s == TEMPTY ) s++;
1854 else *fill++ = *s++;
1857 if ( fill >= (s0+1) && fill[-1] == TWILDCARD ) { *fill++ = *s++;
continue; }
1858 if ( fill >= (s0+2) && fill[-1] == TNOT && fill[-2] == TWILDCARD ) { *fill++ = *s++;
continue; }
1859 s1 = s++; n = 0;
while ( *s >= 0 ) { n = 128*n + *s++; }
1861 if ( *s != LBRACE ) {
while ( s1 < s ) *fill++ = *s1++;
continue; }
1862 if ( n < AM.NumFixedSets || i == CRANGE ) {
1863 MesPrint(
"&It is not allowed to refer to individual elements of built in or ranged sets");
1867 if ( *s != TSYMBOL && *s != TDOLLAR ) {
1868 MesPrint(
"&Set index in RHS is not a wildcard symbol or $-variable");
1870 while ( s1 < s ) *fill++ = *s1++;
1873 settype = ( *s == TDOLLAR );
1874 s++; nsym = 0; s2 = s;
1875 while ( *s >= 0 ) nsym = 128*nsym + *s++;
1876 if ( *s != RBRACE ) {
1877 MesPrint(
"&Improper set argument in RHS");
1879 while ( s1 < s ) *fill++ = *s1++;
1887 w = AC.ProtoType; wstop = w + w[1]; w += SUBEXPSIZE;
1888 while ( w < wstop ) {
1889 if ( *w == SYMTOSYM && w[2] == nsym )
break;
1897 while ( t >= tbuf ) {
1898 if ( *t == TFUNCLOSE ) {
1900 while ( t >= tbuf ) {
1901 if ( *t == TFUNCLOSE ) level++;
1902 else if ( *t == TFUNOPEN ) {
1904 if ( level == 0 )
break;
1909 else if ( *t == RBRACE ) {
1911 while ( t >= tbuf ) {
1912 if ( *t == RBRACE ) level++;
1913 else if ( *t == LBRACE ) {
1915 if ( level == 0 )
break;
1920 else if ( *t == RPARENTHESIS ) {
1922 while ( t >= tbuf ) {
1923 if ( *t == RPARENTHESIS ) level++;
1924 else if ( *t == LPARENTHESIS ) {
1926 if ( level == 0 )
break;
1931 else if ( *t == TFUNOPEN ) {
1933 while ( *t1 > 0 && t1 > tbuf ) t1--;
1934 if ( *t1 == TFUNCTION ) {
1936 while ( *t1 > 0 ) level = level*128+*t1++;
1937 if ( level == (SUMF1-FUNCTION)
1938 || level == (SUMF2-FUNCTION) ) {
1940 if ( *t1 == LPARENTHESIS ) t1++;
1941 if ( *t1 == TSYMBOL ) {
1942 if ( ( t1[1] == COEFFSYMBOL
1943 || t1[1] == NUMERATORSYMBOL
1944 || t1[1] == DENOMINATORSYMBOL )
1948 while ( *t1 >= 0 && t1 < fill ) level = 128*level + *t1++;
1949 if ( level == nsym && t1 < fill ) {
1950 if ( t[1] == LPARENTHESIS
1951 && *t1 == RPARENTHESIS && t1[1] == TCOMMA )
break;
1952 if ( t[1] != LPARENTHESIS && *t1 == TCOMMA )
break;
1963 MesPrint(
"&Set index in RHS is not a wildcard symbol");
1965 while ( s1 < s ) *fill++ = *s1++;
1974 case CSYMBOL: type = TSYMBOL;
break;
1975 case CINDEX: type = TINDEX;
break;
1976 case CVECTOR: type = TVECTOR;
break;
1977 case CFUNCTION: type = TFUNCTION;
break;
1978 case CNUMBER: type = TNUMBER1;
break;
1979 case CDUBIOUS: type = TDUBIOUS;
break;
1981 MesPrint(
"&Unknown set type in simp4token");
1982 error = 1; type = CDUBIOUS;
break;
1985 while ( *s1 >= 0 ) *s3++ = *s1++;
1986 *s3 = -1; s1 = s1buf;
1987 if ( settype ) *fill++ = TSETDOL;
1988 else *fill++ = TSETNUM;
1989 while ( *s2 >= 0 ) *fill++ = *s2++;
1990 *fill++ = type;
while ( *s1 >= 0 ) *fill++ = *s1++;
2003int simp5token(SBYTE *s,
int mode)
2005 int error = 0, n, type;
2007 if ( mode == RHSIDE ) {
2008 while ( *s != TENDOFIT ) {
2009 if ( *s == TFUNCTION ) {
2010 s++; n = 0;
while ( *s >= 0 ) n = 128*n + *s++;
2011 if ( n == AM.sumnum || n == AM.sumpnum ) {
2012 if ( *s != TFUNOPEN )
continue;
2014 if ( *s != TSYMBOL && *s != TINDEX )
continue;
2016 n = 0;
while ( *s >= 0 ) n = 128*n + *s++;
2017 if ( type == TINDEX ) n += AM.OffsetIndex;
2018 if ( *s != TCOMMA )
continue;
2022 while ( w < wstop ) {
2024 if ( ( type == TSYMBOL && ( w[0] == SYMTOSYM
2025 || w[0] == SYMTONUM || w[0] == SYMTOSUB ) ) || (
2026 type == TINDEX && ( w[0] == INDTOIND
2027 || w[0] == INDTOSUB ) ) ) {
2029 MesPrint(
"&Parameter of sum function is already a wildcard");
2049int simp6token(SBYTE *tokens,
int mode)
2053 int level = 0, haveone = 0;
2054 SBYTE *s = tokens, *ss;
2058 if ( mode == RHSIDE ) {
2059 while ( *s == TPLUS || *s == TMINUS ) s++;
2061 while ( *s != TENDOFIT ) {
2062 if ( *s == LPARENTHESIS ) level++;
2063 else if ( *s == RPARENTHESIS ) level--;
2064 else if ( *s == TFUNOPEN ) level++;
2065 else if ( *s == TFUNCLOSE ) level--;
2066 else if ( ( *s == TPLUS || *s == TMINUS ) && level == 0 ) {
2070 if ( s[-1] != TPOWER && s[-1] != TPLUS && s[-1] != TMINUS ) {
2074 else if ( *s == TEXPRESSION ) {
2076 s++; n = 0;
while ( *s >= 0 ) n = 128*n + *s++;
2078 if ( Expressions[n].status == STOREDEXPRESSION ) {
2087 WORD TMproto[SUBEXPSIZE];
2088 TMproto[0] = EXPRESSION;
2089 TMproto[1] = SUBEXPSIZE;
2092 {
int ie;
for ( ie = 4; ie < SUBEXPSIZE; ie++ ) TMproto[ie] = 0; }
2093 AT.TMaddr = TMproto;
2102 if ( ( renumber = GetTable(n,&position,0) ) == 0 )
2105 MesPrint(
"&Problems getting information about stored expression %s(4)"
2111 if ( renumber->
symb.
lo != AN.dummyrenumlist )
2112 M_free(renumber->
symb.
lo,
"VarSpace");
2113 M_free(renumber,
"Renumber");
2119 if ( ( ( AS.Oldvflags[n] & ISFACTORIZED ) != 0 ) && *s != LBRACE ) {
2123 else if ( error == 0 ) {
2124 if ( ss[-1] != TFUNOPEN || funnum != NUMFACTORS-FUNCTION ) {
2125 MesPrint(
"&Illegal use of factorized expression(s) in RHS");
2132 else if ( *s == TFUNCTION ) {
2133 s++; funnum = 0;
while ( *s >= 0 ) funnum = 128*funnum + *s++;
2139 if ( numterms > 1 ) {
2140 MesPrint(
"&Factorized expression in RHS in an expression of more than one term.");
2143 else if ( AC.ToBeInFactors == 0 ) {
2144 MesPrint(
"&Attempt to put a factorized expression inside an unfactorized expression.");
UBYTE * SkipAName(UBYTE *s)