56 #define CHECKPOLY {if(polyflag)MesPrint("&Illegal use of polynomial function"); polyflag = 0; } 58 int 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
90 dovariable: 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;
152 if ( !AP.PreAssignFlag && !AP.PreInsideLevel )
153 Expressions[number].vflags |= ISINRHS;
156 if ( AC.exprfillwarning == 0 ) {
157 AC.exprfillwarning = 1;
160 case CDELTA: *out++ = TDELTA; *in = c;
161 object = 1;
continue;
162 case CDUBIOUS: *out++ = TDUBIOUS;
break;
163 default: *out++ = TDUBIOUS;
164 if ( !error ) error = 1;
165 MesPrint(
"&Undeclared variable %s",s);
166 number = AddDubious(s);
171 do { num[i++] = (SBYTE)(number & 0x7F); number >>= 7; }
while ( number );
172 while ( --i >= 0 ) *out++ = num[i];
178 while ( *s ==
'0' && FG.cTable[s[1]] == 1 ) s++;
180 while ( FG.cTable[*in] == 1 ) { in++; i++; }
183 MesPrint(
"&Illegal position for %s",s);
185 if ( !error ) error = 1;
187 if ( i == 1 && *in ==
'_' && ( *s ==
'5' || *s ==
'6' 189 in++; *out++ = TSGAMMA; *out++ = (SBYTE)(*s -
'4');
194 if ( ( i & 1 ) != 0 ) *out++ = (SBYTE)(*s++ -
'0');
195 while ( out + (in-s)/2 >= AC.toptokens ) {
196 LONG oldsize = (LONG)(out - AC.tokens);
197 SBYTE **ppp = &(AC.tokens);
198 SBYTE **pppp = &(AC.toptokens);
199 DoubleBuffer((
void **)ppp,(
void **)pppp,
sizeof(SBYTE),
"more tokens");
200 out = AC.tokens + oldsize;
201 outtop = AC.toptokens - MAXNUMSIZE;
204 *out++ = (SBYTE)(( *s -
'0' ) * 10 + ( s[1] -
'0' ));
212 if ( leftright == LHSIDE ) {
214 in++; *out++ = TWILDCARD;
215 if ( FG.cTable[in[0]] == 0 || in[0] ==
'[' || in[0] ==
'{' )
object = 0;
217 else if (
object == -1 ) {
219 while ( FG.cTable[*in] == 0 || FG.cTable[*in] == 1 ) in++;
221 if ( FG.cTable[*s] != 0 ) {
222 MesPrint(
"&Illegal name for argument list variable %s",s);
226 i = AddWildcardName((UBYTE *)s);
234 MesPrint(
"&Illegal position for ?");
240 if (
object != -1 )
goto IllPos;
242 if ( FG.cTable[*in] == 0 || FG.cTable[*in] == 1 ) {
244 while ( FG.cTable[*in] == 0 || FG.cTable[*in] == 1 ) in++;
246 i = GetWildcardName((UBYTE *)s);
248 MesPrint(
"&Undefined argument list variable %s",s);
256 if ( AC.vectorlikeLHS == 0 ) {
257 MesPrint(
"&Generated index ? only allowed in vector substitution",s);
265 else if ( *in ==
'.' ) {
273 else if ( *in ==
'$' ) {
276 if ( FG.cTable[*in] == 0 ) {
277 while ( FG.cTable[*in] == 0 || FG.cTable[*in] == 1 ) in++;
278 if ( *in ==
'_' && AP.PreAssignFlag == 2 ) in++;
281 if (
object != 1 || leftright == RHSIDE ) {
282 MesPrint(
"&Illegal position for $%s",s);
283 if ( !error ) error = 1;
286 if ( ( number = GetDollar(s) ) < 0 ) {
287 number = AddDollar(s,0,0,0);
291 else if ( ( number = GetDollar(s) ) < 0 ) {
292 MesPrint(
"&Undefined variable $%s",s);
293 if ( !error ) error = 1;
294 number = AddDollar(s,0,0,0);
298 if ( ( AC.exprfillwarning == 0 ) &&
299 ( ( out > AC.tokens+1 ) && ( out[-2] != TWILDCARD ) ) ) {
300 AC.exprfillwarning = 1;
305 MesPrint(
"Illegal name for $ variable after %s",in);
306 if ( !error ) error = 1;
309 else if ( *in ==
'#' ) {
321 if ( *t == RPARENTHESIS ) {
322 *out++ = LBRACE; *out++ = LPARENTHESIS;
323 bracelevel++; explevel = bracelevel;
326 while ( *t >= 0 && t > AC.tokens ) t--;
327 if ( *t == TEXPRESSION ) {
328 *out++ = LBRACE; *out++ = LPARENTHESIS;
329 bracelevel++; explevel = bracelevel;
331 else {*out++ = LBRACE; bracelevel++; }
342 if ( explevel > 0 && explevel == bracelevel ) {
343 *out++ = RPARENTHESIS; explevel = 0;
345 *out++ = RBRACE;
object = 1; bracelevel--;
351 if ( funlevel >= AM.MaxParLevel ) {
352 MesPrint(
"&More than %d levels of parentheses",AM.MaxParLevel);
356 AC.tokenarglevel[funlevel++] = TYPEISFUN;
359 if ( in[1] !=
')' && in[1] !=
',' ) {
360 *out++ = TNUMBER; *out++ = (SBYTE)(polyflag);
362 *out++ = LPARENTHESIS;
365 *out++ = LPARENTHESIS;
366 *out++ = TNUMBER; *out++ = (SBYTE)(polyflag);
370 else if ( in[1] !=
')' && in[1] !=
',' ) {
371 *out++ = LPARENTHESIS;
374 else if (
object <= 0 ) {
376 AC.tokenarglevel[funlevel++] = TYPEISSUB;
377 *out++ = LPARENTHESIS;
381 AC.tokenarglevel[funlevel++] = TYPEISMYSTERY;
382 MesPrint(
"&Illegal position for (: %s",in);
383 if ( error >= 0 ) error = -1;
387 else if ( *in ==
')' ) {
389 if ( funlevel < 0 ) {
391 MesPrint(
"&There is an unmatched parenthesis");
392 if ( error >= 0 ) error = -1;
395 else if (
object <= 0
396 && ( AC.tokenarglevel[funlevel] != TYPEISFUN
397 || out[-1] != TFUNOPEN ) ) {
398 MesPrint(
"&Illegal position for closing parenthesis.");
399 if ( error >= 0 ) error = -1;
400 if ( AC.tokenarglevel[funlevel] == TYPEISFUN )
object = 1;
404 if ( AC.tokenarglevel[funlevel] == TYPEISFUN ) {
405 if ( out[-1] == TFUNOPEN ) out--;
407 if ( out[-1] != TCOMMA ) *out++ = RPARENTHESIS;
412 else if ( AC.tokenarglevel[funlevel] == TYPEISSUB ) {
413 *out++ = RPARENTHESIS;
418 else if ( *in ==
',' ) {
420 AC.tokenarglevel[funlevel-1] == TYPEISFUN ) {
421 if ( out[-1] != TFUNOPEN && out[-1] != TCOMMA )
422 *out++ = RPARENTHESIS;
423 else { *out++ = TNUMBER; *out++ = 0; }
425 if ( in[1] !=
',' && in[1] !=
')' )
426 *out++ = LPARENTHESIS;
427 else if ( in[1] ==
')' ) {
428 *out++ = TNUMBER; *out++ = 0;
436 MesPrint(
"&Illegal position for comma: %s",in);
437 MesPrint(
"&Forgotten ; ?");
438 if ( error >= 0 ) error = -1;
447 if ( *in ==
':' || *in ==
'%' )
goto IllPos;
448 if ( *in ==
'*' || *in ==
'/' || *in ==
'^' ) {
450 MesPrint(
"&Illegal position for operator: %s",in);
451 if ( error >= 0 ) error = -1;
453 else if ( *in ==
'*' ) *out++ = TMULTIPLY;
454 else if ( *in ==
'/' ) *out++ = TDIVIDE;
455 else *out++ = TPOWER;
460 while ( *in ==
'+' || *in ==
'-' ) {
461 if ( *in ==
'-' ) i = -i;
465 if ( out > AC.tokens && out[-1] != TFUNOPEN &&
466 out[-1] != LPARENTHESIS && out[-1] != TCOMMA
467 && out[-1] != LBRACE )
470 else *out++ = TMINUS;
480 MesPrint(
"&Illegal position for %s",in);
481 if ( !error ) error = 1;
485 number = DoTempSet(s,in);
490 do { num[i++] = (SBYTE)(number & 0x7F); number >>= 7; }
while ( number );
491 while ( --i >= 0 ) *out++ = num[i];
493 else if ( error == 0 ) error = 1;
500 if ( *in !=
'!' || leftright == RHSIDE
501 ||
object != 1 || out[-1] != TWILDCARD )
goto IllPos;
503 if ( FG.cTable[in[1]] == 0 || in[1] ==
'[' || in[1] ==
'{' )
object = 0;
507 IllPos: MesPrint(
"&Illegal character at this position: %s",in);
508 if ( error >= 0 ) error = -1;
515 AC.endoftokens = out;
516 if ( funlevel > 0 || bracelevel != 0 ) {
517 if ( funlevel > 0 ) MesPrint(
"&Unmatched parentheses");
518 if ( bracelevel != 0 ) MesPrint(
"&Unmatched braces");
521 if ( AC.TokensWriteFlag ) WriteTokens(AC.tokens);
525 if ( error == 0 && simp1token(AC.tokens) ) error = 1;
529 if ( error == 0 && leftright == LHSIDE && simpwtoken(AC.tokens) )
534 if ( error == 0 && leftright == RHSIDE && simp4token(AC.tokens) )
539 if ( error == 0 && simp2token(AC.tokens) ) error = 1;
548 if ( error == 0 && ( numexp = simp3atoken(AC.tokens,leftright) ) < 0 )
553 while ( *out != TENDOFIT ) out++;
554 while ( out+numexp*9+20 > outtop ) {
555 LONG oldsize = (LONG)(out - AC.tokens);
556 SBYTE **ppp = &(AC.tokens);
557 SBYTE **pppp = &(AC.toptokens);
558 DoubleBuffer((
void **)ppp,(
void **)pppp,
sizeof(SBYTE),
"out tokens");
559 out = AC.tokens + oldsize;
560 outtop = AC.toptokens - MAXNUMSIZE;
562 tt = out + numexp*9+20;
563 while ( out >= AC.tokens ) { *tt-- = *out--; }
564 while ( tt >= AC.tokens ) { *tt-- = TEMPTY; }
565 if ( error == 0 && simp3btoken(AC.tokens,leftright) ) error = 1;
566 if ( error == 0 && simp2token(AC.tokens) ) error = 1;
572 if ( error == 0 && simp5token(AC.tokens,leftright) ) error = 1;
577 if ( error == 0 && simp6token(AC.tokens,leftright) ) error = 1;
587 char *ttypes[] = {
"\n",
"S",
"I",
"V",
"F",
"set",
"E",
"dotp",
"#",
588 "sub",
"d_",
"$",
"dub",
"(",
")",
"?",
"??",
".",
"[",
"]",
589 ",",
"((",
"))",
"*",
"/",
"^",
"+",
"-",
"!",
"end",
"{{",
"}}",
590 "N_?",
"conj",
"()",
"#d",
"^d",
"_",
"snum" };
592 void WriteTokens(SBYTE *in)
594 int numinline = 0, x, n =
sizeof(ttypes)/
sizeof(
char *);
595 char outbuf[81], *s, *out, c;
597 while ( *in != TENDOFIT ) {
601 while ( *s ) { *out++ = *s++; numinline++; }
604 *out++ =
'-'; x = -*in; numinline++;
613 *out++ = (char)(( x % 10 ) +
'0');
617 c = out[-1]; out[-1] = *s; *s = c;
619 if ( numinline > 70 ) {
621 MesPrint(
"%s",outbuf);
622 out = outbuf; numinline = 0;
625 *out++ =
' '; numinline++;
629 if ( numinline > 0 ) { *out = 0; MesPrint(
"%s",outbuf); }
640 int simp1token(SBYTE *s)
642 int error = 0, n, i, base;
644 SBYTE *fill = s, *start, *t, numtab[10];
646 while ( *s != TENDOFIT ) {
647 if ( *s == RBRACE ) {
649 while ( *start != LBRACE ) start--;
651 while ( *t >= 0 ) t--;
652 if ( *t == TSET && ( start[1] == TNUMBER || start[1] == TNUMBER1 ) ) {
653 base = start[1] == TNUMBER ? 100: 128;
656 while ( *start >= 0 && start < fill )
657 { numsub = base*numsub + *start++; }
658 if ( start == fill ) {
660 t++; n = *t++;
while ( *t >= 0 ) { n = 128*n + *t++; }
662 if ( ( set->type != CRANGE )
663 && ( numsub > 0 && numsub <= set->last-set->first ) ) {
665 n = SetElements[
set->first+numsub-1];
668 if ( n > MAXPOWER ) {
670 if ( n < 0 ) { n = -n; *fill++ = TMINUS; }
673 else *fill++ = TSYMBOL;
676 if ( n < AM.OffsetIndex ) *fill++ = TNUMBER1;
682 case CVECTOR: *fill++ = TVECTOR;
683 n -= AM.OffsetVector;
break;
684 case CFUNCTION: *fill++ = TFUNCTION;
685 n -= FUNCTION;
break;
686 case CNUMBER: *fill++ = TNUMBER1;
break;
687 case CDUBIOUS: *fill++ = TDUBIOUS; n = 1;
break;
691 MesPrint(
"Value of n = %d",n);
693 do { numtab[i++] = (SBYTE)(n & 0x7F); n >>= 7; }
while ( n );
694 while ( --i >= 0 ) *fill++ = numtab[i];
697 MesPrint(
"&Illegal element %d in set",numsub);
729 int simpwtoken(SBYTE *s)
731 int error = 0, first = 1, notflag;
732 WORD num, numto, numdollar, *w = AC.WildC, *wstart, *wtop;
733 SBYTE *fill = s, *t, *v, *s0 = s;
734 while ( *s != TENDOFIT ) {
735 if ( *s == TWILDCARD ) {
736 notflag = 0; t = fill;
737 while ( t > s0 && t[-1] >= 0 ) t--;
738 v = t; num = 0; *fill++ = *s++;
739 while ( *v >= 0 ) num = 128*num + *v++;
742 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
746 *w++ = SYMTOSYM; *w++ = 4; *w++ = num; *w++ = num;
break;
748 num += AM.OffsetIndex;
749 *w++ = INDTOIND; *w++ = 4; *w++ = num; *w++ = num;
break;
751 num += AM.OffsetVector;
752 *w++ = VECTOVEC; *w++ = 4; *w++ = num; *w++ = num;
break;
755 *w++ = FUNTOFUN; *w++ = 4; *w++ = num; *w++ = num;
break;
757 MesPrint(
"&Illegal type of wildcard in LHS");
759 *w++ = SYMTOSYM; *w++ = 4; *w++ = num; *w++ = num;
break;
766 if ( *s == TNOT && s[1] == TSET ) { notflag = 1; s++; }
768 s++; num = 0;
while ( *s >= 0 ) num = 128*num + *s++;
769 if ( notflag == 0 && *s == TWILDCARD && s[1] == TSET ) {
770 s += 2; numto = 0;
while ( *s >= 0 ) numto = 128*numto + *s++;
771 if ( num < AM.NumFixedSets || numto < AM.NumFixedSets
772 || Sets[num].type == CRANGE || Sets[numto].type == CRANGE ) {
773 MesPrint(
"&This type of set not allowed in this wildcard construction");
778 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
779 *w++ = FROMSET; *w++ = 4; *w++ = num; *w++ = numto;
783 else if ( notflag == 0 && *s == LBRACE && s[1] == TSYMBOL ) {
784 if ( num < AM.NumFixedSets || Sets[num].type == CRANGE ) {
785 MesPrint(
"&This type of set not allowed in this wildcard construction");
789 numto = 0;
while ( *s >= 0 ) numto = 128*numto + *s++;
790 if ( *s == TWILDCARD ) s++;
791 if ( *s == RBRACE ) {
794 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
795 *w++ = SETTONUM; *w++ = 4; *w++ = num; *w++ = numto;
797 *w++ = SYMTOSYM; *w++ = 4; *w++ = numto; *w++ = 0;
799 else if ( *s == TDOLLAR ) {
801 while ( *s >= 0 ) numdollar = 128*numdollar + *s++;
802 if ( *s == RBRACE ) {
805 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
806 *w++ = SETTONUM; *w++ = 4; *w++ = num; *w++ = numto;
808 *w++ = SYMTOSYM; *w++ = 4; *w++ = numto; *w++ = 0;
809 *w++ = LOADDOLLAR; *w++ = 4; *w++ = numdollar;
812 else { s = v;
goto singlewild; }
814 else { s = v;
goto singlewild; }
817 singlewild: num += notflag * 2*WILDOFFSET;
819 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
820 *w++ = FROMSET; *w++ = 4; *w++ = num; *w++ = -WILDOFFSET;
824 else if ( *s != TDOLLAR && *s != TENDOFIT && *s != RPARENTHESIS
825 && *s != RBRACE && *s != TCOMMA && *s != TFUNCLOSE && *s != TMULTIPLY
826 && *s != TPOWER && *s != TDIVIDE && *s != TPLUS && *s != TMINUS
827 && *s != TPOWER1 && *s != TEMPTY && *s != TFUNOPEN && *s != TDOT ) {
828 MesPrint(
"&Illegal type of wildcard in LHS");
831 if ( *s == TDOLLAR ) {
833 while ( *s >= 0 ) numdollar = 128*numdollar + *s++;
835 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
838 while ( w > wstart ) { w[4] = w[0]; w--; }
840 *w++ = LOADDOLLAR; *w++ = 4; *w++ = numdollar; *w++ = numdollar;
844 else if ( *s == TWILDARG ) {
847 while ( *s >= 0 ) { num = 128*num + *s; *fill++ = *s++; }
849 if ( AC.NwildC > 4*AM.MaxWildcards ) {
850 firsterr:
if ( first ) {
851 MesPrint(
"&More than %d wildcards",AM.MaxWildcards);
856 else { *w++ = ARGTOARG; *w++ = 4; *w++ = num; *w++ = -1; }
857 if ( *s == TDOLLAR ) {
858 s++; num = 0;
while ( *s >= 0 ) num = 128*num + *s++;
860 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
861 *w++ = LOADDOLLAR; *w++ = 4; *w++ = num; *w++ = num;
883 int simp2token(SBYTE *s)
885 SBYTE *to, *fill, *t, *v, *w, *s0 = s, *vv;
891 while ( *s != TENDOFIT ) {
892 if ( *s == LPARENTHESIS && s[1] == LPARENTHESIS ) {
896 if ( *t == LPARENTHESIS ) n++;
897 else if ( *t == RPARENTHESIS ) n--;
899 if ( t[1] == RPARENTHESIS ) {
904 else if ( *s == TEMPTY ) s++;
905 else if ( *s == AM.facnum && ( fill > (s0+1) ) && fill[-2] == TDIVIDE
906 && fill[-1] == TFUNCTION ) {
907 fill[-2] = TMULTIPLY; *fill++ = (SBYTE)(AM.invfacnum); s++;
909 else if ( *s == AM.invfacnum && ( fill > (s0+1) ) && fill[-2] == TDIVIDE
910 && fill[-1] == TFUNCTION ) {
911 fill[-2] = TMULTIPLY; *fill++ = (SBYTE)(AM.facnum); s++;
922 while ( *s != TENDOFIT ) {
923 if ( *s == LPARENTHESIS ) {
927 if ( *t == LPARENTHESIS ) n++;
928 else if ( *t == RPARENTHESIS ) n--;
930 if ( t[1] == TFUNCLOSE && s[1] != TWILDARG ) {
932 while ( n >= 0 && v >= to ) {
933 if ( *v == TFUNOPEN ) n--;
934 else if ( *v == TFUNCLOSE ) n++;
938 while ( *v >= 0 ) v--;
939 if ( *v == TFUNCTION ) { v++;
940 n = 0;
while ( *v >= 0 && v < fill ) n = 128*n + *v++;
941 if ( n == AM.sumnum || n == AM.sumpnum ) {
942 *fill++ = *s++;
continue;
944 else if ( ( n == (FIRSTBRACKET-FUNCTION)
945 || n == (TERMSINEXPR-FUNCTION)
946 || n == (NUMFACTORS-FUNCTION)
947 || n == (GCDFUNCTION-FUNCTION)
948 || n == (DIVFUNCTION-FUNCTION)
949 || n == (REMFUNCTION-FUNCTION)
950 || n == (INVERSEFUNCTION-FUNCTION)
951 || n == (MULFUNCTION-FUNCTION)
952 || n == (FACTORIN-FUNCTION)
953 || n == (FIRSTTERM-FUNCTION)
954 || n == (CONTENTTERM-FUNCTION) )
955 && fill[-1] == TFUNOPEN ) {
957 if ( *v == TEXPRESSION ) {
959 n = 0;
while ( *v >= 0 ) n = 128*n + *v++;
969 && ( ( fill[-1] == TFUNOPEN || fill[-1] == TCOMMA )
970 && ( t[1] == TFUNCLOSE || t[1] == TCOMMA ) ) ) {
975 if ( *v == TVECTOR ) {
976 w = v+1;
while ( *w >= 0 ) w++;
982 if ( *v == TNUMBER || *v == TNUMBER1 ) {
983 if ( BITSINWORD == 16 ) { LONG x; WORD base;
984 base = ( *v == TNUMBER ) ? 100: 128;
985 vv = v+1; x = 0;
while ( *vv >= 0 ) { x = x*base + *vv++; }
986 if ( ( vv != t ) || ( ( vv - v ) > 4 ) || ( x > (MAXPOSITIVE+1) ) )
988 else { *t = TEMPTY; s++;
break; }
990 else if ( BITSINWORD == 32 ) { LONG x; WORD base;
991 base = ( *v == TNUMBER ) ? 100: 128;
992 vv = v+1; x = 0;
while ( *vv >= 0 ) { x = x*base + *vv++; }
993 if ( ( vv != t ) || ( ( vv - v ) > 6 ) || ( x > (MAXPOSITIVE+1) ) )
995 else { *t = TEMPTY; s++;
break; }
998 if ( ( v+2 == t ) || ( v+3 == t && v[2] >= 0 ) )
999 { *t = TEMPTY; s++;
break; }
1000 else *fill++ = *s++;
1003 else if ( *v == LPARENTHESIS && t[-1] == RPARENTHESIS ) {
1007 if ( *w == LPARENTHESIS ) n++;
1008 else if ( *w == RPARENTHESIS ) n--;
1010 if ( w == ( t-1 ) ) { *t = TEMPTY; s++; }
1011 else *fill++ = *s++;
1013 else *fill++ = *s++;
1017 v++;
while ( *v >= 0 ) v++;
1020 if ( ( v[1] == COEFFSYMBOL || v[1] == NUMERATORSYMBOL
1021 || v[1] == DENOMINATORSYMBOL ) && v[2] < 0 ) {
1022 *fill++ = *s++;
break;
1030 tcommon: v++;
while ( *v >= 0 ) v++;
1031 if ( v == t || ( v[0] == TWILDCARD && v+1 == t ) )
1032 { *t = TEMPTY; s++; }
1033 else *fill++ = *s++;
1037 if ( v == t ) { *t = TEMPTY; s++; }
1038 else *fill++ = *s++;
1042 if ( BITSINWORD == 16 ) { LONG x; WORD base;
1043 base = ( *v == TNUMBER ) ? 100: 128;
1044 vv = v+1; x = 0;
while ( *vv >= 0 ) { x = x*base + *vv++; }
1045 if ( ( vv != t ) || ( ( vv - v ) > 4 ) || ( x > MAXPOSITIVE ) )
1047 else { *t = TEMPTY; s++;
break; }
1049 else if ( BITSINWORD == 32 ) { LONG x; WORD base;
1050 base = ( *v == TNUMBER ) ? 100: 128;
1051 vv = v+1; x = 0;
while ( *vv >= 0 ) { x = x*base + *vv++; }
1052 if ( ( vv != t ) || ( ( vv - v ) > 6 ) || ( x > MAXPOSITIVE ) )
1054 else { *t = TEMPTY; s++;
break; }
1057 if ( ( v+2 == t ) || ( v+3 == t && v[2] >= 0 ) )
1058 { *t = TEMPTY; s++;
break; }
1059 else *fill++ = *s++;
1063 v++;
while ( *v >= 0 ) v++;
1064 if ( v == t ) { *t = TEMPTY; s++; }
1065 else *fill++ = *s++;
1074 if ( *vv != TEXPRESSION )
break;
1075 vv++;
while ( *vv >= 0 ) vv++;
1077 if ( vv < t ) { *fill++ = *s++;
break; }
1082 while ( n >= 0 && w >= to ) {
1083 if ( *w == TFUNOPEN ) n--;
1084 else if ( *w == TFUNCLOSE ) n++;
1087 w--;
while ( w > to && *w >= 0 ) w--;
1088 if ( *w != TFUNCTION ) { *fill++ = *s++;
break; }
1090 while ( *w >= 0 ) { n = 128*n + *w++; }
1091 if ( n == GCDFUNCTION-FUNCTION
1092 || n == DIVFUNCTION-FUNCTION
1093 || n == REMFUNCTION-FUNCTION
1094 || n == INVERSEFUNCTION-FUNCTION
1095 || n == MULFUNCTION-FUNCTION ) {
1098 else *fill++ = *s++;
1100 default: *fill++ = *s++;
break;
1103 else *fill++ = *s++;
1105 else if ( *s == TEMPTY ) s++;
1106 else *fill++ = *s++;
1127 int simp3atoken(SBYTE *s,
int mode)
1129 int error = 0, n, numexp = 0, denom, base, numprot, i;
1133 if ( mode == RHSIDE ) {
1134 prot = AC.ProtoType;
1135 numprot = prot[1] - SUBEXPSIZE;
1138 else { prot = 0; numprot = 0; }
1139 while ( *s != TENDOFIT ) {
1141 if ( *s == TDIVIDE ) { denom = -1; s++; }
1147 s++;
while ( *s >= 0 ) s++;
1148 if ( *s == TWILDCARD ) s++;
1150 if ( *s != TPOWER )
continue;
1152 if ( *s == TMINUS ) s++;
1153 if ( *s == TNUMBER || *s == TNUMBER1 ) {
1154 base = *s == TNUMBER ? 100: 128;
1158 if ( num > MAXPOWER )
break;
1159 num = base*num + *s++;
1161 while ( *s >= 0 ) s++;
1162 if ( *s == TPOWER )
goto doublepower;
1163 if ( num <= MAXPOWER )
continue;
1165 else if ( *s == TSYMBOL && c != TNUMBER && c != TNUMBER1 ) {
1166 s++; n = 0;
while ( *s >= 0 ) { n = 128*n + *s++; }
1167 if ( *s == TWILDCARD ) { s++;
1168 if ( *s == TPOWER )
goto doublepower;
1173 if ( mode == RHSIDE ) {
1175 for ( i = 0; i < numprot; i += 4 ) {
1176 if ( prot[i+2] == n && prot[i] == SYMTOSYM )
break;
1178 if ( i < numprot )
break;
1180 if ( *s == TPOWER )
goto doublepower;
1185 s++;
while ( *s >= 0 ) s++;
1186 if ( *s == TWILDCARD ) s++;
1188 if ( denom < 0 || *s == TPOWER ) {
1189 MesPrint(
"&Index to a power or in denominator is illegal");
1194 s++;
while ( *s >= 0 ) s++;
1195 if ( *s == TWILDCARD ) s++;
1197 if ( *s == TFUNOPEN ) {
1200 if ( *s == TFUNOPEN ) {
1202 MesPrint(
"&Illegal vector index");
1205 else if ( *s == TFUNCLOSE ) {
1207 if ( n <= 0 )
break;
1213 else if ( *s == TDOT )
goto dodot;
1214 if ( denom < 0 || *s == TPOWER || *s == TPOWER1 ) numexp++;
1217 s++;
while ( *s >= 0 ) s++;
1218 if ( *s == TWILDCARD ) s++;
1221 if ( *t == TFUNOPEN ) {
1224 if ( *t == TFUNOPEN ) n++;
1225 else if ( *t == TFUNCLOSE ) {
if ( --n <= 0 )
break; }
1230 if ( denom < 0 || *t == TPOWER || *t == TPOWER1 ) numexp++;
1233 s++;
while ( *s >= 0 ) s++;
1235 if ( *t == TFUNOPEN ) {
1238 if ( *t == TFUNOPEN ) n++;
1239 else if ( *t == TFUNCLOSE ) {
if ( --n <= 0 )
break; }
1244 if ( *t == LBRACE ) {
1247 if ( *t == LBRACE ) n++;
1248 else if ( *t == RBRACE ) {
if ( --n <= 0 )
break; }
1253 if ( denom < 0 || ( ( *t == TPOWER || *t == TPOWER1 )
1254 && t[1] == TMINUS ) ) numexp++;
1257 s++;
while ( *s >= 0 ) s++;
1258 if ( denom < 0 || ( ( *s == TPOWER || *s == TPOWER1 )
1259 && s[1] == TMINUS ) ) numexp++;
1264 if ( *t == LPARENTHESIS ) n++;
1265 else if ( *t == RPARENTHESIS ) {
if ( --n <= 0 )
break; }
1269 if ( denom > 0 && ( *t == TPOWER || *t == TPOWER1 ) ) {
1270 if ( ( t[1] == TNUMBER || t[1] == TNUMBER1 ) && t[2] >= 0
1271 && t[3] < 0 )
break;
1274 else if ( denom < 0 && ( *t == TPOWER || *t == TPOWER1 ) ) {
1275 if ( t[1] == TMINUS && ( t[2] == TNUMBER
1276 || t[2] == TNUMBER1 ) && t[3] >= 0
1277 && t[4] < 0 )
break;
1280 else if ( denom < 0 || ( ( *t == TPOWER || *t == TPOWER1 )
1281 && ( t[1] == TMINUS || t[1] == LPARENTHESIS ) ) ) numexp++;
1284 s++; n = *s++;
while ( *s >= 0 ) { n = 128*n + *s++; }
1287 case CSYMBOL:
goto dosymbol;
1288 case CINDEX:
goto doindex;
1289 case CVECTOR:
goto dovector;
1290 case CFUNCTION:
goto dofunction;
1291 case CNUMBER:
goto dosymbol;
1292 default: error = 1;
break;
1297 if ( *s == TVECTOR ) { s++;
while ( *s >= 0 ) s++; }
1298 else if ( *s == TSET ) {
1299 s++; n = *s++;
while ( *s >= 0 ) { n = 128*n + *s++; }
1300 if ( Sets[n].type != CVECTOR ) {
1301 MesPrint(
"&Set in dotproduct is not a set of vectors");
1304 if ( *s == LBRACE ) {
1307 if ( *s == LBRACE ) n++;
1308 else if ( *s == RBRACE ) {
if ( --n <= 0 )
break; }
1314 MesPrint(
"&Set without argument in dotproduct");
1318 else if ( *s == TSETNUM ) {
1319 s++; n = *s++;
while ( *s >= 0 ) { n = 128*n + *s++; }
1320 if ( *s != TVECTOR )
goto nodot;
1321 s++; n = *s++;
while ( *s >= 0 ) { n = 128*n + *s++; }
1322 if ( Sets[n].type != CVECTOR ) {
1323 MesPrint(
"&Set in dotproduct is not a set of vectors");
1328 nodot: MesPrint(
"&Illegal second element in dotproduct");
1330 s++;
while ( *s >= 0 ) s++;
1334 s++;
while ( *s >= 0 ) s++;
1338 if ( error )
return(-1);
1341 MesPrint(
"&Dubious notation with object^power1^power2");
1350 int simp3btoken(SBYTE *s,
int mode)
1352 int error = 0, i, numprot, n, denom, base, inset = 0, dotp, sube = 0;
1353 SBYTE *t, c, *fill, *ff, *ss;
1356 if ( mode == RHSIDE ) {
1357 prot = AC.ProtoType;
1358 numprot = prot[1] - SUBEXPSIZE;
1361 else { prot = 0; numprot = 0; }
1363 while ( *s == TEMPTY ) s++;
1364 while ( *s != TENDOFIT ) {
1365 if ( *s == TEMPTY ) { s++;
continue; }
1367 if ( *s == TDIVIDE ) { denom = -1; *fill++ = *s++; }
1368 ff = fill; ss = s; c = *s;
1369 if ( c == TSETNUM ) {
1370 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1379 while ( *s >= 0 ) *fill++ = *s++;
1380 if ( *s == TWILDCARD ) *fill++ = *s++;
1383 if ( *s != TPOWER )
continue;
1385 if ( *s == TMINUS ) *fill++ = *s++;
1386 if ( *s == TPLUS ) s++;
1387 if ( *s == TSETNUM ) {
1388 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1392 if ( *s == TNUMBER || *s == TNUMBER1 ) {
1393 base = *s == TNUMBER ? 100: 128;
1395 num = *s++; *fill++ = num;
1397 if ( num > MAXPOWER )
break;
1399 num = base*num + *s++;
1401 while ( *s >= 0 ) *fill++ = *s++;
1402 if ( num <= MAXPOWER )
continue;
1405 else if ( *s == TSYMBOL && c != TNUMBER && c != TNUMBER1 ) {
1407 n = 0;
while ( *s >= 0 ) { n = 128*n + *s; *fill++ = *s++; }
1408 if ( *s == TWILDCARD ) { *fill++ = *s++;
1409 if ( *s == TPOWER )
goto doublepower;
1414 if ( mode == RHSIDE && inset == 0 ) {
1416 for ( i = 0; i < numprot; i += 4 ) {
1417 if ( prot[i+2] == n && prot[i] == SYMTOSYM )
break;
1419 if ( i < numprot )
break;
1423 if ( denom < 0 ) fill[-1] = TMULTIPLY;
1424 *fill++ = TFUNCTION; *fill++ = (SBYTE)(AM.expnum); *fill++ = TFUNOPEN;
1425 if ( dotp ) *fill++ = LPARENTHESIS;
1426 while ( ss < t ) *fill++ = *ss++;
1427 if ( dotp ) *fill++ = RPARENTHESIS;
1430 if ( *ss == TMINUS ) { denom = -denom; ss++; }
1432 *fill++ = LPARENTHESIS;
1434 while ( ss < s ) *fill++ = *ss++;
1435 *fill++ = RPARENTHESIS;
1438 while ( ss < s ) *fill++ = *ss++;
1440 *fill++ = TFUNCLOSE;
1441 if ( *ss == TPOWER )
goto doublepower;
1448 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1449 if ( *s == TWILDCARD ) *fill++ = *s++;
1452 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1453 if ( *s == TWILDCARD ) *fill++ = *s++;
1455 if ( *s == TFUNOPEN ) {
1456 while ( *s != TFUNCLOSE ) *fill++ = *s++;
1459 else if ( *s == TDOT )
goto dodot;
1463 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1464 if ( *s == TWILDCARD ) *fill++ = *s++;
1467 if ( *t == TFUNOPEN ) {
1470 if ( *t == TFUNOPEN ) n++;
1471 else if ( *t == TFUNCLOSE ) {
if ( --n <= 0 )
break; }
1474 t++; *fill++ = *s++;
1478 if ( *t == TPOWER || *t == TPOWER1 ) {
1480 if ( ( t[1] == TNUMBER || t[1] == TNUMBER1 )
1482 if ( t[2] >= 0 && t[3] < 0 ) { sube = 0;
break; }
1484 else if ( t[1] == TMINUS && denom < 0 &&
1485 ( t[2] == TNUMBER || t[2] == TNUMBER1 ) ) {
1486 if ( t[2] >= 0 && t[3] < 0 ) { sube = 0;
break; }
1491 *fill++ = TFUNCTION; *fill++ = (SBYTE)(AM.expnum); *fill++ = TFUNOPEN;
1492 *fill++ = LPARENTHESIS;
1493 while ( ss < t ) *fill++ = *ss++;
1495 *fill++ = RPARENTHESIS; *fill++ = TCOMMA;
1496 if ( *t == TMINUS ) { t++; denom = -denom; }
1497 *fill++ = LPARENTHESIS;
1498 if ( denom < 0 ) *fill++ = TMINUS;
1499 if ( *t == LPARENTHESIS ) {
1500 *fill++ = *t++; n = 0;
1502 if ( *t == LPARENTHESIS ) n++;
1503 else if ( *t == RPARENTHESIS ) n--;
1507 else if ( *t == TFUNCTION || *t == TDUBIOUS ) {
1508 *fill++ = *t++;
while ( *t >= 0 ) *fill++ = *t++;
1509 if ( *t == TWILDCARD ) *fill++ = *t++;
1510 if ( *t == TFUNOPEN ) {
1511 *fill++ = *t++; n = 0;
1513 if ( *t == TFUNOPEN ) n++;
1514 else if ( *t == TFUNCLOSE ) n--;
1519 else if ( *t == TSET ) {
1520 *fill++ = *t++; n = 0;
1521 while ( *t >= 0 ) { n = 128*n + *t; *fill++ = *t++; }
1522 if ( *t == LBRACE ) {
1523 if ( n < AM.NumFixedSets || Sets[n].type == CRANGE ) {
1524 MesPrint(
"&This type of usage of sets is not allowed");
1527 *fill++ = *t++; n = 0;
1529 if ( *t == LBRACE ) n++;
1530 else if ( *t == RBRACE ) n--;
1535 else if ( *t == TEXPRESSION ) {
1536 *fill++ = *t++;
while ( *t >= 0 ) *fill++ = *t++;
1537 if ( *t == TFUNOPEN ) {
1538 *fill++ = *t++; n = 0;
1540 if ( *t == TFUNOPEN ) n++;
1541 else if ( *t == TFUNCLOSE ) n--;
1545 if ( *t == LBRACE ) {
1546 *fill++ = *t++; n = 0;
1548 if ( *t == LBRACE ) n++;
1549 else if ( *t == RBRACE ) n--;
1554 else if ( *t == TVECTOR ) {
1555 *fill++ = *t++;
while ( *t >= 0 ) *fill++ = *t++;
1556 if ( *t == TFUNOPEN ) {
1557 *fill++ = *t++; n = 0;
1559 if ( *t == TFUNOPEN ) n++;
1560 else if ( *t == TFUNCLOSE ) n--;
1564 else if ( *t == TDOT ) {
1566 if ( *t == TVECTOR || *t == TDUBIOUS ) {
1567 *fill++ = *t++;
while ( *t >= 0 ) *fill++ = *t++;
1569 else if ( *t == TSET ) {
1570 *fill++ = *t++; num = 0;
1571 while ( *t >= 0 ) { num = 128*num + *t; *fill++ = *t++; }
1572 if ( Sets[num].type != CVECTOR ) {
1573 MesPrint(
"&Illegal set type in dotproduct");
1576 if ( *t == LBRACE ) {
1577 *fill++ = *t++; n = 0;
1579 if ( *t == LBRACE ) n++;
1580 else if ( *t == RBRACE ) n--;
1585 else if ( *t == TSETNUM ) {
1587 while ( *t >= 0 ) { *fill++ = *t++; }
1589 while ( *t >= 0 ) { *fill++ = *t++; }
1593 MesPrint(
"&Illegal second element in dotproduct");
1598 *fill++ = *t++;
while ( *t >= 0 ) *fill++ = *t++;
1599 if ( *t == TWILDCARD ) *fill++ = *t++;
1601 *fill++ = RPARENTHESIS; *fill++ = TFUNCLOSE;
1602 if ( *t == TPOWER )
goto doublepower;
1603 while ( fill > ff ) *--t = *--fill;
1606 else if ( denom < 0 ) {
1607 fill = ff; ff[-1] = TMULTIPLY;
1608 *fill++ = TFUNCTION; *fill++ = (SBYTE)(AM.denomnum);
1609 *fill++ = TFUNOPEN; *fill++ = LPARENTHESIS;
1610 while ( ss < t ) *fill++ = *ss++;
1611 *fill++ = RPARENTHESIS; *fill++ = TFUNCLOSE;
1612 while ( fill > ff ) *--t = *--fill;
1613 s = t; denom = 1; sube = 0;
1619 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1621 if ( *t == TFUNOPEN ) {
1624 if ( *t == TFUNOPEN ) n++;
1625 else if ( *t == TFUNCLOSE ) {
if ( --n <= 0 )
break; }
1630 if ( *t == LBRACE ) {
1633 if ( *t == LBRACE ) n++;
1634 else if ( *t == RBRACE ) {
if ( --n <= 0 )
break; }
1639 if ( t > s || denom < 0 || ( ( *t == TPOWER || *t == TPOWER1 )
1640 && t[1] == TMINUS ) )
goto dofunpower;
1643 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1646 *fill++ = *s++; n = 1; t = s;
1648 if ( *t == LPARENTHESIS ) n++;
1649 else if ( *t == RPARENTHESIS ) {
if ( --n <= 0 )
break; }
1655 *fill++ = *s++; n = *s++; *fill++ = (SBYTE)n;
1656 while ( *s >= 0 ) { *fill++ = *s; n = 128*n + *s++; }
1659 case CSYMBOL:
goto dosymbol;
1661 case CVECTOR:
goto dovector;
1662 case CFUNCTION:
goto dofunction;
1663 case CNUMBER:
goto dosymbol;
1664 default: error = 1;
break;
1668 dodot: *fill++ = *s++;
1669 if ( *s == TVECTOR ) {
1670 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1672 else if ( *s == TSET ) {
1673 *fill++ = *s++; n = *s++; *fill++ = (SBYTE)n;
1674 while ( *s >= 0 ) { *fill++ = *s; n = 128*n + *s++; }
1675 if ( *s == LBRACE ) {
1676 if ( n < AM.NumFixedSets || Sets[n].type == CRANGE ) {
1677 MesPrint(
"&This type of usage of sets is not allowed");
1680 *fill++ = *s++; n = 1;
1682 if ( *s == LBRACE ) n++;
1683 else if ( *s == RBRACE ) {
if ( --n <= 0 )
break; }
1689 MesPrint(
"&Set without argument in dotproduct");
1693 else if ( *s == TSETNUM ) {
1694 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1695 if ( *s != TVECTOR )
goto nodot;
1696 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1699 nodot: MesPrint(
"&Illegal second element in dotproduct");
1702 while ( *s >= 0 ) *fill++ = *s++;
1708 while ( *s >= 0 ) *fill++ = *s++;
1715 MesPrint(
"&Dubious notation with power of power");
1726 int simp4token(SBYTE *s)
1728 int error = 0, n, nsym, settype;
1729 WORD i, *w, *wstop, level;
1730 SBYTE *
const s0 = s;
1731 SBYTE *fill = s, *s1, *s2, *s3, type, s1buf[10];
1732 SBYTE *tbuf = s, *t, *t1;
1734 while ( *s != TENDOFIT ) {
1736 if ( *s == TEMPTY ) s++;
1737 else *fill++ = *s++;
1740 if ( fill >= (s0+1) && fill[-1] == TWILDCARD ) { *fill++ = *s++;
continue; }
1741 if ( fill >= (s0+2) && fill[-1] == TNOT && fill[-2] == TWILDCARD ) { *fill++ = *s++;
continue; }
1742 s1 = s++; n = 0;
while ( *s >= 0 ) { n = 128*n + *s++; }
1744 if ( *s != LBRACE ) {
while ( s1 < s ) *fill++ = *s1++;
continue; }
1745 if ( n < AM.NumFixedSets || i == CRANGE ) {
1746 MesPrint(
"&It is not allowed to refer to individual elements of built in or ranged sets");
1750 if ( *s != TSYMBOL && *s != TDOLLAR ) {
1751 MesPrint(
"&Set index in RHS is not a wildcard symbol or $-variable");
1753 while ( s1 < s ) *fill++ = *s1++;
continue;
1755 settype = ( *s == TDOLLAR );
1756 s++; nsym = 0; s2 = s;
1757 while ( *s >= 0 ) nsym = 128*nsym + *s++;
1758 if ( *s != RBRACE ) {
1759 MesPrint(
"&Improper set argument in RHS");
1761 while ( s1 < s ) *fill++ = *s1++;
continue;
1768 w = AC.ProtoType; wstop = w + w[1]; w += SUBEXPSIZE;
1769 while ( w < wstop ) {
1770 if ( *w == SYMTOSYM && w[2] == nsym )
break;
1778 while ( t >= tbuf ) {
1779 if ( *t == TFUNCLOSE ) {
1781 while ( t >= tbuf ) {
1782 if ( *t == TFUNCLOSE ) level++;
1783 else if ( *t == TFUNOPEN ) {
1785 if ( level == 0 )
break;
1790 else if ( *t == RBRACE ) {
1792 while ( t >= tbuf ) {
1793 if ( *t == RBRACE ) level++;
1794 else if ( *t == LBRACE ) {
1796 if ( level == 0 )
break;
1801 else if ( *t == RPARENTHESIS ) {
1803 while ( t >= tbuf ) {
1804 if ( *t == RPARENTHESIS ) level++;
1805 else if ( *t == LPARENTHESIS ) {
1807 if ( level == 0 )
break;
1812 else if ( *t == TFUNOPEN ) {
1814 while ( *t1 > 0 && t1 > tbuf ) t1--;
1815 if ( *t1 == TFUNCTION ) {
1817 while ( *t1 > 0 ) level = level*128+*t1++;
1818 if ( level == (SUMF1-FUNCTION)
1819 || level == (SUMF2-FUNCTION) ) {
1821 if ( *t1 == LPARENTHESIS ) t1++;
1822 if ( *t1 == TSYMBOL ) {
1823 if ( ( t1[1] == COEFFSYMBOL
1824 || t1[1] == NUMERATORSYMBOL
1825 || t1[1] == DENOMINATORSYMBOL )
1829 while ( *t1 >= 0 && t1 < fill ) level = 128*level + *t1++;
1830 if ( level == nsym && t1 < fill ) {
1831 if ( t[1] == LPARENTHESIS
1832 && *t1 == RPARENTHESIS && t1[1] == TCOMMA )
break;
1833 if ( t[1] != LPARENTHESIS && *t1 == TCOMMA )
break;
1844 MesPrint(
"&Set index in RHS is not a wildcard symbol");
1846 while ( s1 < s ) *fill++ = *s1++;
continue;
1854 case CSYMBOL: type = TSYMBOL;
break;
1855 case CINDEX: type = TINDEX;
break;
1856 case CVECTOR: type = TVECTOR;
break;
1857 case CFUNCTION: type = TFUNCTION;
break;
1858 case CNUMBER: type = TNUMBER1;
break;
1859 case CDUBIOUS: type = TDUBIOUS;
break;
1861 MesPrint(
"&Unknown set type in simp4token");
1862 error = 1; type = CDUBIOUS;
break;
1865 while ( *s1 >= 0 ) *s3++ = *s1++;
1866 *s3 = -1; s1 = s1buf;
1867 if ( settype ) *fill++ = TSETDOL;
1868 else *fill++ = TSETNUM;
1869 while ( *s2 >= 0 ) *fill++ = *s2++;
1870 *fill++ = type;
while ( *s1 >= 0 ) *fill++ = *s1++;
1883 int simp5token(SBYTE *s,
int mode)
1885 int error = 0, n, type;
1887 if ( mode == RHSIDE ) {
1888 while ( *s != TENDOFIT ) {
1889 if ( *s == TFUNCTION ) {
1890 s++; n = 0;
while ( *s >= 0 ) n = 128*n + *s++;
1891 if ( n == AM.sumnum || n == AM.sumpnum ) {
1892 if ( *s != TFUNOPEN )
continue;
1894 if ( *s != TSYMBOL && *s != TINDEX )
continue;
1896 n = 0;
while ( *s >= 0 ) n = 128*n + *s++;
1897 if ( type == TINDEX ) n += AM.OffsetIndex;
1898 if ( *s != TCOMMA )
continue;
1902 while ( w < wstop ) {
1904 if ( ( type == TSYMBOL && ( w[0] == SYMTOSYM
1905 || w[0] == SYMTONUM || w[0] == SYMTOSUB ) ) || (
1906 type == TINDEX && ( w[0] == INDTOIND
1907 || w[0] == INDTOSUB ) ) ) {
1909 MesPrint(
"&Parameter of sum function is already a wildcard");
1929 int simp6token(SBYTE *tokens,
int mode)
1933 int level = 0, haveone = 0;
1934 SBYTE *s = tokens, *ss;
1938 if ( mode == RHSIDE ) {
1939 while ( *s == TPLUS || *s == TMINUS ) s++;
1941 while ( *s != TENDOFIT ) {
1942 if ( *s == LPARENTHESIS ) level++;
1943 else if ( *s == RPARENTHESIS ) level--;
1944 else if ( *s == TFUNOPEN ) level++;
1945 else if ( *s == TFUNCLOSE ) level--;
1946 else if ( ( *s == TPLUS || *s == TMINUS ) && level == 0 ) {
1950 if ( s[-1] != TPOWER && s[-1] != TPLUS && s[-1] != TMINUS ) {
1954 else if ( *s == TEXPRESSION ) {
1956 s++; n = 0;
while ( *s >= 0 ) n = 128*n + *s++;
1958 if ( Expressions[n].status == STOREDEXPRESSION ) {
1967 WORD TMproto[SUBEXPSIZE];
1968 TMproto[0] = EXPRESSION;
1969 TMproto[1] = SUBEXPSIZE;
1972 {
int ie;
for ( ie = 4; ie < SUBEXPSIZE; ie++ ) TMproto[ie] = 0; }
1973 AT.TMaddr = TMproto;
1982 if ( ( renumber = GetTable(n,&position,0) ) == 0 )
1985 MesPrint(
"&Problems getting information about stored expression %s(4)" 1991 if ( renumber->
symb.
lo != AN.dummyrenumlist )
1992 M_free(renumber->
symb.
lo,
"VarSpace");
1993 M_free(renumber,
"Renumber");
1999 if ( ( ( AS.Oldvflags[n] & ISFACTORIZED ) != 0 ) && *s != LBRACE ) {
2003 else if ( error == 0 ) {
2004 if ( ss[-1] != TFUNOPEN || funnum != NUMFACTORS-FUNCTION ) {
2005 MesPrint(
"&Illegal use of factorized expression(s) in RHS");
2012 else if ( *s == TFUNCTION ) {
2013 s++; funnum = 0;
while ( *s >= 0 ) funnum = 128*funnum + *s++;
2019 if ( numterms > 1 ) {
2020 MesPrint(
"&Factorized expression in RHS in an expression of more than one term.");
2023 else if ( AC.ToBeInFactors == 0 ) {
2024 MesPrint(
"&Attempt to put a factorized expression inside an unfactorized expression.");