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' && s[1] ==
'0' ) 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] ==
'[' )
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);
235 if (
object != -1 )
goto IllPos;
237 if ( FG.cTable[*in] == 0 || FG.cTable[*in] == 1 ) {
239 while ( FG.cTable[*in] == 0 || FG.cTable[*in] == 1 ) in++;
241 i = GetWildcardName((UBYTE *)s);
243 MesPrint(
"&Undefined argument list variable %s",s);
256 else if ( *in ==
'.' ) {
264 else if ( *in ==
'$' ) {
267 if ( FG.cTable[*in] == 0 ) {
268 while ( FG.cTable[*in] == 0 || FG.cTable[*in] == 1 ) in++;
269 if ( *in ==
'_' && AP.PreAssignFlag == 2 ) in++;
272 if (
object != 1 || leftright == RHSIDE ) {
273 MesPrint(
"&Illegal position for $%s",s);
274 if ( !error ) error = 1;
277 if ( ( number = GetDollar(s) ) < 0 ) {
278 number = AddDollar(s,0,0,0);
282 else if ( ( number = GetDollar(s) ) < 0 ) {
283 MesPrint(
"&Undefined variable $%s",s);
284 if ( !error ) error = 1;
285 number = AddDollar(s,0,0,0);
289 if ( ( AC.exprfillwarning == 0 ) &&
290 ( ( out > AC.tokens+1 ) && ( out[-2] != TWILDCARD ) ) ) {
291 AC.exprfillwarning = 1;
296 MesPrint(
"Illegal name for $ variable after %s",in);
297 if ( !error ) error = 1;
300 else if ( *in ==
'#' ) {
312 if ( *t == RPARENTHESIS ) {
313 *out++ = LBRACE; *out++ = LPARENTHESIS;
314 bracelevel++; explevel = bracelevel;
317 while ( *t >= 0 && t > AC.tokens ) t--;
318 if ( *t == TEXPRESSION ) {
319 *out++ = LBRACE; *out++ = LPARENTHESIS;
320 bracelevel++; explevel = bracelevel;
322 else {*out++ = LBRACE; bracelevel++; }
333 if ( explevel > 0 && explevel == bracelevel ) {
334 *out++ = RPARENTHESIS; explevel = 0;
336 *out++ = RBRACE;
object = 1; bracelevel--;
342 if ( funlevel >= AM.MaxParLevel ) {
343 MesPrint(
"&More than %d levels of parentheses",AM.MaxParLevel);
347 AC.tokenarglevel[funlevel++] = TYPEISFUN;
350 if ( in[1] !=
')' && in[1] !=
',' ) {
351 *out++ = TNUMBER; *out++ = (SBYTE)(polyflag);
353 *out++ = LPARENTHESIS;
356 *out++ = LPARENTHESIS;
357 *out++ = TNUMBER; *out++ = (SBYTE)(polyflag);
361 else if ( in[1] !=
')' && in[1] !=
',' ) {
362 *out++ = LPARENTHESIS;
365 else if (
object <= 0 ) {
367 AC.tokenarglevel[funlevel++] = TYPEISSUB;
368 *out++ = LPARENTHESIS;
372 AC.tokenarglevel[funlevel++] = TYPEISMYSTERY;
373 MesPrint(
"&Illegal position for (: %s",in);
374 if ( error >= 0 ) error = -1;
378 else if ( *in ==
')' ) {
380 if ( funlevel < 0 ) {
382 MesPrint(
"&There is an unmatched parenthesis");
383 if ( error >= 0 ) error = -1;
386 else if (
object <= 0
387 && ( AC.tokenarglevel[funlevel] != TYPEISFUN
388 || out[-1] != TFUNOPEN ) ) {
389 MesPrint(
"&Illegal position for closing parenthesis.");
390 if ( error >= 0 ) error = -1;
391 if ( AC.tokenarglevel[funlevel] == TYPEISFUN )
object = 1;
395 if ( AC.tokenarglevel[funlevel] == TYPEISFUN ) {
396 if ( out[-1] == TFUNOPEN ) out--;
398 if ( out[-1] != TCOMMA ) *out++ = RPARENTHESIS;
403 else if ( AC.tokenarglevel[funlevel] == TYPEISSUB ) {
404 *out++ = RPARENTHESIS;
409 else if ( *in ==
',' ) {
411 AC.tokenarglevel[funlevel-1] == TYPEISFUN ) {
412 if ( out[-1] != TFUNOPEN && out[-1] != TCOMMA )
413 *out++ = RPARENTHESIS;
414 else { *out++ = TNUMBER; *out++ = 0; }
416 if ( in[1] !=
',' && in[1] !=
')' )
417 *out++ = LPARENTHESIS;
418 else if ( in[1] ==
')' ) {
419 *out++ = TNUMBER; *out++ = 0;
427 MesPrint(
"&Illegal position for comma: %s",in);
428 MesPrint(
"&Forgotten ; ?");
429 if ( error >= 0 ) error = -1;
438 if ( *in ==
':' || *in ==
'%' )
goto IllPos;
439 if ( *in ==
'*' || *in ==
'/' || *in ==
'^' ) {
441 MesPrint(
"&Illegal position for operator: %s",in);
442 if ( error >= 0 ) error = -1;
444 else if ( *in ==
'*' ) *out++ = TMULTIPLY;
445 else if ( *in ==
'/' ) *out++ = TDIVIDE;
446 else *out++ = TPOWER;
451 while ( *in ==
'+' || *in ==
'-' ) {
452 if ( *in ==
'-' ) i = -i;
456 if ( out > AC.tokens && out[-1] != TFUNOPEN &&
457 out[-1] != LPARENTHESIS && out[-1] != TCOMMA
458 && out[-1] != LBRACE )
461 else *out++ = TMINUS;
472 number = DoTempSet(s,in);
477 do { num[i++] = (SBYTE)(number & 0x7F); number >>= 7; }
while ( number );
478 while ( --i >= 0 ) *out++ = num[i];
480 else if ( error == 0 ) error = 1;
487 if ( *in !=
'!' || leftright == RHSIDE
488 ||
object != 1 || out[-1] != TWILDCARD )
goto IllPos;
490 if ( FG.cTable[in[1]] == 0 || in[1] ==
'[' )
object = 0;
494 IllPos: MesPrint(
"&Illegal character at this position: %s",in);
495 if ( error >= 0 ) error = -1;
502 AC.endoftokens = out;
503 if ( funlevel > 0 || bracelevel != 0 ) {
504 if ( funlevel > 0 ) MesPrint(
"&Unmatched parentheses");
505 if ( bracelevel != 0 ) MesPrint(
"&Unmatched braces");
508 if ( AC.TokensWriteFlag ) WriteTokens(AC.tokens);
512 if ( error == 0 && simp1token(AC.tokens) ) error = 1;
516 if ( error == 0 && leftright == LHSIDE && simpwtoken(AC.tokens) )
521 if ( error == 0 && leftright == RHSIDE && simp4token(AC.tokens) )
526 if ( error == 0 && simp2token(AC.tokens) ) error = 1;
535 if ( error == 0 && ( numexp = simp3atoken(AC.tokens,leftright) ) < 0 )
540 while ( *out != TENDOFIT ) out++;
541 while ( out+numexp*9+20 > outtop ) {
542 LONG oldsize = (LONG)(out - AC.tokens);
543 SBYTE **ppp = &(AC.tokens);
544 SBYTE **pppp = &(AC.toptokens);
545 DoubleBuffer((
void **)ppp,(
void **)pppp,
sizeof(SBYTE),
"out tokens");
546 out = AC.tokens + oldsize;
547 outtop = AC.toptokens - MAXNUMSIZE;
549 tt = out + numexp*9+20;
550 while ( out >= AC.tokens ) { *tt-- = *out--; }
551 while ( tt >= AC.tokens ) { *tt-- = TEMPTY; }
552 if ( error == 0 && simp3btoken(AC.tokens,leftright) ) error = 1;
553 if ( error == 0 && simp2token(AC.tokens) ) error = 1;
559 if ( error == 0 && simp5token(AC.tokens,leftright) ) error = 1;
564 if ( error == 0 && simp6token(AC.tokens,leftright) ) error = 1;
574 char *ttypes[] = {
"\n",
"S",
"I",
"V",
"F",
"set",
"E",
"dotp",
"#",
575 "sub",
"d_",
"$",
"dub",
"(",
")",
"?",
"??",
".",
"[",
"]",
576 ",",
"((",
"))",
"*",
"/",
"^",
"+",
"-",
"!",
"end",
"{{",
"}}",
577 "N_?",
"conj",
"()",
"#d",
"^d",
"_",
"snum" };
579 void WriteTokens(SBYTE *in)
581 int numinline = 0, x, n =
sizeof(ttypes)/
sizeof(
char *);
582 char outbuf[81], *s, *out, c;
584 while ( *in != TENDOFIT ) {
588 while ( *s ) { *out++ = *s++; numinline++; }
591 *out++ =
'-'; x = -*in; numinline++;
600 *out++ = (char)(( x % 10 ) +
'0');
604 c = out[-1]; out[-1] = *s; *s = c;
606 if ( numinline > 70 ) {
608 MesPrint(
"%s",outbuf);
609 out = outbuf; numinline = 0;
612 *out++ =
' '; numinline++;
616 if ( numinline > 0 ) { *out = 0; MesPrint(
"%s",outbuf); }
627 int simp1token(SBYTE *s)
629 int error = 0, n, i, base;
631 SBYTE *fill = s, *start, *t, numtab[10];
633 while ( *s != TENDOFIT ) {
634 if ( *s == RBRACE ) {
636 while ( *start != LBRACE ) start--;
638 while ( *t >= 0 ) t--;
639 if ( *t == TSET && ( start[1] == TNUMBER || start[1] == TNUMBER1 ) ) {
640 base = start[1] == TNUMBER ? 100: 128;
643 while ( *start >= 0 && start < fill )
644 { numsub = base*numsub + *start++; }
645 if ( start == fill ) {
647 t++; n = *t++;
while ( *t >= 0 ) { n = 128*n + *t++; }
649 if ( ( set->type != CRANGE )
650 && ( numsub > 0 && numsub <= set->last-set->first ) ) {
652 n = SetElements[
set->first+numsub-1];
655 if ( n > MAXPOWER ) {
657 if ( n < 0 ) { n = -n; *fill++ = TMINUS; }
660 else *fill++ = TSYMBOL;
663 if ( n < AM.OffsetIndex ) *fill++ = TNUMBER1;
669 case CVECTOR: *fill++ = TVECTOR;
670 n -= AM.OffsetVector;
break;
671 case CFUNCTION: *fill++ = TFUNCTION;
672 n -= FUNCTION;
break;
673 case CNUMBER: *fill++ = TNUMBER1;
break;
674 case CDUBIOUS: *fill++ = TDUBIOUS; n = 1;
break;
678 MesPrint(
"Value of n = %d",n);
680 do { numtab[i++] = (SBYTE)(n & 0x7F); n >>= 7; }
while ( n );
681 while ( --i >= 0 ) *fill++ = numtab[i];
684 MesPrint(
"&Illegal element %d in set",numsub);
716 int simpwtoken(SBYTE *s)
718 int error = 0, first = 1, notflag;
719 WORD num, numto, numdollar, *w = AC.WildC, *wstart, *wtop;
720 SBYTE *fill = s, *t, *v, *s0 = s;
721 while ( *s != TENDOFIT ) {
722 if ( *s == TWILDCARD ) {
723 notflag = 0; t = fill;
724 while ( t > s0 && t[-1] >= 0 ) t--;
725 v = t; num = 0; *fill++ = *s++;
726 while ( *v >= 0 ) num = 128*num + *v++;
729 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
733 *w++ = SYMTOSYM; *w++ = 4; *w++ = num; *w++ = -1;
break;
735 num += AM.OffsetIndex;
736 *w++ = INDTOIND; *w++ = 4; *w++ = num; *w++ = 0;
break;
738 num += AM.OffsetVector;
739 *w++ = VECTOVEC; *w++ = 4; *w++ = num; *w++ = 0;
break;
742 *w++ = FUNTOFUN; *w++ = 4; *w++ = num; *w++ = 0;
break;
744 MesPrint(
"&Illegal type of wildcard in LHS");
746 *w++ = SYMTOSYM; *w++ = 4; *w++ = num; *w++ = -1;
break;
753 if ( *s == TNOT && s[1] == TSET ) { notflag = 1; s++; }
755 s++; num = 0;
while ( *s >= 0 ) num = 128*num + *s++;
756 if ( notflag == 0 && *s == TWILDCARD && s[1] == TSET ) {
757 s += 2; numto = 0;
while ( *s >= 0 ) numto = 128*numto + *s++;
758 if ( num < AM.NumFixedSets || numto < AM.NumFixedSets
759 || Sets[num].type == CRANGE || Sets[numto].type == CRANGE ) {
760 MesPrint(
"&This type of set not allowed in this wildcard construction");
765 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
766 *w++ = FROMSET; *w++ = 4; *w++ = num; *w++ = numto;
770 else if ( notflag == 0 && *s == LBRACE && s[1] == TSYMBOL ) {
771 if ( num < AM.NumFixedSets || Sets[num].type == CRANGE ) {
772 MesPrint(
"&This type of set not allowed in this wildcard construction");
776 numto = 0;
while ( *s >= 0 ) numto = 128*numto + *s++;
777 if ( *s == TWILDCARD ) s++;
778 if ( *s == RBRACE ) {
781 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
782 *w++ = SETTONUM; *w++ = 4; *w++ = num; *w++ = numto;
784 *w++ = SYMTOSYM; *w++ = 4; *w++ = numto; *w++ = 0;
786 else if ( *s == TDOLLAR ) {
788 while ( *s >= 0 ) numdollar = 128*numdollar + *s++;
789 if ( *s == RBRACE ) {
792 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
793 *w++ = SETTONUM; *w++ = 4; *w++ = num; *w++ = numto;
795 *w++ = SYMTOSYM; *w++ = 4; *w++ = numto; *w++ = 0;
796 *w++ = LOADDOLLAR; *w++ = 4; *w++ = numdollar;
799 else { s = v;
goto singlewild; }
801 else { s = v;
goto singlewild; }
804 singlewild: num += notflag * 2*WILDOFFSET;
806 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
807 *w++ = FROMSET; *w++ = 4; *w++ = num; *w++ = -WILDOFFSET;
811 else if ( *s != TDOLLAR && *s != TENDOFIT && *s != RPARENTHESIS
812 && *s != RBRACE && *s != TCOMMA && *s != TFUNCLOSE && *s != TMULTIPLY
813 && *s != TPOWER && *s != TDIVIDE && *s != TPLUS && *s != TMINUS
814 && *s != TPOWER1 && *s != TEMPTY && *s != TFUNOPEN && *s != TDOT ) {
815 MesPrint(
"&Illegal type of wildcard in LHS");
818 if ( *s == TDOLLAR ) {
820 while ( *s >= 0 ) numdollar = 128*numdollar + *s++;
822 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
825 while ( w > wstart ) { w[4] = w[0]; w--; }
827 *w++ = LOADDOLLAR; *w++ = 4; *w++ = numdollar; *w++ = numdollar;
831 else if ( *s == TWILDARG ) {
834 while ( *s >= 0 ) { num = 128*num + *s; *fill++ = *s++; }
836 if ( AC.NwildC > 4*AM.MaxWildcards ) {
837 firsterr:
if ( first ) {
838 MesPrint(
"&More than %d wildcards",AM.MaxWildcards);
843 else { *w++ = ARGTOARG; *w++ = 4; *w++ = num; *w++ = -1; }
844 if ( *s == TDOLLAR ) {
845 s++; num = 0;
while ( *s >= 0 ) num = 128*num + *s++;
847 if ( AC.NwildC > 4*AM.MaxWildcards )
goto firsterr;
848 *w++ = LOADDOLLAR; *w++ = 4; *w++ = num; *w++ = num;
870 int simp2token(SBYTE *s)
872 SBYTE *to, *fill, *t, *v, *w, *s0 = s, *vv;
878 while ( *s != TENDOFIT ) {
879 if ( *s == LPARENTHESIS && s[1] == LPARENTHESIS ) {
883 if ( *t == LPARENTHESIS ) n++;
884 else if ( *t == RPARENTHESIS ) n--;
886 if ( t[1] == RPARENTHESIS ) {
891 else if ( *s == TEMPTY ) s++;
892 else if ( *s == AM.facnum && ( fill > (s0+1) ) && fill[-2] == TDIVIDE
893 && fill[-1] == TFUNCTION ) {
894 fill[-2] = TMULTIPLY; *fill++ = (SBYTE)(AM.invfacnum); s++;
896 else if ( *s == AM.invfacnum && ( fill > (s0+1) ) && fill[-2] == TDIVIDE
897 && fill[-1] == TFUNCTION ) {
898 fill[-2] = TMULTIPLY; *fill++ = (SBYTE)(AM.facnum); s++;
909 while ( *s != TENDOFIT ) {
910 if ( *s == LPARENTHESIS ) {
914 if ( *t == LPARENTHESIS ) n++;
915 else if ( *t == RPARENTHESIS ) n--;
917 if ( t[1] == TFUNCLOSE && s[1] != TWILDARG ) {
919 while ( n >= 0 && v >= to ) {
920 if ( *v == TFUNOPEN ) n--;
921 else if ( *v == TFUNCLOSE ) n++;
925 while ( *v >= 0 ) v--;
926 if ( *v == TFUNCTION ) { v++;
927 n = 0;
while ( *v >= 0 && v < fill ) n = 128*n + *v++;
928 if ( n == AM.sumnum || n == AM.sumpnum ) {
929 *fill++ = *s++;
continue;
931 else if ( ( n == (FIRSTBRACKET-FUNCTION)
932 || n == (TERMSINEXPR-FUNCTION)
933 || n == (NUMFACTORS-FUNCTION)
934 || n == (GCDFUNCTION-FUNCTION)
935 || n == (DIVFUNCTION-FUNCTION)
936 || n == (REMFUNCTION-FUNCTION)
937 || n == (INVERSEFUNCTION-FUNCTION)
938 || n == (FACTORIN-FUNCTION)
939 || n == (FIRSTTERM-FUNCTION)
940 || n == (CONTENTTERM-FUNCTION) )
941 && fill[-1] == TFUNOPEN ) {
943 if ( *v == TEXPRESSION ) {
945 n = 0;
while ( *v >= 0 ) n = 128*n + *v++;
955 && ( ( fill[-1] == TFUNOPEN || fill[-1] == TCOMMA )
956 && ( t[1] == TFUNCLOSE || t[1] == TCOMMA ) ) ) {
961 if ( *v == TVECTOR ) {
962 w = v+1;
while ( *w >= 0 ) w++;
968 if ( *v == TNUMBER || *v == TNUMBER1 ) {
969 if ( BITSINWORD == 16 ) { LONG x; WORD base;
970 base = ( *v == TNUMBER ) ? 100: 128;
971 vv = v+1; x = 0;
while ( *vv >= 0 ) { x = x*base + *vv++; }
972 if ( ( vv != t ) || ( ( vv - v ) > 4 ) || ( x > (MAXPOSITIVE+1) ) )
974 else { *t = TEMPTY; s++;
break; }
976 else if ( BITSINWORD == 32 ) { LONG x; WORD base;
977 base = ( *v == TNUMBER ) ? 100: 128;
978 vv = v+1; x = 0;
while ( *vv >= 0 ) { x = x*base + *vv++; }
979 if ( ( vv != t ) || ( ( vv - v ) > 6 ) || ( x > (MAXPOSITIVE+1) ) )
981 else { *t = TEMPTY; s++;
break; }
984 if ( ( v+2 == t ) || ( v+3 == t && v[2] >= 0 ) )
985 { *t = TEMPTY; s++;
break; }
989 else if ( *v == LPARENTHESIS && t[-1] == RPARENTHESIS ) {
993 if ( *w == LPARENTHESIS ) n++;
994 else if ( *w == RPARENTHESIS ) n--;
996 if ( w == ( t-1 ) ) { *t = TEMPTY; s++; }
1003 v++;
while ( *v >= 0 ) v++;
1006 if ( ( v[1] == COEFFSYMBOL || v[1] == NUMERATORSYMBOL
1007 || v[1] == DENOMINATORSYMBOL ) && v[2] < 0 ) {
1008 *fill++ = *s++;
break;
1016 tcommon: v++;
while ( *v >= 0 ) v++;
1017 if ( v == t || ( v[0] == TWILDCARD && v+1 == t ) )
1018 { *t = TEMPTY; s++; }
1019 else *fill++ = *s++;
1023 if ( v == t ) { *t = TEMPTY; s++; }
1024 else *fill++ = *s++;
1028 if ( BITSINWORD == 16 ) { LONG x; WORD base;
1029 base = ( *v == TNUMBER ) ? 100: 128;
1030 vv = v+1; x = 0;
while ( *vv >= 0 ) { x = x*base + *vv++; }
1031 if ( ( vv != t ) || ( ( vv - v ) > 4 ) || ( x > MAXPOSITIVE ) )
1033 else { *t = TEMPTY; s++;
break; }
1035 else if ( BITSINWORD == 32 ) { LONG x; WORD base;
1036 base = ( *v == TNUMBER ) ? 100: 128;
1037 vv = v+1; x = 0;
while ( *vv >= 0 ) { x = x*base + *vv++; }
1038 if ( ( vv != t ) || ( ( vv - v ) > 6 ) || ( x > MAXPOSITIVE ) )
1040 else { *t = TEMPTY; s++;
break; }
1043 if ( ( v+2 == t ) || ( v+3 == t && v[2] >= 0 ) )
1044 { *t = TEMPTY; s++;
break; }
1045 else *fill++ = *s++;
1049 v++;
while ( *v >= 0 ) v++;
1050 if ( v == t ) { *t = TEMPTY; s++; }
1051 else *fill++ = *s++;
1060 if ( *vv != TEXPRESSION )
break;
1061 vv++;
while ( *vv >= 0 ) vv++;
1063 if ( vv < t ) { *fill++ = *s++;
break; }
1068 while ( n >= 0 && w >= to ) {
1069 if ( *w == TFUNOPEN ) n--;
1070 else if ( *w == TFUNCLOSE ) n++;
1073 w--;
while ( w > to && *w >= 0 ) w--;
1074 if ( *w != TFUNCTION ) { *fill++ = *s++;
break; }
1076 while ( *w >= 0 ) { n = 128*n + *w++; }
1077 if ( n == GCDFUNCTION-FUNCTION
1078 || n == DIVFUNCTION-FUNCTION
1079 || n == REMFUNCTION-FUNCTION
1080 || n == INVERSEFUNCTION-FUNCTION ) {
1083 else *fill++ = *s++;
1085 default: *fill++ = *s++;
break;
1088 else *fill++ = *s++;
1090 else if ( *s == TEMPTY ) s++;
1091 else *fill++ = *s++;
1112 int simp3atoken(SBYTE *s,
int mode)
1114 int error = 0, n, numexp = 0, denom, base, numprot, i;
1118 if ( mode == RHSIDE ) {
1119 prot = AC.ProtoType;
1120 numprot = prot[1] - SUBEXPSIZE;
1123 else { prot = 0; numprot = 0; }
1124 while ( *s != TENDOFIT ) {
1126 if ( *s == TDIVIDE ) { denom = -1; s++; }
1132 s++;
while ( *s >= 0 ) s++;
1133 if ( *s == TWILDCARD ) s++;
1135 if ( *s != TPOWER )
continue;
1137 if ( *s == TMINUS ) s++;
1138 if ( *s == TNUMBER || *s == TNUMBER1 ) {
1139 base = *s == TNUMBER ? 100: 128;
1143 if ( num > MAXPOWER )
break;
1144 num = base*num + *s++;
1146 while ( *s >= 0 ) s++;
1147 if ( *s == TPOWER )
goto doublepower;
1148 if ( num <= MAXPOWER )
continue;
1150 else if ( *s == TSYMBOL && c != TNUMBER && c != TNUMBER1 ) {
1151 s++; n = 0;
while ( *s >= 0 ) { n = 128*n + *s++; }
1152 if ( *s == TWILDCARD ) { s++;
1153 if ( *s == TPOWER )
goto doublepower;
1158 if ( mode == RHSIDE ) {
1160 for ( i = 0; i < numprot; i += 4 ) {
1161 if ( prot[i+2] == n && prot[i] == SYMTOSYM )
break;
1163 if ( i < numprot )
break;
1165 if ( *s == TPOWER )
goto doublepower;
1170 s++;
while ( *s >= 0 ) s++;
1171 if ( *s == TWILDCARD ) s++;
1173 if ( denom < 0 || *s == TPOWER ) {
1174 MesPrint(
"&Index to a power or in denominator is illegal");
1179 s++;
while ( *s >= 0 ) s++;
1180 if ( *s == TWILDCARD ) s++;
1182 if ( *s == TFUNOPEN ) {
1185 if ( *s == TFUNOPEN ) {
1187 MesPrint(
"&Illegal vector index");
1190 else if ( *s == TFUNCLOSE ) {
1192 if ( n <= 0 )
break;
1198 else if ( *s == TDOT )
goto dodot;
1199 if ( denom < 0 || *s == TPOWER || *s == TPOWER1 ) numexp++;
1202 s++;
while ( *s >= 0 ) s++;
1203 if ( *s == TWILDCARD ) s++;
1206 if ( *t == TFUNOPEN ) {
1209 if ( *t == TFUNOPEN ) n++;
1210 else if ( *t == TFUNCLOSE ) {
if ( --n <= 0 )
break; }
1215 if ( denom < 0 || *t == TPOWER || *t == TPOWER1 ) numexp++;
1218 s++;
while ( *s >= 0 ) s++;
1220 if ( *t == TFUNOPEN ) {
1223 if ( *t == TFUNOPEN ) n++;
1224 else if ( *t == TFUNCLOSE ) {
if ( --n <= 0 )
break; }
1229 if ( *t == LBRACE ) {
1232 if ( *t == LBRACE ) n++;
1233 else if ( *t == RBRACE ) {
if ( --n <= 0 )
break; }
1238 if ( denom < 0 || ( ( *t == TPOWER || *t == TPOWER1 )
1239 && t[1] == TMINUS ) ) numexp++;
1242 s++;
while ( *s >= 0 ) s++;
1243 if ( denom < 0 || ( ( *s == TPOWER || *s == TPOWER1 )
1244 && s[1] == TMINUS ) ) numexp++;
1249 if ( *t == LPARENTHESIS ) n++;
1250 else if ( *t == RPARENTHESIS ) {
if ( --n <= 0 )
break; }
1254 if ( denom > 0 && ( *t == TPOWER || *t == TPOWER1 ) ) {
1255 if ( ( t[1] == TNUMBER || t[1] == TNUMBER1 ) && t[2] >= 0
1256 && t[3] < 0 )
break;
1259 else if ( denom < 0 && ( *t == TPOWER || *t == TPOWER1 ) ) {
1260 if ( t[1] == TMINUS && ( t[2] == TNUMBER
1261 || t[2] == TNUMBER1 ) && t[3] >= 0
1262 && t[4] < 0 )
break;
1265 else if ( denom < 0 || ( ( *t == TPOWER || *t == TPOWER1 )
1266 && ( t[1] == TMINUS || t[1] == LPARENTHESIS ) ) ) numexp++;
1269 s++; n = *s++;
while ( *s >= 0 ) { n = 128*n + *s++; }
1272 case CSYMBOL:
goto dosymbol;
1273 case CINDEX:
goto doindex;
1274 case CVECTOR:
goto dovector;
1275 case CFUNCTION:
goto dofunction;
1276 case CNUMBER:
goto dosymbol;
1277 default: error = 1;
break;
1282 if ( *s == TVECTOR ) { s++;
while ( *s >= 0 ) s++; }
1283 else if ( *s == TSET ) {
1284 s++; n = *s++;
while ( *s >= 0 ) { n = 128*n + *s++; }
1285 if ( Sets[n].type != CVECTOR ) {
1286 MesPrint(
"&Set in dotproduct is not a set of vectors");
1289 if ( *s == LBRACE ) {
1292 if ( *s == LBRACE ) n++;
1293 else if ( *s == RBRACE ) {
if ( --n <= 0 )
break; }
1299 MesPrint(
"&Set without argument in dotproduct");
1303 else if ( *s == TSETNUM ) {
1304 s++; n = *s++;
while ( *s >= 0 ) { n = 128*n + *s++; }
1305 if ( *s != TVECTOR )
goto nodot;
1306 s++; n = *s++;
while ( *s >= 0 ) { n = 128*n + *s++; }
1307 if ( Sets[n].type != CVECTOR ) {
1308 MesPrint(
"&Set in dotproduct is not a set of vectors");
1313 nodot: MesPrint(
"&Illegal second element in dotproduct");
1315 s++;
while ( *s >= 0 ) s++;
1319 s++;
while ( *s >= 0 ) s++;
1323 if ( error )
return(-1);
1326 MesPrint(
"&Dubious notation with object^power1^power2");
1335 int simp3btoken(SBYTE *s,
int mode)
1337 int error = 0, i, numprot, n, denom, base, inset = 0, dotp, sube = 0;
1338 SBYTE *t, c, *fill, *ff, *ss;
1341 if ( mode == RHSIDE ) {
1342 prot = AC.ProtoType;
1343 numprot = prot[1] - SUBEXPSIZE;
1346 else { prot = 0; numprot = 0; }
1348 while ( *s == TEMPTY ) s++;
1349 while ( *s != TENDOFIT ) {
1350 if ( *s == TEMPTY ) { s++;
continue; }
1352 if ( *s == TDIVIDE ) { denom = -1; *fill++ = *s++; }
1353 ff = fill; ss = s; c = *s;
1354 if ( c == TSETNUM ) {
1355 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1364 while ( *s >= 0 ) *fill++ = *s++;
1365 if ( *s == TWILDCARD ) *fill++ = *s++;
1368 if ( *s != TPOWER )
continue;
1370 if ( *s == TMINUS ) *fill++ = *s++;
1371 if ( *s == TPLUS ) s++;
1372 if ( *s == TSETNUM ) {
1373 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1377 if ( *s == TNUMBER || *s == TNUMBER1 ) {
1378 base = *s == TNUMBER ? 100: 128;
1380 num = *s++; *fill++ = num;
1382 if ( num > MAXPOWER )
break;
1384 num = base*num + *s++;
1386 while ( *s >= 0 ) *fill++ = *s++;
1387 if ( num <= MAXPOWER )
continue;
1390 else if ( *s == TSYMBOL && c != TNUMBER && c != TNUMBER1 ) {
1392 n = 0;
while ( *s >= 0 ) { n = 128*n + *s; *fill++ = *s++; }
1393 if ( *s == TWILDCARD ) { *fill++ = *s++;
1394 if ( *s == TPOWER )
goto doublepower;
1399 if ( mode == RHSIDE && inset == 0 ) {
1401 for ( i = 0; i < numprot; i += 4 ) {
1402 if ( prot[i+2] == n && prot[i] == SYMTOSYM )
break;
1404 if ( i < numprot )
break;
1408 if ( denom < 0 ) fill[-1] = TMULTIPLY;
1409 *fill++ = TFUNCTION; *fill++ = (SBYTE)(AM.expnum); *fill++ = TFUNOPEN;
1410 if ( dotp ) *fill++ = LPARENTHESIS;
1411 while ( ss < t ) *fill++ = *ss++;
1412 if ( dotp ) *fill++ = RPARENTHESIS;
1415 if ( *ss == TMINUS ) { denom = -denom; ss++; }
1417 *fill++ = LPARENTHESIS;
1419 while ( ss < s ) *fill++ = *ss++;
1420 *fill++ = RPARENTHESIS;
1423 while ( ss < s ) *fill++ = *ss++;
1425 *fill++ = TFUNCLOSE;
1426 if ( *ss == TPOWER )
goto doublepower;
1433 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1434 if ( *s == TWILDCARD ) *fill++ = *s++;
1437 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1438 if ( *s == TWILDCARD ) *fill++ = *s++;
1440 if ( *s == TFUNOPEN ) {
1441 while ( *s != TFUNCLOSE ) *fill++ = *s++;
1444 else if ( *s == TDOT )
goto dodot;
1448 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1449 if ( *s == TWILDCARD ) *fill++ = *s++;
1452 if ( *t == TFUNOPEN ) {
1455 if ( *t == TFUNOPEN ) n++;
1456 else if ( *t == TFUNCLOSE ) {
if ( --n <= 0 )
break; }
1459 t++; *fill++ = *s++;
1463 if ( *t == TPOWER || *t == TPOWER1 ) {
1465 if ( ( t[1] == TNUMBER || t[1] == TNUMBER1 )
1467 if ( t[2] >= 0 && t[3] < 0 ) { sube = 0;
break; }
1469 else if ( t[1] == TMINUS && denom < 0 &&
1470 ( t[2] == TNUMBER || t[2] == TNUMBER1 ) ) {
1471 if ( t[2] >= 0 && t[3] < 0 ) { sube = 0;
break; }
1476 *fill++ = TFUNCTION; *fill++ = (SBYTE)(AM.expnum); *fill++ = TFUNOPEN;
1477 *fill++ = LPARENTHESIS;
1478 while ( ss < t ) *fill++ = *ss++;
1480 *fill++ = RPARENTHESIS; *fill++ = TCOMMA;
1481 if ( *t == TMINUS ) { t++; denom = -denom; }
1482 *fill++ = LPARENTHESIS;
1483 if ( denom < 0 ) *fill++ = TMINUS;
1484 if ( *t == LPARENTHESIS ) {
1485 *fill++ = *t++; n = 0;
1487 if ( *t == LPARENTHESIS ) n++;
1488 else if ( *t == RPARENTHESIS ) n--;
1492 else if ( *t == TFUNCTION || *t == TDUBIOUS ) {
1493 *fill++ = *t++;
while ( *t >= 0 ) *fill++ = *t++;
1494 if ( *t == TWILDCARD ) *fill++ = *t++;
1495 if ( *t == TFUNOPEN ) {
1496 *fill++ = *t++; n = 0;
1498 if ( *t == TFUNOPEN ) n++;
1499 else if ( *t == TFUNCLOSE ) n--;
1504 else if ( *t == TSET ) {
1505 *fill++ = *t++; n = 0;
1506 while ( *t >= 0 ) { n = 128*n + *t; *fill++ = *t++; }
1507 if ( *t == LBRACE ) {
1508 if ( n < AM.NumFixedSets || Sets[n].type == CRANGE ) {
1509 MesPrint(
"&This type of usage of sets is not allowed");
1512 *fill++ = *t++; n = 0;
1514 if ( *t == LBRACE ) n++;
1515 else if ( *t == RBRACE ) n--;
1520 else if ( *t == TEXPRESSION ) {
1521 *fill++ = *t++;
while ( *t >= 0 ) *fill++ = *t++;
1522 if ( *t == TFUNOPEN ) {
1523 *fill++ = *t++; n = 0;
1525 if ( *t == TFUNOPEN ) n++;
1526 else if ( *t == TFUNCLOSE ) n--;
1530 if ( *t == LBRACE ) {
1531 *fill++ = *t++; n = 0;
1533 if ( *t == LBRACE ) n++;
1534 else if ( *t == RBRACE ) n--;
1539 else if ( *t == TVECTOR ) {
1540 *fill++ = *t++;
while ( *t >= 0 ) *fill++ = *t++;
1541 if ( *t == TFUNOPEN ) {
1542 *fill++ = *t++; n = 0;
1544 if ( *t == TFUNOPEN ) n++;
1545 else if ( *t == TFUNCLOSE ) n--;
1549 else if ( *t == TDOT ) {
1551 if ( *t == TVECTOR || *t == TDUBIOUS ) {
1552 *fill++ = *t++;
while ( *t >= 0 ) *fill++ = *t++;
1554 else if ( *t == TSET ) {
1555 *fill++ = *t++; num = 0;
1556 while ( *t >= 0 ) { num = 128*num + *t; *fill++ = *t++; }
1557 if ( Sets[num].type != CVECTOR ) {
1558 MesPrint(
"&Illegal set type in dotproduct");
1561 if ( *t == LBRACE ) {
1562 *fill++ = *t++; n = 0;
1564 if ( *t == LBRACE ) n++;
1565 else if ( *t == RBRACE ) n--;
1570 else if ( *t == TSETNUM ) {
1572 while ( *t >= 0 ) { *fill++ = *t++; }
1574 while ( *t >= 0 ) { *fill++ = *t++; }
1578 MesPrint(
"&Illegal second element in dotproduct");
1583 *fill++ = *t++;
while ( *t >= 0 ) *fill++ = *t++;
1584 if ( *t == TWILDCARD ) *fill++ = *t++;
1586 *fill++ = RPARENTHESIS; *fill++ = TFUNCLOSE;
1587 if ( *t == TPOWER )
goto doublepower;
1588 while ( fill > ff ) *--t = *--fill;
1591 else if ( denom < 0 ) {
1592 fill = ff; ff[-1] = TMULTIPLY;
1593 *fill++ = TFUNCTION; *fill++ = (SBYTE)(AM.denomnum);
1594 *fill++ = TFUNOPEN; *fill++ = LPARENTHESIS;
1595 while ( ss < t ) *fill++ = *ss++;
1596 *fill++ = RPARENTHESIS; *fill++ = TFUNCLOSE;
1597 while ( fill > ff ) *--t = *--fill;
1598 s = t; denom = 1; sube = 0;
1604 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1606 if ( *t == TFUNOPEN ) {
1609 if ( *t == TFUNOPEN ) n++;
1610 else if ( *t == TFUNCLOSE ) {
if ( --n <= 0 )
break; }
1615 if ( *t == LBRACE ) {
1618 if ( *t == LBRACE ) n++;
1619 else if ( *t == RBRACE ) {
if ( --n <= 0 )
break; }
1624 if ( t > s || denom < 0 || ( ( *t == TPOWER || *t == TPOWER1 )
1625 && t[1] == TMINUS ) )
goto dofunpower;
1628 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1631 *fill++ = *s++; n = 1; t = s;
1633 if ( *t == LPARENTHESIS ) n++;
1634 else if ( *t == RPARENTHESIS ) {
if ( --n <= 0 )
break; }
1640 *fill++ = *s++; n = *s++; *fill++ = (SBYTE)n;
1641 while ( *s >= 0 ) { *fill++ = *s; n = 128*n + *s++; }
1644 case CSYMBOL:
goto dosymbol;
1646 case CVECTOR:
goto dovector;
1647 case CFUNCTION:
goto dofunction;
1648 case CNUMBER:
goto dosymbol;
1649 default: error = 1;
break;
1653 dodot: *fill++ = *s++;
1654 if ( *s == TVECTOR ) {
1655 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1657 else if ( *s == TSET ) {
1658 *fill++ = *s++; n = *s++; *fill++ = (SBYTE)n;
1659 while ( *s >= 0 ) { *fill++ = *s; n = 128*n + *s++; }
1660 if ( *s == LBRACE ) {
1661 if ( n < AM.NumFixedSets || Sets[n].type == CRANGE ) {
1662 MesPrint(
"&This type of usage of sets is not allowed");
1665 *fill++ = *s++; n = 1;
1667 if ( *s == LBRACE ) n++;
1668 else if ( *s == RBRACE ) {
if ( --n <= 0 )
break; }
1674 MesPrint(
"&Set without argument in dotproduct");
1678 else if ( *s == TSETNUM ) {
1679 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1680 if ( *s != TVECTOR )
goto nodot;
1681 *fill++ = *s++;
while ( *s >= 0 ) *fill++ = *s++;
1684 nodot: MesPrint(
"&Illegal second element in dotproduct");
1687 while ( *s >= 0 ) *fill++ = *s++;
1693 while ( *s >= 0 ) *fill++ = *s++;
1700 MesPrint(
"&Dubious notation with power of power");
1711 int simp4token(SBYTE *s)
1713 int error = 0, n, nsym, settype;
1714 WORD i, *w, *wstop, level;
1715 SBYTE *fill = s, *s1, *s2, *s3, type, s1buf[10];
1716 SBYTE *tbuf = s, *t, *t1;
1718 while ( *s != TENDOFIT ) {
1720 if ( *s == TEMPTY ) s++;
1721 else *fill++ = *s++;
1724 if ( fill[-1] == TWILDCARD ) { *fill++ = *s++;
continue; }
1725 if ( fill[-1] == TNOT && fill[-2] == TWILDCARD ) { *fill++ = *s++;
continue; }
1726 s1 = s++; n = 0;
while ( *s >= 0 ) { n = 128*n + *s++; }
1728 if ( *s != LBRACE ) {
while ( s1 < s ) *fill++ = *s1++;
continue; }
1729 if ( n < AM.NumFixedSets || i == CRANGE ) {
1730 MesPrint(
"&It is not allowed to refer to individual elements of built in or ranged sets");
1734 if ( *s != TSYMBOL && *s != TDOLLAR ) {
1735 MesPrint(
"&Set index in RHS is not a wildcard symbol or $-variable");
1737 while ( s1 < s ) *fill++ = *s1++;
continue;
1739 settype = ( *s == TDOLLAR );
1740 s++; nsym = 0; s2 = s;
1741 while ( *s >= 0 ) nsym = 128*nsym + *s++;
1742 if ( *s != RBRACE ) {
1743 MesPrint(
"&Improper set argument in RHS");
1745 while ( s1 < s ) *fill++ = *s1++;
continue;
1752 w = AC.ProtoType; wstop = w + w[1]; w += SUBEXPSIZE;
1753 while ( w < wstop ) {
1754 if ( *w == SYMTOSYM && w[2] == nsym )
break;
1762 while ( t >= tbuf ) {
1763 if ( *t == TFUNCLOSE ) {
1765 while ( t >= tbuf ) {
1766 if ( *t == TFUNCLOSE ) level++;
1767 else if ( *t == TFUNOPEN ) {
1769 if ( level == 0 )
break;
1774 else if ( *t == RBRACE ) {
1776 while ( t >= tbuf ) {
1777 if ( *t == RBRACE ) level++;
1778 else if ( *t == LBRACE ) {
1780 if ( level == 0 )
break;
1785 else if ( *t == RPARENTHESIS ) {
1787 while ( t >= tbuf ) {
1788 if ( *t == RPARENTHESIS ) level++;
1789 else if ( *t == LPARENTHESIS ) {
1791 if ( level == 0 )
break;
1796 else if ( *t == TFUNOPEN ) {
1798 while ( *t1 > 0 && t1 > tbuf ) t1--;
1799 if ( *t1 == TFUNCTION ) {
1801 while ( *t1 > 0 ) level = level*128+*t1++;
1802 if ( level == (SUMF1-FUNCTION)
1803 || level == (SUMF2-FUNCTION) ) {
1805 if ( *t1 == LPARENTHESIS ) t1++;
1806 if ( *t1 == TSYMBOL ) {
1807 if ( ( t1[1] == COEFFSYMBOL
1808 || t1[1] == NUMERATORSYMBOL
1809 || t1[1] == DENOMINATORSYMBOL )
1813 while ( *t1 >= 0 && t1 < fill ) level = 128*level + *t1++;
1814 if ( level == nsym && t1 < fill ) {
1815 if ( t[1] == LPARENTHESIS
1816 && *t1 == RPARENTHESIS && t1[1] == TCOMMA )
break;
1817 if ( t[1] != LPARENTHESIS && *t1 == TCOMMA )
break;
1828 MesPrint(
"&Set index in RHS is not a wildcard symbol");
1830 while ( s1 < s ) *fill++ = *s1++;
continue;
1838 case CSYMBOL: type = TSYMBOL;
break;
1839 case CINDEX: type = TINDEX;
break;
1840 case CVECTOR: type = TVECTOR;
break;
1841 case CFUNCTION: type = TFUNCTION;
break;
1842 case CNUMBER: type = TNUMBER1;
break;
1843 case CDUBIOUS: type = TDUBIOUS;
break;
1845 MesPrint(
"&Unknown set type in simp4token");
1846 error = 1; type = CDUBIOUS;
break;
1849 while ( *s1 >= 0 ) *s3++ = *s1++;
1850 *s3 = -1; s1 = s1buf;
1851 if ( settype ) *fill++ = TSETDOL;
1852 else *fill++ = TSETNUM;
1853 while ( *s2 >= 0 ) *fill++ = *s2++;
1854 *fill++ = type;
while ( *s1 >= 0 ) *fill++ = *s1++;
1867 int simp5token(SBYTE *s,
int mode)
1869 int error = 0, n, type;
1871 if ( mode == RHSIDE ) {
1872 while ( *s != TENDOFIT ) {
1873 if ( *s == TFUNCTION ) {
1874 s++; n = 0;
while ( *s >= 0 ) n = 128*n + *s++;
1875 if ( n == AM.sumnum || n == AM.sumpnum ) {
1876 if ( *s != TFUNOPEN )
continue;
1878 if ( *s != TSYMBOL && *s != TINDEX )
continue;
1880 n = 0;
while ( *s >= 0 ) n = 128*n + *s++;
1881 if ( type == TINDEX ) n += AM.OffsetIndex;
1882 if ( *s != TCOMMA )
continue;
1886 while ( w < wstop ) {
1888 if ( ( type == TSYMBOL && ( w[0] == SYMTOSYM
1889 || w[0] == SYMTONUM || w[0] == SYMTOSUB ) ) || (
1890 type == TINDEX && ( w[0] == INDTOIND
1891 || w[0] == INDTOSUB ) ) ) {
1893 MesPrint(
"&Parameter of sum function is already a wildcard");
1913 int simp6token(SBYTE *tokens,
int mode)
1917 int level = 0, haveone = 0;
1918 SBYTE *s = tokens, *ss;
1922 if ( mode == RHSIDE ) {
1923 while ( *s == TPLUS || *s == TMINUS ) s++;
1925 while ( *s != TENDOFIT ) {
1926 if ( *s == LPARENTHESIS ) level++;
1927 else if ( *s == RPARENTHESIS ) level--;
1928 else if ( *s == TFUNOPEN ) level++;
1929 else if ( *s == TFUNCLOSE ) level--;
1930 else if ( ( *s == TPLUS || *s == TMINUS ) && level == 0 ) {
1934 if ( s[-1] != TPOWER && s[-1] != TPLUS && s[-1] != TMINUS ) {
1938 else if ( *s == TEXPRESSION ) {
1940 s++; n = 0;
while ( *s >= 0 ) n = 128*n + *s++;
1942 if ( Expressions[n].status == STOREDEXPRESSION ) {
1951 WORD TMproto[SUBEXPSIZE];
1952 TMproto[0] = EXPRESSION;
1953 TMproto[1] = SUBEXPSIZE;
1956 {
int ie;
for ( ie = 4; ie < SUBEXPSIZE; ie++ ) TMproto[ie] = 0; }
1957 AT.TMaddr = TMproto;
1966 if ( ( renumber = GetTable(n,&position,0) ) == 0 )
1969 MesPrint(
"&Problems getting information about stored expression %s(4)" 1975 if ( renumber->
symb.
lo != AN.dummyrenumlist )
1976 M_free(renumber->
symb.
lo,
"VarSpace");
1977 M_free(renumber,
"Renumber");
1983 if ( ( ( AS.Oldvflags[n] & ISFACTORIZED ) != 0 ) && *s != LBRACE ) {
1987 else if ( error == 0 ) {
1988 if ( ss[-1] != TFUNOPEN || funnum != NUMFACTORS-FUNCTION ) {
1989 MesPrint(
"&Illegal use of factorized expression(s) in RHS");
1996 else if ( *s == TFUNCTION ) {
1997 s++; funnum = 0;
while ( *s >= 0 ) funnum = 128*funnum + *s++;
2003 if ( numterms > 1 ) {
2004 MesPrint(
"&Factorized expression in RHS in an expression of more than one term.");
2007 else if ( AC.ToBeInFactors == 0 ) {
2008 MesPrint(
"&Attempt to put a factorized expression inside an unfactorized expression.");