2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2007 - INRIA - Allan CORNET
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
17 #include "stack-def.h"
20 #include "do_error_number.h"
21 #include "parserConstant.h"
23 /*--------------------------------------------------------------------------*/
25 static int checkvalue = 4095;
28 /*--------------------------------------------------------------------------*/
29 extern int C2F(compil)(int *, int *, int *, int *, int *);
30 extern int C2F(getsym)(void);
31 extern int C2F(istrue)(int *);
32 extern int C2F(eptover)(int *, int *);
33 /*--------------------------------------------------------------------------*/
36 static int eye[6] = { 672014862, 673720360, 673720360, 673720360, 673720360, 673720360 };
38 int r = 0 , s = 0, ir = 0, op = 0, ls = 0, sign = 0;
42 if (C2F(iop).ddt == 4)
46 sprintf(tmp, " expr pt:%d rstk(pt):%d sym:%d", C2F(recu).pt, C2F(recu).rstk[C2F(recu).pt - 1], C2F(com).sym);
47 C2F(basout)(&io, &C2F(iop).wte, tmp, (long)strlen(tmp));
50 r = C2F(recu).rstk[C2F(recu).pt - 1];
98 if (C2F(com).sym >= ou && C2F(com).sym <= great)
105 if (C2F(com).sym == not)
110 if (C2F(com).sym == colon)
112 C2F(putid)(C2F(com).syn, eye);
118 if (C2F(com).sym == minus)
123 if (C2F(com).sym == plus || C2F(com).sym == minus)
134 if (C2F(eptover)(&inc, &checkvalue))
139 C2F(recu).pstk[C2F(recu).pt - 1] = sign + (kount << 8);
140 C2F(recu).rstk[C2F(recu).pt - 1] = 101;
145 sign = C2F(recu).pstk[C2F(recu).pt - 1] % 256;
146 kount = C2F(recu).pstk[C2F(recu).pt - 1] / 256;
155 C2F(recu).pstk[C2F(recu).pt - 1] = kount;
157 C2F(recu).rstk[C2F(recu).pt - 1] = 102;
159 /* *call* allops(minus) */
162 kount = C2F(recu).pstk[C2F(recu).pt - 1];
165 if (C2F(com).sym == plus || C2F(com).sym == minus)
169 if (C2F(recu).rstk[C2F(recu).pt - 1] == 113)
173 if (C2F(recu).rstk[C2F(recu).pt - 1] == 112)
177 if (C2F(com).sym == eol)
181 if (C2F(com).sym >= ou || C2F(com).sym == equal)
187 if (C2F(recu).rstk[C2F(recu).pt - 1] != 301)
191 /* blank or tab is delimiter inside angle brackets */
192 ls = C2F(iop).lpt[2] - 2;
193 if ( (i = C2F(iop).lin[ls - 1], abs(i)) == blank && (j = C2F(iop).lin[C2F(iop).lpt[2] - 1], abs(j)) != blank)
201 /* next lines added to handle sequence of + and - operators, S. Steer */
202 /* 03/2005 (Matlab compatibility). Here i implemented a lazy way */
203 /* without calling unary + or unary - operator */
205 if (C2F(com).sym == plus)
211 if (C2F(com).sym == minus)
227 C2F(recu).pstk[C2F(recu).pt - 1] = op + (kount << 8);
228 if (C2F(com).sym != not)
233 C2F(recu).rstk[C2F(recu).pt - 1] = 115;
241 C2F(recu).rstk[C2F(recu).pt - 1] = 103;
246 op = C2F(recu).pstk[C2F(recu).pt - 1] % 256;
247 kount = C2F(recu).pstk[C2F(recu).pt - 1] / 256;
249 C2F(recu).pstk[C2F(recu).pt - 1] = kount;
250 C2F(recu).rstk[C2F(recu).pt - 1] = 104;
253 /* *call* allops(op) */
256 kount = C2F(recu).pstk[C2F(recu).pt - 1];
260 if (C2F(com).sym != colon)
283 C2F(recu).rstk[C2F(recu).pt - 1] = 105;
286 /* *call* allops(colon) */
290 r = C2F(recu).rstk[C2F(recu).pt - 1];
331 if (C2F(iop).ddt == 4) {}
333 if (C2F(eptover)(&inc, &checkvalue))
337 C2F(recu).ids[C2F(recu).pt * 6 - 6] = 0;
338 C2F(recu).ids[C2F(recu).pt * 6 - 5] = C2F(errgst).err1;
339 if (C2F(com).sym == ou)
342 C2F(recu).pstk[C2F(recu).pt - 1] = ou;
345 /* checking for possible logical 'if expression' */
346 /* evaluation shortcircuit */
347 if (C2F(com).comp[0] != 0)
349 if (C2F(compil)(&code, &inc, &val, &val, &val))
355 C2F(recu).ids[C2F(recu).pt * 6 - 6] = C2F(com).comp[0];
360 temp = (i = *istk(iadr(C2F(vstk).lstk[Top - 1])), abs(i));
361 if ( (temp != 8) && (C2F(istrue)(&val)) )
363 /* first term is true there is no use to evaluate the other */
364 C2F(recu).ids[C2F(recu).pt * 6 - 6] = 1;
365 /* err1 <>0 sets interpretation without evaluation */
366 /* use special value to be able to distinguish from */
367 /* recovered errors */
368 C2F(errgst).err1 = 9191919;
375 C2F(recu).pstk[C2F(recu).pt - 1] = 0;
377 C2F(recu).pstk[C2F(recu).pt - 1] += kount << 8;
378 C2F(recu).rstk[C2F(recu).pt - 1] = 106;
382 op = C2F(recu).pstk[C2F(recu).pt - 1] % 256;
383 kount = C2F(recu).pstk[C2F(recu).pt - 1] / 256;
390 if (C2F(com).comp[0] == 0 && C2F(recu).ids[(C2F(recu).pt + 1) * 6 - 6] == 1)
392 /* term has not been evaluated */
393 if ((i = -C2F(errgst).errct, abs(i)) / 100000 == 0)
395 C2F(errgst).err1 = C2F(recu).ids[(C2F(recu).pt + 1) * 6 - 5];
397 else if (C2F(recu).ids[(C2F(recu).pt + 1) * 6 - 5] != 0)
399 C2F(errgst).err1 = C2F(recu).ids[(C2F(recu).pt + 1) * 6 - 5];
403 if (C2F(errgst).err1 == 9191919)
405 C2F(errgst).err1 = 0;
408 if (C2F(errgst).err1 > 0)
418 C2F(recu).rstk[C2F(recu).pt - 1] = 107;
419 C2F(recu).pstk[C2F(recu).pt - 1] = kount;
420 /* *call* allops(ou) */
423 kount = C2F(recu).pstk[C2F(recu).pt - 1];
424 if (C2F(com).comp[0] != 0 && C2F(recu).ids[C2F(recu).pt * 6 - 6] != 0)
426 i = C2F(recu).ids[C2F(recu).pt * 6 - 6] - 1;
427 if ( (C2F(compil)(&code, &val, &i, &val, &val)) && (Err > 0) )
434 if (C2F(com).sym == ou)
441 if (C2F(iop).ddt == 4) { }
443 if (C2F(eptover)(&inc, &checkvalue))
448 C2F(recu).ids[C2F(recu).pt * 6 - 6] = 0;
449 C2F(recu).ids[C2F(recu).pt * 6 - 5] = C2F(errgst).err1;
450 if (C2F(com).sym == et)
452 C2F(recu).pstk[C2F(recu).pt - 1] = et;
453 C2F(recu).ids[C2F(recu).pt * 6 - 6] = 0;
456 /* if expression evaluation, checking for possible */
457 /* logical expression evaluation shortcircuit */
458 if (C2F(com).comp[0] != 0)
460 if (C2F(compil)(&code, &val, &val, &val, &val))
466 C2F(recu).ids[C2F(recu).pt * 6 - 6] = C2F(com).comp[0];
471 temp = (i = *istk(iadr(C2F(vstk).lstk[Top - 1])), abs(i));
472 if ( (temp != 8) && (! C2F(istrue)(&val)) )
474 /* first term is false there is no use to evaluate the other */
475 C2F(recu).ids[C2F(recu).pt * 6 - 6] = 1;
476 /* err1 <>0 sets interpretation without evaluation */
477 C2F(errgst).err1 = 9191919;
484 C2F(recu).pstk[C2F(recu).pt - 1] = 0;
486 C2F(recu).pstk[C2F(recu).pt - 1] += kount << 8;
487 C2F(recu).rstk[C2F(recu).pt - 1] = 108;
491 op = C2F(recu).pstk[C2F(recu).pt - 1] % 256;
492 kount = C2F(recu).pstk[C2F(recu).pt - 1] / 256;
499 if (C2F(com).comp[0] == 0 && C2F(recu).ids[(C2F(recu).pt + 1) * 6 - 6] == 1)
501 /* term has not been evaluated */
502 if ((i = -C2F(errgst).errct, abs(i)) / 100000 == 0)
504 C2F(errgst).err1 = C2F(recu).ids[(C2F(recu).pt + 1) * 6 - 5];
506 else if (C2F(recu).ids[(C2F(recu).pt + 1) * 6 - 5] != 0)
508 /* error detected before if expression evaluation (should not occur ?) */
509 C2F(errgst).err1 = C2F(recu).ids[(C2F(recu).pt + 1) * 6 - 5];
513 if (C2F(errgst).err1 == 9191919)
515 C2F(errgst).err1 = 0;
518 if (C2F(errgst).err1 > 0)
528 C2F(recu).pstk[C2F(recu).pt - 1] = kount;
529 C2F(recu).rstk[C2F(recu).pt - 1] = 109;
530 /* *call* allops(et) */
533 kount = C2F(recu).pstk[C2F(recu).pt - 1];
534 if (C2F(com).comp[0] != 0 && C2F(recu).ids[C2F(recu).pt * 6 - 6] != 0)
536 i = C2F(recu).ids[C2F(recu).pt * 6 - 6] - 1;
537 if ( (C2F(compil)(&code, &val, &i, &val, &val)) && (Err > 0) )
544 if (C2F(com).sym != et)
552 if (C2F(iop).ddt == 4) { }
553 if (C2F(eptover)(&inc, &checkvalue))
558 C2F(recu).pstk[C2F(recu).pt - 1] = 0;
559 if (C2F(com).sym == not && C2F(com).char1 != equal)
561 C2F(recu).pstk[C2F(recu).pt - 1] = not;
564 C2F(recu).pstk[C2F(recu).pt - 1] += kount << 8;
565 C2F(recu).rstk[C2F(recu).pt - 1] = 110;
569 op = C2F(recu).pstk[C2F(recu).pt - 1] % 256;
570 kount = C2F(recu).pstk[C2F(recu).pt - 1] / 256;
579 C2F(recu).pstk[C2F(recu).pt - 1] = kount;
580 C2F(recu).rstk[C2F(recu).pt - 1] = 111;
582 /* *call* allops(not) */
586 /* next two lines to handle a+~b and a*~b,... */
587 if (C2F(recu).rstk[C2F(recu).pt - 1] == 115)
591 if (C2F(recu).rstk[C2F(recu).pt - 1] == 204)
598 if (C2F(iop).ddt == 4) { }
599 if (C2F(recu).pstk[C2F(recu).pt - 1] % 256 != 0)
603 if (C2F(com).sym != et && C2F(com).sym != ou)
609 if (C2F(eptover)(&val, &checkvalue))
615 C2F(recu).rstk[C2F(recu).pt - 1] = 112;
621 if ((C2F(com).sym != equal && C2F(com).sym < less) || C2F(com).sym == eol)
628 if (op == equal && C2F(com).sym != equal)
630 if (C2F(com).sym == great || C2F(com).sym == less)
635 int code_message = 7;
636 C2F(msgs)(&code_message, &val);
639 if (C2F(com).sym == equal || C2F(com).sym == great)
646 if (op == not + equal)
652 C2F(recu).rstk[C2F(recu).pt - 1] = 113;
653 C2F(recu).pstk[C2F(recu).pt - 1] = op;
658 Fin = C2F(recu).pstk[C2F(recu).pt - 1];
660 C2F(recu).rstk[C2F(recu).pt - 1] = 114;
662 /* *call* allops(fin) */
665 /*--------------------------------------------------------------------------*/