source: git/Singular/grammar.y @ 50cbdc

fieker-DuValspielwiese
Last change on this file since 50cbdc was 50cbdc, checked in by Hans Schönemann <hannes@…>, 23 years ago
*hannes: merge-2-0-2 git-svn-id: file:///usr/local/Singular/svn/trunk@5619 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 44.7 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: grammar.y,v 1.92 2001-08-27 14:47:01 Singular Exp $ */
5/*
6* ABSTRACT: SINGULAR shell grammatik
7*/
8%{
9
10#include <stdio.h>
11#include <stddef.h>
12#include <stdlib.h>
13#include <stdarg.h>
14#include <string.h>
15#ifdef __MWERKS__
16  #ifdef __POWERPC__
17    #include <alloca.h>
18  #else
19    #ifdef macintosh
20      #define alloca malloc /* this is not corect! */
21    #else
22      #include <malloc.h>
23    #endif
24  #endif
25#endif
26
27#include "mod2.h"
28#include <mylimits.h>
29#include "omalloc.h"
30#include "tok.h"
31#include "stype.h"
32#include "ipid.h"
33#include "intvec.h"
34#include "febase.h"
35#include "matpol.h"
36#include "ring.h"
37#include "kstd1.h"
38#include "subexpr.h"
39#include "ipshell.h"
40#include "ipconv.h"
41#include "sdb.h"
42#include "ideals.h"
43#include "numbers.h"
44#include "polys.h"
45#include "weight.h"
46#include "stairc.h"
47#include "timer.h"
48#include "cntrlc.h"
49#include "maps.h"
50#include "syz.h"
51#include "lists.h"
52#include "libparse.h"
53
54/* From the bison docu:
55
56     By defining the macro `YYMAXDEPTH', you can control how deep the
57parser stack can become before a stack overflow occurs.  Define the
58macro with a value that is an integer.  This value is the maximum number
59of tokens that can be shifted (and not reduced) before overflow.  It
60must be a constant expression whose value is known at compile time.
61
62   The stack space allowed is not necessarily allocated.  If you
63specify a large value for `YYMAXDEPTH', the parser actually allocates a
64small stack at first, and then makes it bigger by stages as needed.
65This increasing allocation happens automatically and silently.
66Therefore, you do not need to make `YYMAXDEPTH' painfully small merely
67to save space for ordinary inputs that do not need much stack.
68
69   The default value of `YYMAXDEPTH', if you do not define it, is 10000.
70*/
71#define YYMAXDEPTH INT_MAX
72
73extern int   yylineno;
74extern FILE* yyin;
75
76char       my_yylinebuf[80];
77char *     currid;
78BOOLEAN    yyInRingConstruction=FALSE;
79BOOLEAN    expected_parms;
80int        cmdtok;
81int        inerror = 0;
82
83#define TESTSETINT(a,i)                                \
84   if ((a).Typ() != INT_CMD)                           \
85   {                                                   \
86     WerrorS("no int expression");                     \
87     YYERROR;                                          \
88   }                                                   \
89   (i) = (int)(a).Data();
90
91#define MYYERROR(a) { WerrorS(a); YYERROR; }
92
93void yyerror(char * fmt)
94{
95
96  BOOLEAN old_errorreported=errorreported;
97  errorreported = TRUE;
98  if (currid!=NULL)
99  {
100    killid(currid,&IDROOT);
101    currid = NULL;
102  }
103  if(inerror==0)
104  {
105    #ifdef HAVE_TCL
106    if (tclmode)
107    { /* omit output of line number if tclmode and stdin */
108      const char *n=VoiceName();
109      if (strcmp(n,"STDIN")==0)
110        Werror( "error occurred in %s: `%s`"
111               ,n, my_yylinebuf);
112      else
113        Werror( "error occurred in %s line %d: `%s`"
114               ,n, yylineno, my_yylinebuf);
115    }
116    else
117    #endif
118    {
119      if ((strlen(fmt)>1) && (strncmp(fmt,"parse",5)!=0))
120        WerrorS(fmt);
121      Werror( "error occurred in %s line %d: `%s`"
122             ,VoiceName(), yylineno, my_yylinebuf);
123    }
124    if (cmdtok!=0)
125    {
126      char *s=Tok2Cmdname(cmdtok);
127      if (expected_parms)
128      {
129        Werror("expected %s-expression. type \'help %s;\'",s,s);
130      }
131      else
132      {
133        Werror("wrong type declaration. type \'help %s;\'",s);
134      }
135    }
136    if (!old_errorreported && (lastreserved!=NULL))
137    {
138      Werror("last reserved name was `%s`",lastreserved);
139    }
140    inerror=1;
141  }
142  if ((currentVoice!=NULL)
143  && (currentVoice->prev!=NULL)
144  && (myynest>0)
145#ifdef HAVE_SDB
146  && ((sdb_flags &1)==0)
147#endif
148  )
149  {
150    Werror("leaving %s",VoiceName());
151  }
152}
153
154%}
155
156/* %expect 22 */
157%pure_parser
158
159/* special symbols */
160%token DOTDOT
161%token EQUAL_EQUAL
162%token GE
163%token LE
164%token MINUSMINUS
165%token NOT
166%token NOTEQUAL
167%token PLUSPLUS
168%token COLONCOLON
169
170/* types, part 1 (ring indep.)*/
171%token <i> DRING_CMD
172%token <i> INTMAT_CMD
173%token <i> PROC_CMD
174%token <i> RING_CMD
175
176/* valid when ring defined ! */
177%token <i> BEGIN_RING
178/* types, part 2 */
179%token <i> IDEAL_CMD
180%token <i> MAP_CMD
181%token <i> MATRIX_CMD
182%token <i> MODUL_CMD
183%token <i> NUMBER_CMD
184%token <i> POLY_CMD
185%token <i> RESOLUTION_CMD
186%token <i> VECTOR_CMD
187/* end types */
188
189/* ring dependent cmd:*/
190%token <i> BETTI_CMD
191%token <i> COEFFS_CMD
192%token <i> COEF_CMD
193%token <i> CONTRACT_CMD
194%token <i> DEGREE_CMD
195%token <i> DEG_CMD
196%token <i> DIFF_CMD
197%token <i> DIM_CMD
198%token <i> DIVISION_CMD
199%token <i> ELIMINATION_CMD
200%token <i> E_CMD
201%token <i> FETCH_CMD
202%token <i> FREEMODULE_CMD
203%token <i> KEEPRING_CMD
204%token <i> HILBERT_CMD
205%token <i> HOMOG_CMD
206%token <i> IMAP_CMD
207%token <i> INDEPSET_CMD
208%token <i> INTERRED_CMD
209%token <i> INTERSECT_CMD
210%token <i> JACOB_CMD
211%token <i> JET_CMD
212%token <i> KBASE_CMD
213%token <i> KOSZUL_CMD
214%token <i> LEADCOEF_CMD
215%token <i> LEADEXP_CMD
216%token <i> LEAD_CMD
217%token <i> LEADMONOM_CMD
218%token <i> LIFTSTD_CMD
219%token <i> LIFT_CMD
220%token <i> MAXID_CMD
221%token <i> MINBASE_CMD
222%token <i> MINOR_CMD
223%token <i> MINRES_CMD
224%token <i> MODULO_CMD
225%token <i> MRES_CMD
226%token <i> MULTIPLICITY_CMD
227%token <i> ORD_CMD
228%token <i> PAR_CMD
229%token <i> PARDEG_CMD
230%token <i> PREIMAGE_CMD
231%token <i> QUOTIENT_CMD
232%token <i> QHWEIGHT_CMD
233%token <i> REDUCE_CMD
234%token <i> REGULARITY_CMD
235%token <i> RES_CMD
236%token <i> SIMPLIFY_CMD
237%token <i> SORTVEC_CMD
238%token <i> SRES_CMD
239%token <i> STD_CMD
240%token <i> SUBST_CMD
241%token <i> SYZYGY_CMD
242%token <i> VAR_CMD
243%token <i> VDIM_CMD
244%token <i> WEDGE_CMD
245%token <i> WEIGHT_CMD
246
247/*system variables in ring block*/
248%token <i> VALTVARS
249%token <i> VMAXDEG
250%token <i> VMAXMULT
251%token <i> VNOETHER
252%token <i> VMINPOLY
253
254%token <i> END_RING
255/* end of ring definitions */
256
257%token <i> CMD_1
258%token <i> CMD_2
259%token <i> CMD_3
260%token <i> CMD_12
261%token <i> CMD_13
262%token <i> CMD_23
263%token <i> CMD_123
264%token <i> CMD_M
265%token <i> ROOT_DECL
266        /* put variables of this type into the idroot list */
267%token <i> ROOT_DECL_LIST
268        /* put variables of this type into the idroot list */
269%token <i> RING_DECL
270        /* put variables of this type into the currRing list */
271%token <i> EXAMPLE_CMD
272%token <i> EXPORT_CMD
273%token <i> EXPORTTO_CMD
274%token <i> IMPORTFROM_CMD
275%token <i> HELP_CMD
276%token <i> KILL_CMD
277%token <i> LIB_CMD
278%token <i> LISTVAR_CMD
279%token <i> SETRING_CMD
280%token <i> TYPE_CMD
281
282%token <name> STRINGTOK BLOCKTOK INT_CONST
283%token <name> UNKNOWN_IDENT RINGVAR PROC_DEF
284
285/* control */
286%token <i> BREAK_CMD
287%token <i> CONTINUE_CMD
288%token <i> ELSE_CMD
289%token <i> EVAL
290%token <i> QUOTE
291%token <i> FOR_CMD
292%token <i> IF_CMD
293%token <i> SYS_BREAK
294%token <i> WHILE_CMD
295%token <i> RETURN
296%token <i> PARAMETER
297
298/* system variables */
299%token <i> SYSVAR
300
301%type <name> extendedid
302%type <lv>   rlist ordering OrderingList orderelem
303%type <name> stringexpr
304%type <lv>   expr elemexpr exprlist expr_arithmetic
305%type <lv>   declare_ip_variable left_value
306%type <i>    ordername
307%type <i>    cmdeq
308%type <i>    currring_lists
309%type <i>    setrings
310%type <i>    ringcmd1
311
312%type <i>    '=' '<' '>' '+' '-' COLONCOLON
313%type <i>    '/' '[' ']' '^' ',' ';'
314
315
316/*%nonassoc '=' PLUSEQUAL DOTDOT*/
317/*%nonassoc '=' DOTDOT COLONCOLON*/
318%nonassoc '=' DOTDOT
319%left ','
320%left '&'
321%left EQUAL_EQUAL NOTEQUAL
322%left '<'
323%left '+' '-'
324%left '/'
325%left UMINUS NOT
326%left  '^'
327%left '[' ']'
328%left '(' ')'
329%left PLUSPLUS MINUSMINUS
330%left COLONCOLON
331
332%%
333lines:
334        /**/
335        | lines pprompt
336          {
337            if (timerv)
338            {
339              writeTime("used time:");
340              startTimer();
341            }
342            #ifdef HAVE_RTIMER
343            if (rtimerv)
344            {
345              writeRTime("used real time:");
346              startRTimer();
347            }
348            #endif
349            prompt_char = '>';
350#ifdef HAVE_SDB
351            if (sdb_flags & 2) { sdb_flags=1; YYERROR; }
352#endif
353            if(siCntrlc)
354            {
355              siCntrlc=FALSE;
356              MYYERROR("abort...");
357            }
358            if (errorreported)
359            {
360              yyerror("");
361            }
362            if (inerror==2) PrintLn();
363            errorreported = inerror = cmdtok = 0;
364            lastreserved = currid = NULL;
365            expected_parms = siCntrlc = FALSE;
366          }
367        ;
368
369pprompt:
370        flowctrl                       /* if, while, for, proc */
371        | command ';'                  /* commands returning no value */
372          {currentVoice->ifsw=0;}
373        | declare_ip_variable ';'      /* default initialization */
374          { $1.CleanUp(); currentVoice->ifsw=0;}
375        | returncmd
376          {
377            YYACCEPT;
378          }
379        | SYS_BREAK
380          {
381            currentVoice->ifsw=0;
382            iiDebug();
383          }
384        | ';'                    /* ignore empty statements */
385          {currentVoice->ifsw=0;}
386        | error ';'
387          {
388            #ifdef SIQ
389            siq=0;
390            #endif
391            yyInRingConstruction = FALSE;
392            currentVoice->ifsw=0;
393            if (inerror)
394            {
395              if ((inerror!=3) && ($1.i<UMINUS) && ($1.i>' '))
396              {
397                // 1: yyerror called
398                // 2: scanner put actual string
399                // 3: error rule put token+\n
400                inerror=3;
401                Print(" error at token `%s`\n",iiTwoOps($1.i));
402              }
403            }
404            if (!errorreported) WerrorS("...parse error");
405            yyerror("");
406            yyerrok;
407#ifdef HAVE_SDB
408            if ((sdb_flags & 1) && currentVoice->pi!=NULL)
409            {
410              currentVoice->pi->trace_flag |=1;
411            }
412            else
413#endif
414            if (myynest>0)
415            {
416              feBufferTypes t=currentVoice->Typ();
417              //PrintS("leaving yyparse\n");
418              exitBuffer(BT_proc);
419              if (t==BT_example)
420                YYACCEPT;
421              else
422                YYABORT;
423            }
424            else if (currentVoice->prev!=NULL)
425            {
426              exitVoice();
427            }
428#ifdef HAVE_SDB
429            if (sdb_flags &2) sdb_flags=1;
430#endif
431          }
432        ;
433
434flowctrl: ifcmd
435          | whilecmd
436          | example_dummy
437          | forcmd
438          | proccmd
439          | filecmd
440          | helpcmd
441          | examplecmd
442            {currentVoice->ifsw=0;}
443        ;
444
445example_dummy : EXAMPLE_CMD BLOCKTOK { omFree((ADDRESS)$2); }
446
447command: assign
448         | exportcmd
449         | killcmd
450         | listcmd
451         | parametercmd
452         | ringcmd
453         | scriptcmd
454         | setringcmd
455         | typecmd
456         ;
457
458assign: left_value exprlist
459          {
460            if(iiAssign(&$1,&$2)) YYERROR;
461          }
462        ;
463
464elemexpr:
465        RINGVAR
466          {
467            if (currRing==NULL) MYYERROR("no ring active");
468            syMake(&$$,omStrDup($1));
469          }
470        | extendedid
471          {
472            syMake(&$$,$1);
473          }
474        | elemexpr COLONCOLON elemexpr
475          {
476            if(iiExprArith2(&$$, &$1, COLONCOLON, &$3)) YYERROR;
477          }
478        | elemexpr '('  ')'
479          {
480            if(iiExprArith1(&$$,&$1,'(')) YYERROR;
481          }
482        | elemexpr '(' exprlist ')'
483          {
484            if ($1.rtyp==LIB_CMD)
485            {
486              if(iiExprArith1(&$$,&$3,LIB_CMD)) YYERROR;
487            }
488            else
489            {
490              $1.next=(leftv)omAllocBin(sleftv_bin);
491              memcpy($1.next,&$3,sizeof(sleftv));
492              if(iiExprArithM(&$$,&$1,'(')) YYERROR;
493            }
494          }
495        | '[' exprlist ']'
496          {
497            if (currRingHdl==NULL) MYYERROR("no ring active");
498            int j = 0;
499            memset(&$$,0,sizeof(sleftv));
500            $$.rtyp=VECTOR_CMD;
501            leftv v = &$2;
502            while (v!=NULL)
503            {
504              int i,t;
505              sleftv tmp;
506              memset(&tmp,0,sizeof(tmp));
507              i=iiTestConvert((t=v->Typ()),POLY_CMD);
508              if((i==0) || (iiConvert(t /*v->Typ()*/,POLY_CMD,i,v,&tmp)))
509              {
510                pDelete((poly *)&$$.data);
511                $2.CleanUp();
512                MYYERROR("expected '[poly,...'");
513              }
514              poly p = (poly)tmp.CopyD(POLY_CMD);
515              pSetCompP(p,++j);
516              $$.data = (void *)pAdd((poly)$$.data,p);
517              v->next=tmp.next;tmp.next=NULL;
518              tmp.CleanUp();
519              v=v->next;
520            }
521            $2.CleanUp();
522          }
523        | INT_CONST
524          {
525            memset(&$$,0,sizeof($$));
526            int i = atoi($1);
527            /*remember not to omFree($1)
528            *because it is a part of the scanner buffer*/
529            $$.rtyp  = INT_CMD;
530            $$.data = (void *)i;
531
532            /* check: out of range input */
533            int l = strlen($1)+2;
534            if (l >= MAX_INT_LEN)
535            {
536              char tmp[MAX_INT_LEN+5];
537              sprintf(tmp,"%d",i);
538              if (strcmp(tmp,$1)!=0)
539              {
540                if (currRing==NULL)
541                {
542                  Werror("`%s` greater than %d(max. integer representation)"
543                         ,$1,MAX_INT_VAL);
544                  YYERROR;
545                }
546                char *t1=omStrDup($1);
547                syMake(&$$,t1);
548              }
549            }
550          }
551        | SYSVAR
552          {
553            memset(&$$,0,sizeof($$));
554            $$.rtyp = $1;
555            $$.data = $$.Data();
556          }
557        | stringexpr
558          {
559            memset(&$$,0,sizeof($$));
560            $$.rtyp  = STRING_CMD;
561            $$.data = $1;
562          }
563        ;
564
565exprlist:
566        expr ',' exprlist
567          {
568            leftv v = &$1;
569            while (v->next!=NULL)
570            {
571              v=v->next;
572            }
573            v->next = (leftv)omAllocBin(sleftv_bin);
574            memcpy(v->next,&($3),sizeof(sleftv));
575            $$ = $1;
576          }
577        | expr
578          {
579            $$ = $1;
580          }
581        ;
582
583expr:   expr_arithmetic
584          {
585            /*if ($1.typ == eunknown) YYERROR;*/
586            $$ = $1;
587          }
588        | elemexpr       { $$ = $1; }
589        | '(' exprlist ')'    { $$ = $2; }
590        | expr '[' expr ',' expr ']'
591          {
592            if(iiExprArith3(&$$,'[',&$1,&$3,&$5)) YYERROR;
593          }
594        | expr '[' expr ']'
595          {
596            if(iiExprArith2(&$$,&$1,'[',&$3)) YYERROR;
597          }
598        | ROOT_DECL '(' expr ')'
599          {
600            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
601          }
602        | ROOT_DECL_LIST '(' exprlist ')'
603          {
604            if(iiExprArithM(&$$,&$3,$1)) YYERROR;
605          }
606        | ROOT_DECL_LIST '(' ')'
607          {
608            if(iiExprArithM(&$$,NULL,$1)) YYERROR;
609          }
610        | RING_DECL '(' expr ')'
611          {
612            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
613          }
614        | currring_lists '(' exprlist ')'
615          {
616            if(iiExprArithM(&$$,&$3,$1)) YYERROR;
617          }
618        | currring_lists '(' ')'
619          {
620            if(iiExprArithM(&$$,NULL,$1)) YYERROR;
621          }
622        | CMD_1 '(' expr ')'
623          {
624            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
625          }
626        | CMD_2 '(' expr ',' expr ')'
627          {
628            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
629          }
630        | CMD_3 '(' expr ',' expr ',' expr ')'
631          {
632            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
633          }
634        | CMD_23 '(' expr ',' expr ')'
635          {
636            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
637          }
638        | CMD_23 '(' expr ',' expr ',' expr ')'
639          {
640            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
641          }
642        | CMD_12 '(' expr ')'
643          {
644            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
645          }
646        | CMD_13 '(' expr ')'
647          {
648            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
649          }
650        | CMD_12 '(' expr ',' expr ')'
651          {
652            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
653          }
654        | CMD_123 '(' expr ')'
655          {
656            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
657          }
658        | CMD_123 '(' expr ',' expr ')'
659          {
660            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
661          }
662        | CMD_13 '(' expr ',' expr ',' expr ')'
663          {
664            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
665          }
666        | CMD_123 '(' expr ',' expr ',' expr ')'
667          {
668            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
669          }
670        | CMD_M '(' ')'
671          {
672            if(iiExprArithM(&$$,NULL,$1)) YYERROR;
673          }
674        | CMD_M '(' exprlist ')'
675          {
676            if(iiExprArithM(&$$,&$3,$1)) YYERROR;
677          }
678        | MATRIX_CMD '(' expr ',' expr ',' expr ')'
679          {
680            if(iiExprArith3(&$$,MATRIX_CMD,&$3,&$5,&$7)) YYERROR;
681          }
682        | MATRIX_CMD '(' expr ')'
683          {
684            if(iiExprArith1(&$$,&$3,MATRIX_CMD)) YYERROR;
685          }
686        | INTMAT_CMD '(' expr ',' expr ',' expr ')'
687          {
688            if(iiExprArith3(&$$,INTMAT_CMD,&$3,&$5,&$7)) YYERROR;
689          }
690        | INTMAT_CMD '(' expr ')'
691          {
692            if(iiExprArith1(&$$,&$3,INTMAT_CMD)) YYERROR;
693          }
694        | RING_CMD '(' rlist ',' rlist ',' ordering ')'
695          {
696            if(iiExprArith3(&$$,RING_CMD,&$3,&$5,&$7)) YYERROR;
697          }
698        | RING_CMD '(' expr ')'
699          {
700            if(iiExprArith1(&$$,&$3,RING_CMD)) YYERROR;
701          }
702        | quote_start expr quote_end
703          {
704            $$=$2;
705          }
706        | quote_start expr '=' expr quote_end
707          {
708            #ifdef SIQ
709            siq++;
710            if (siq>0)
711            { if (iiExprArith2(&$$,&$2,'=',&$4)) YYERROR; }
712            else
713            #endif
714            {
715              memset(&$$,0,sizeof($$));
716              $$.rtyp=NONE;
717              if (iiAssign(&$2,&$4)) YYERROR;
718            }
719            #ifdef SIQ
720            siq--;
721            #endif
722          }
723        | EVAL  '('
724          {
725            #ifdef SIQ
726            siq--;
727            #endif
728          }
729          expr ')'
730          {
731            #ifdef SIQ
732            if (siq<=0) $4.Eval();
733            #endif
734            $$=$4;
735            #ifdef SIQ
736            siq++;
737            #endif
738          }
739          ;
740
741quote_start:    QUOTE  '('
742          {
743            #ifdef SIQ
744            siq++;
745            #endif
746          }
747          ;
748
749quote_end: ')'
750          {
751            #ifdef SIQ
752            siq--;
753            #endif
754          }
755          ;
756
757expr_arithmetic:
758          expr PLUSPLUS     %prec PLUSPLUS
759          {
760            if(iiExprArith1(&$$,&$1,PLUSPLUS)) YYERROR;
761          }
762        | expr MINUSMINUS   %prec MINUSMINUS
763          {
764            if(iiExprArith1(&$$,&$1,MINUSMINUS)) YYERROR;
765          }
766        | expr '+' expr
767          {
768            if(iiExprArith2(&$$,&$1,'+',&$3)) YYERROR;
769          }
770        | expr '-' expr
771          {
772            if(iiExprArith2(&$$,&$1,'-',&$3)) YYERROR;
773          }
774        | expr '/' expr
775          {
776            if(iiExprArith2(&$$,&$1,$<i>2,&$3)) YYERROR;
777          }
778        | expr '^' expr
779          {
780            if(iiExprArith2(&$$,&$1,'^',&$3)) YYERROR;
781          }
782        | expr '<' expr
783          {
784            if(iiExprArith2(&$$,&$1,$<i>2,&$3)) YYERROR;
785          }
786        | expr '&' expr
787          {
788            if(iiExprArith2(&$$,&$1,$<i>2,&$3)) YYERROR;
789          }
790        | expr NOTEQUAL expr
791          {
792            if(iiExprArith2(&$$,&$1,NOTEQUAL,&$3)) YYERROR;
793          }
794        | expr EQUAL_EQUAL expr
795          {
796            if(iiExprArith2(&$$,&$1,EQUAL_EQUAL,&$3)) YYERROR;
797          }
798        | expr DOTDOT expr
799          {
800            if(iiExprArith2(&$$,&$1,DOTDOT,&$3)) YYERROR;
801          }
802        | NOT expr
803          {
804            memset(&$$,0,sizeof($$));
805            int i; TESTSETINT($2,i);
806            $$.rtyp  = INT_CMD;
807            $$.data = (void *)(i == 0 ? 1 : 0);
808          }
809        | '-' expr %prec UMINUS
810          {
811            if(iiExprArith1(&$$,&$2,'-')) YYERROR;
812          }
813        ;
814
815left_value:
816        declare_ip_variable cmdeq  { $$ = $1; }
817        | exprlist '='
818          {
819            if ($1.rtyp==0)
820            {
821              Werror("`%s` is undefined",$1.Fullname());
822              YYERROR;
823            }
824            $$ = $1;
825          }
826        ;
827
828
829extendedid:
830        UNKNOWN_IDENT
831        | '`' expr '`'
832          {
833            if ($2.Typ()!=STRING_CMD)
834            {
835              MYYERROR("string expression expected");
836            }
837            $$ = (char *)$2.CopyD(STRING_CMD);
838            $2.CleanUp();
839          }
840        ;
841
842currring_lists:
843        IDEAL_CMD | MODUL_CMD
844        /* put variables into the current ring */
845        ;
846
847declare_ip_variable:
848        ROOT_DECL elemexpr
849          {
850            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
851          }
852        | ROOT_DECL_LIST elemexpr
853          {
854            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
855          }
856        | RING_DECL elemexpr
857          {
858            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
859          }
860        | currring_lists elemexpr
861          {
862            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
863          }
864        | MATRIX_CMD elemexpr '[' expr ']' '[' expr ']'
865          {
866            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
867            int r; TESTSETINT($4,r);
868            int c; TESTSETINT($7,c);
869            if (r < 1)
870              MYYERROR("rows must be greater than 0");
871            if (c < 0)
872              MYYERROR("cols must be greater than -1");
873            leftv v=&$$;
874            //while (v->next!=NULL) { v=v->next; }
875            idhdl h=(idhdl)v->data;
876            idDelete(&IDIDEAL(h));
877            IDMATRIX(h) = mpNew(r,c);
878            if (IDMATRIX(h)==NULL) YYERROR;
879          }
880        | MATRIX_CMD elemexpr
881          {
882            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
883          }
884        | INTMAT_CMD elemexpr '[' expr ']' '[' expr ']'
885          {
886            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
887            int r; TESTSETINT($4,r);
888            int c; TESTSETINT($7,c);
889            if (r < 1)
890              MYYERROR("rows must be greater than 0");
891            if (c < 0)
892              MYYERROR("cols must be greater than -1");
893            leftv v=&$$;
894            //while (v->next!=NULL) { v=v->next; }
895            idhdl h=(idhdl)v->data;
896            delete IDINTVEC(h);
897            IDINTVEC(h) = new intvec(r,c,0);
898            if (IDINTVEC(h)==NULL) YYERROR;
899          }
900        | INTMAT_CMD elemexpr
901          {
902            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
903            leftv v=&$$;
904            idhdl h;
905            do
906            {
907               h=(idhdl)v->data;
908               delete IDINTVEC(h);
909               IDINTVEC(h) = new intvec(1,1,0);
910               v=v->next;
911            } while (v!=NULL);
912          }
913        | declare_ip_variable ',' elemexpr
914          {
915            int t=$1.Typ();
916            sleftv r;
917            memset(&r,0,sizeof(sleftv));
918            if ((BEGIN_RING<t) && (t<END_RING))
919            {
920              if (iiDeclCommand(&r,&$3,myynest,t,&(currRing->idroot), TRUE)) YYERROR;
921            }
922            else
923            {
924              if (iiDeclCommand(&r,&$3,myynest,t,&IDROOT)) YYERROR;
925            }
926            leftv v=&$1;
927            while (v->next!=NULL) v=v->next;
928            v->next=(leftv)omAllocBin(sleftv_bin);
929            memcpy(v->next,&r,sizeof(sleftv));
930            $$=$1;
931          }
932        | PROC_CMD elemexpr
933          {
934            if (iiDeclCommand(&$$,&$2,myynest,PROC_CMD,&IDROOT, FALSE, TRUE)) YYERROR;
935          }
936        ;
937
938stringexpr:
939        STRINGTOK
940        ;
941
942rlist:
943        expr
944        | '(' expr ',' exprlist ')'
945          {
946            leftv v = &$2;
947            while (v->next!=NULL)
948            {
949              v=v->next;
950            }
951            v->next = (leftv)omAllocBin(sleftv_bin);
952            memcpy(v->next,&($4),sizeof(sleftv));
953            $$ = $2;
954          }
955        ;
956
957ordername:
958        UNKNOWN_IDENT
959        {
960          // let rInit take care of any errors
961          $$=rOrderName($1);
962        }
963        ;
964
965orderelem:
966        ordername
967          {
968            memset(&$$,0,sizeof($$));
969            intvec *iv = new intvec(2);
970            (*iv)[0] = 1;
971            (*iv)[1] = $1;
972            $$.rtyp = INTVEC_CMD;
973            $$.data = (void *)iv;
974          }
975        | ordername '(' exprlist ')'
976          {
977            memset(&$$,0,sizeof($$));
978            leftv sl = &$3;
979            int slLength;
980            {
981              slLength =  exprlist_length(sl);
982              int l = 2 +  slLength;
983              intvec *iv = new intvec(l);
984              (*iv)[0] = slLength;
985              (*iv)[1] = $1;
986
987              int i = 2;
988              while ((i<l) && (sl!=NULL))
989              {
990                if (sl->Typ() == INT_CMD)
991                {
992                  (*iv)[i++] = (int)(sl->Data());
993                }
994                else if ((sl->Typ() == INTVEC_CMD)
995                ||(sl->Typ() == INTMAT_CMD))
996                {
997                  intvec *ivv = (intvec *)(sl->Data());
998                  int ll = 0,l = ivv->length();
999                  for (; l>0; l--)
1000                  {
1001                    (*iv)[i++] = (*ivv)[ll++];
1002                  }
1003                }
1004                else
1005                {
1006                  delete iv;
1007                  $3.CleanUp();
1008                  MYYERROR("wrong type in ordering");
1009                }
1010                sl = sl->next;
1011              }
1012              $$.rtyp = INTVEC_CMD;
1013              $$.data = (void *)iv;
1014            }
1015            $3.CleanUp();
1016          }
1017        ;
1018
1019OrderingList:
1020        orderelem
1021        |  orderelem ',' OrderingList
1022          {
1023            $$ = $1;
1024            $$.next = (sleftv *)omAllocBin(sleftv_bin);
1025            memcpy($$.next,&$3,sizeof(sleftv));
1026          }
1027        ;
1028
1029ordering:
1030        orderelem
1031        | '(' OrderingList ')'
1032          {
1033            $$ = $2;
1034          }
1035        ;
1036
1037cmdeq:  '='
1038          {
1039            expected_parms = TRUE;
1040          }
1041        ;
1042
1043
1044/* --------------------------------------------------------------------*/
1045/* section of pure commands                                            */
1046/* --------------------------------------------------------------------*/
1047
1048filecmd:
1049        '<' stringexpr
1050          { if ($<i>1 != '<') YYERROR;
1051            if((feFilePending=feFopen($2,"r",NULL,TRUE))==NULL) YYERROR; }
1052        ';'
1053          { newFile($2,feFilePending); }
1054        ;
1055
1056helpcmd:
1057        HELP_CMD STRINGTOK ';'
1058          {
1059            feHelp($2);
1060            omFree((ADDRESS)$2);
1061          }
1062        | HELP_CMD ';'
1063          {
1064            feHelp(NULL);
1065          }
1066        ;
1067
1068examplecmd:
1069        EXAMPLE_CMD STRINGTOK ';'
1070          {
1071            singular_example($2);
1072            omFree((ADDRESS)$2);
1073          }
1074       ;
1075
1076exportcmd:
1077        EXPORT_CMD exprlist
1078        {
1079#ifdef HAVE_NAMESPACES
1080          if (iiExport(&$2,0,namespaceroot->get("Top",0,TRUE))) YYERROR;
1081#else /* HAVE_NAMESPACES */
1082          if (iiExport(&$2,0)) YYERROR;
1083#endif /* HAVE_NAMESPACES */
1084            }
1085        | EXPORT_CMD exprlist extendedid expr
1086        {
1087          if ((strcmp($3,"to")!=0) ||
1088          (($4.Typ()!=PACKAGE_CMD) && ($4.Typ()!=INT_CMD) &&
1089           ($4.Typ()!=STRING_CMD)))
1090            MYYERROR("export <id> to <package|int>");
1091          omFree((ADDRESS)$3);
1092          if ($4.Typ()==INT_CMD)
1093          {
1094            if (iiExport(&$2,((int)$4.Data())-1)) YYERROR;
1095          }
1096          else
1097          {
1098#ifdef HAVE_NAMESPACES
1099            if (($4.Typ()==PACKAGE_CMD)
1100            && (iiExport(&$2,0,(idhdl)$4.data)))
1101              YYERROR;
1102#else
1103            printf("String: %s;\n", (char *)$4.data);
1104#endif /* HAVE_NAMESPACES */
1105          }
1106        }
1107        ;
1108
1109killcmd:
1110        KILL_CMD exprlist
1111        {
1112          leftv v=&$2;
1113          do
1114          {
1115            if (v->rtyp!=IDHDL)
1116            {
1117              if (v->name!=NULL) Werror("`%s` is undefined in kill",v->name);
1118              else               WerrorS("kill what ?");
1119            }
1120            else
1121            {
1122            #ifdef HAVE_NAMESPACES
1123              if (v->packhdl != NULL)
1124              {
1125                namespaceroot->push( IDPACKAGE(v->packhdl) , IDID(v->packhdl));
1126                killhdl((idhdl)v->data);
1127                namespaceroot->pop();
1128              }
1129              else
1130              #endif /* HAVE_NAMESPACES */
1131                killhdl((idhdl)v->data);
1132            }
1133            v=v->next;
1134          } while (v!=NULL);
1135          $2.CleanUp();
1136        }
1137        ;
1138
1139listcmd:
1140        LISTVAR_CMD '(' ROOT_DECL ')'
1141          {
1142            list_cmd($3,NULL,"// ",TRUE);
1143          }
1144        | LISTVAR_CMD '(' ROOT_DECL_LIST ')'
1145          {
1146            list_cmd($3,NULL,"// ",TRUE);
1147          }
1148        | LISTVAR_CMD '(' RING_DECL ')'
1149          {
1150            if ($3==QRING_CMD) $3=RING_CMD;
1151            list_cmd($3,NULL,"// ",TRUE);
1152          }
1153        | LISTVAR_CMD '(' currring_lists ')'
1154          {
1155            list_cmd($3,NULL,"// ",TRUE);
1156          }
1157        | LISTVAR_CMD '(' RING_CMD ')'
1158          {
1159            list_cmd(RING_CMD,NULL,"// ",TRUE);
1160          }
1161        | LISTVAR_CMD '(' MATRIX_CMD ')'
1162          {
1163            list_cmd(MATRIX_CMD,NULL,"// ",TRUE);
1164           }
1165        | LISTVAR_CMD '(' INTMAT_CMD ')'
1166          {
1167            list_cmd(INTMAT_CMD,NULL,"// ",TRUE);
1168          }
1169        | LISTVAR_CMD '(' PROC_CMD ')'
1170          {
1171            list_cmd(PROC_CMD,NULL,"// ",TRUE);
1172          }
1173        | LISTVAR_CMD '(' elemexpr ')'
1174          {
1175#ifdef HAVE_NAMESPACES
1176            if($3.Typ() == PACKAGE_CMD) {
1177              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1178                                   ((sleftv)$3).name);
1179              list_cmd(-2,NULL,"// ",TRUE);
1180              namespaceroot->pop();
1181            }
1182            else
1183#endif /* HAVE_NAMESPACES */
1184              list_cmd(0,$3.Fullname(),"// ",TRUE);
1185            $3.CleanUp();
1186          }
1187        | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL ')'
1188          {
1189#ifdef HAVE_NAMESPACES
1190            if($3.Typ() == PACKAGE_CMD) {
1191              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1192                                   ((sleftv)$3).name);
1193              list_cmd($5,NULL,"// ",TRUE);
1194              namespaceroot->pop();
1195            }
1196#endif /* HAVE_NAMESPACES */
1197            $3.CleanUp();
1198          }
1199        | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL_LIST ')'
1200          {
1201#ifdef HAVE_NAMESPACES
1202            if($3.Typ() == PACKAGE_CMD) {
1203              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1204                                   ((sleftv)$3).name);
1205              list_cmd($5,NULL,"// ",TRUE);
1206              namespaceroot->pop();
1207            }
1208#endif /* HAVE_NAMESPACES */
1209            $3.CleanUp();
1210          }
1211        | LISTVAR_CMD '(' elemexpr ',' RING_DECL ')'
1212          {
1213#ifdef HAVE_NAMESPACES
1214            if($3.Typ() == PACKAGE_CMD) {
1215              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1216                                   ((sleftv)$3).name);
1217              if ($5==QRING_CMD) $5=RING_CMD;
1218              list_cmd($5,NULL,"// ",TRUE);
1219              namespaceroot->pop();
1220            }
1221#endif /* HAVE_NAMESPACES */
1222            $3.CleanUp();
1223          }
1224        | LISTVAR_CMD '(' elemexpr ',' currring_lists ')'
1225          {
1226#ifdef HAVE_NAMESPACES
1227            if($3.Typ() == PACKAGE_CMD) {
1228              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1229                                   ((sleftv)$3).name);
1230              list_cmd($5,NULL,"// ",TRUE);
1231              namespaceroot->pop();
1232            }
1233#endif /* HAVE_NAMESPACES */
1234            $3.CleanUp();
1235          }
1236        | LISTVAR_CMD '(' elemexpr ',' RING_CMD ')'
1237          {
1238#ifdef HAVE_NAMESPACES
1239            if($3.Typ() == PACKAGE_CMD) {
1240              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1241                                   ((sleftv)$3).name);
1242              list_cmd(RING_CMD,NULL,"// ",TRUE);
1243              namespaceroot->pop();
1244            }
1245#endif /* HAVE_NAMESPACES */
1246            $3.CleanUp();
1247          }
1248        | LISTVAR_CMD '(' elemexpr ',' MATRIX_CMD ')'
1249          {
1250#ifdef HAVE_NAMESPACES
1251            if($3.Typ() == PACKAGE_CMD) {
1252              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1253                                   ((sleftv)$3).name);
1254              list_cmd(MATRIX_CMD,NULL,"// ",TRUE);
1255              namespaceroot->pop();
1256            }
1257#endif /* HAVE_NAMESPACES */
1258            $3.CleanUp();
1259          }
1260        | LISTVAR_CMD '(' elemexpr ',' INTMAT_CMD ')'
1261          {
1262#ifdef HAVE_NAMESPACES
1263            if($3.Typ() == PACKAGE_CMD) {
1264              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1265                                   ((sleftv)$3).name);
1266              list_cmd(INTMAT_CMD,NULL,"// ",TRUE);
1267              namespaceroot->pop();
1268            }
1269#endif /* HAVE_NAMESPACES */
1270            $3.CleanUp();
1271          }
1272        | LISTVAR_CMD '(' elemexpr ',' PROC_CMD ')'
1273          {
1274#ifdef HAVE_NAMESPACES
1275            if($3.Typ() == PACKAGE_CMD) {
1276              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1277                                   ((sleftv)$3).name);
1278              list_cmd(PROC_CMD,$3.Fullname(),"// ",TRUE);
1279              namespaceroot->pop();
1280            }
1281#endif /* HAVE_NAMESPACES */
1282            $3.CleanUp();
1283          }
1284        | LISTVAR_CMD '(' elemexpr ',' elemexpr ')'
1285          {
1286#ifdef HAVE_NAMESPACES
1287            if($3.Typ() == PACKAGE_CMD) {
1288              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1289                                   ((sleftv)$3).name);
1290              list_cmd(0,$5.Fullname(),"// ",TRUE);
1291              namespaceroot->pop();
1292            }
1293#endif /* HAVE_NAMESPACES */
1294            $3.CleanUp();
1295          }
1296        | LISTVAR_CMD '(' ')'
1297          {
1298            list_cmd(-1,NULL,"// ",TRUE);
1299          }
1300        ;
1301
1302ringcmd1:
1303       RING_CMD { yyInRingConstruction = TRUE; }
1304       ;
1305
1306ringcmd:
1307        ringcmd1
1308          elemexpr cmdeq
1309          rlist     ','      /* description of coeffs */
1310          rlist     ','      /* var names */
1311          ordering           /* list of (multiplier ordering (weight(s))) */
1312          {
1313            BOOLEAN do_pop = FALSE;
1314            char *ring_name = $2.name;
1315            #ifdef HAVE_NAMESPACES
1316              if (((sleftv)$2).req_packhdl != NULL)
1317              {
1318                namespaceroot->push( IDPACKAGE(((sleftv)$2).req_packhdl) , "");
1319                do_pop = TRUE;
1320                if( (((sleftv)$2).req_packhdl != NULL) &&
1321                    (((sleftv)$2).packhdl != ((sleftv)$2).req_packhdl))
1322                  ring_name = omStrDup($2.name);
1323              }
1324            #endif /* HAVE_NAMESPACES */
1325            ring b=
1326            rInit(&$4,            /* characteristik and list of parameters*/
1327                  &$6,            /* names of ringvariables */
1328                  &$8);            /* ordering */
1329            idhdl newRingHdl=NULL;
1330            if (b!=NULL)
1331            {
1332              newRingHdl=enterid(ring_name, myynest, RING_CMD, &IDROOT);
1333              if (newRingHdl!=NULL)
1334              {
1335                omFreeSize(IDRING(newRingHdl),sizeof(ip_sring));
1336                IDRING(newRingHdl)=b;
1337              }
1338              else
1339              {
1340                rKill(b);
1341              }
1342            }
1343            #ifdef HAVE_NAMESPACES
1344              if(do_pop) namespaceroot->pop();
1345            #endif /* HAVE_NAMESPACES */
1346            yyInRingConstruction = FALSE;
1347            if (newRingHdl==NULL)
1348            {
1349              MYYERROR("cannot make ring");
1350            }
1351            else
1352            {
1353              rSetHdl(newRingHdl);
1354            }
1355          }
1356        | ringcmd1 elemexpr
1357          {
1358            BOOLEAN do_pop = FALSE;
1359            char *ring_name = $2.name;
1360            #ifdef HAVE_NAMESPACES
1361              if (((sleftv)$2).req_packhdl != NULL)
1362              {
1363                namespaceroot->push( IDPACKAGE(((sleftv)$2).req_packhdl) , "");
1364                do_pop = TRUE;
1365                if( (((sleftv)$2).req_packhdl != NULL) &&
1366                  (((sleftv)$2).packhdl != ((sleftv)$2).req_packhdl))
1367                  ring_name = omStrDup($2.name);
1368              }
1369            #endif /* HAVE_NAMESPACES */
1370            if (!inerror) rDefault(ring_name);
1371            #ifdef HAVE_NAMESPACES
1372              if(do_pop) namespaceroot->pop();
1373            #endif /* HAVE_NAMESPACES */
1374            yyInRingConstruction = FALSE;
1375          }
1376        ;
1377
1378scriptcmd:
1379         SYSVAR stringexpr
1380          {
1381            if (($1!=LIB_CMD)||(iiLibCmd($2)))
1382            YYERROR;
1383          }
1384        ;
1385
1386setrings:  SETRING_CMD | KEEPRING_CMD ;
1387
1388setringcmd:
1389        setrings expr
1390          {
1391            if (($1==KEEPRING_CMD) && (myynest==0))
1392               MYYERROR("only inside a proc allowed");
1393            const char * n=$2.Name();
1394            if ((($2.Typ()==RING_CMD)||($2.Typ()==QRING_CMD))
1395            && ($2.rtyp==IDHDL))
1396            {
1397              idhdl h=(idhdl)$2.data;
1398              if ($2.e!=NULL) h=rFindHdl((ring)$2.Data(),NULL, NULL);
1399              if ($1==KEEPRING_CMD)
1400              {
1401                if (h!=NULL)
1402                {
1403                  if (IDLEV(h)!=0)
1404                  {
1405#ifdef HAVE_NAMESPACES
1406                    if(namespaceroot->isroot) {
1407                      if (iiExport(&$2,myynest-1)) YYERROR;
1408                    } else {
1409                      if (iiExport(&$2,myynest-1,
1410                        namespaceroot->get(namespaceroot->next->name,0,TRUE)))
1411                        YYERROR;
1412                    }
1413#else /* HAVE_NAMESPACES */
1414                    if (iiExport(&$2,myynest-1)) YYERROR;
1415#endif /* HAVE_NAMESPACES */
1416                    //if (TEST_OPT_KEEPVARS)
1417                    //{
1418                      idhdl p=IDRING(h)->idroot;
1419                      idhdl root=p;
1420                      int prevlev=myynest-1;
1421                      while (p!=NULL)
1422                      {
1423                        if (IDLEV(p)==myynest)
1424                        {
1425                          idhdl old=root->get(IDID(p),prevlev);
1426                          if (old!=NULL)
1427                          {
1428                            if (BVERBOSE(V_REDEFINE))
1429                              Warn("redefining %s",IDID(p));
1430                            killhdl(old,&root);
1431                          }
1432                          IDLEV(p)=prevlev;
1433                        }
1434                        p=IDNEXT(p);
1435                      }
1436                    //}
1437                  }
1438#ifdef USE_IILOCALRING
1439                  iiLocalRing[myynest-1]=IDRING(h);
1440#else
1441                  namespaceroot->next->currRing=IDRING(h);
1442#endif
1443                }
1444                else
1445                {
1446                  Werror("%s is no identifier",n);
1447                  $2.CleanUp();
1448                  YYERROR;
1449                }
1450              }
1451              if (h!=NULL) rSetHdl(h);
1452              else
1453              {
1454                Werror("cannot find the name of the basering %s",n);
1455                $2.CleanUp();
1456                YYERROR;
1457              }
1458              $2.CleanUp();
1459            }
1460            else
1461            {
1462              Werror("%s is no name of a ring/qring",n);
1463              $2.CleanUp();
1464              YYERROR;
1465            }
1466          }
1467        ;
1468
1469typecmd:
1470        TYPE_CMD expr
1471          {
1472            if ($2.rtyp!=IDHDL) MYYERROR("identifier expected");
1473            idhdl h = (idhdl)$2.data;
1474            type_cmd(h);
1475          }
1476        | exprlist
1477          {
1478            //Print("typ is %d, rtyp:%d\n",$1.Typ(),$1.rtyp);
1479            #ifdef SIQ
1480            if ($1.rtyp!=COMMAND)
1481            {
1482            #endif
1483              if ($1.Typ()==UNKNOWN)
1484              {
1485                if ($1.name!=NULL)
1486                {
1487                  Werror("`%s` is undefined",$1.name);
1488                  omFree((ADDRESS)$1.name);
1489                }
1490                YYERROR;
1491              }
1492            #ifdef SIQ
1493            }
1494            #endif
1495            $1.Print(&sLastPrinted);
1496            $1.CleanUp();
1497            if (errorreported) YYERROR;
1498          }
1499        ;
1500
1501/* --------------------------------------------------------------------*/
1502/* section of flow control                                             */
1503/* --------------------------------------------------------------------*/
1504
1505ifcmd: IF_CMD '(' expr ')' BLOCKTOK
1506          {
1507            int i; TESTSETINT($3,i);
1508            if (i!=0)
1509            {
1510              newBuffer( $5, BT_if);
1511            }
1512            else
1513            {
1514              omFree((ADDRESS)$5);
1515              currentVoice->ifsw=1;
1516            }
1517          }
1518        | ELSE_CMD BLOCKTOK
1519          {
1520            if (currentVoice->ifsw==1)
1521            {
1522              currentVoice->ifsw=0;
1523              newBuffer( $2, BT_else);
1524            }
1525            else
1526            {
1527              if (currentVoice->ifsw!=2)
1528              {
1529                Warn("`else` without `if` in level %d",myynest);
1530              }
1531              omFree((ADDRESS)$2);
1532            }
1533            currentVoice->ifsw=0;
1534          }
1535        | IF_CMD '(' expr ')' BREAK_CMD
1536          {
1537            int i; TESTSETINT($3,i);
1538            if (i)
1539            {
1540              if (exitBuffer(BT_break)) YYERROR;
1541            }
1542            currentVoice->ifsw=0;
1543          }
1544        | BREAK_CMD
1545          {
1546            if (exitBuffer(BT_break)) YYERROR;
1547            currentVoice->ifsw=0;
1548          }
1549        | CONTINUE_CMD
1550          {
1551            if (contBuffer(BT_break)) YYERROR;
1552            currentVoice->ifsw=0;
1553          }
1554      ;
1555
1556whilecmd:
1557        WHILE_CMD STRINGTOK BLOCKTOK
1558          {
1559            /* -> if(!$2) break; $3; continue;*/
1560            char * s = (char *)omAlloc( strlen($2) + strlen($3) + 36);
1561            sprintf(s,"whileif (!(%s)) break;\n%scontinue;\n " ,$2,$3);
1562            newBuffer(s,BT_break);
1563            omFree((ADDRESS)$2);
1564            omFree((ADDRESS)$3);
1565          }
1566        ;
1567
1568forcmd:
1569        FOR_CMD STRINGTOK STRINGTOK STRINGTOK BLOCKTOK
1570          {
1571            /* $2 */
1572            /* if (!$3) break; $5; $4; continue; */
1573            char * s = (char *)omAlloc( strlen($3)+strlen($4)+strlen($5)+36);
1574            sprintf(s,"forif (!(%s)) break;\n%s%s;\ncontinue;\n "
1575                   ,$3,$5,$4);
1576            omFree((ADDRESS)$3);
1577            omFree((ADDRESS)$4);
1578            omFree((ADDRESS)$5);
1579            newBuffer(s,BT_break);
1580            s = (char *)omAlloc( strlen($2) + 3);
1581            sprintf(s,"%s;\n",$2);
1582            omFree((ADDRESS)$2);
1583            newBuffer(s,BT_if);
1584          }
1585        ;
1586
1587proccmd:
1588        PROC_CMD extendedid BLOCKTOK
1589          {
1590            procinfov pi;
1591            idhdl h = enterid($2,myynest,PROC_CMD,&IDROOT,TRUE);
1592            if (h==NULL) {omFree((ADDRESS)$3); YYERROR;}
1593            iiInitSingularProcinfo(IDPROC(h),"", $2, 0, 0);
1594            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+31);;
1595            sprintf(IDPROC(h)->data.s.body,"parameter list #;\n%s;return();\n\n",$3);
1596            omFree((ADDRESS)$3);
1597          }
1598        | PROC_DEF STRINGTOK BLOCKTOK
1599          {
1600            idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE);
1601            if (h==NULL)
1602            {
1603              omFree((ADDRESS)$2);
1604              omFree((ADDRESS)$3);
1605              YYERROR;
1606            }
1607            char *args=iiProcArgs($2,FALSE);
1608            omFree((ADDRESS)$2);
1609            procinfov pi;
1610            iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0);
1611            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+strlen(args)+14);;
1612            sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$3);
1613            omFree((ADDRESS)args);
1614            omFree((ADDRESS)$3);
1615          }
1616        | PROC_DEF STRINGTOK STRINGTOK BLOCKTOK
1617          {
1618            omFree((ADDRESS)$3);
1619            idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE);
1620            if (h==NULL)
1621            {
1622              omFree((ADDRESS)$2);
1623              omFree((ADDRESS)$4);
1624              YYERROR;
1625            }
1626            char *args=iiProcArgs($2,FALSE);
1627            omFree((ADDRESS)$2);
1628            procinfov pi;
1629            iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0);
1630            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($4)+strlen(args)+14);;
1631            sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$4);
1632            omFree((ADDRESS)args);
1633            omFree((ADDRESS)$4);
1634          }
1635        ;
1636
1637parametercmd:
1638        PARAMETER declare_ip_variable
1639          {
1640            //Print("par:%s, %d\n",$2.Name(),$2.Typ());
1641            //yylineno--;
1642            if (iiParameter(&$2)) YYERROR;
1643          }
1644        | PARAMETER expr
1645          {
1646            //Print("par:%s, %d\n",$2.Name(),$2.Typ());
1647            sleftv tmp_expr;
1648            //yylineno--;
1649            if ((iiDeclCommand(&tmp_expr,&$2,myynest,DEF_CMD,&IDROOT))
1650            || (iiParameter(&tmp_expr)))
1651              YYERROR;
1652          }
1653        ;
1654
1655returncmd:
1656        RETURN '(' exprlist ')'
1657          {
1658            if(iiRETURNEXPR==NULL) YYERROR;
1659            iiRETURNEXPR[myynest].Copy(&$3);
1660            $3.CleanUp();
1661            if (exitBuffer(BT_proc)) YYERROR;
1662          }
1663        | RETURN '(' ')'
1664          {
1665            if ($1==RETURN)
1666            {
1667              if(iiRETURNEXPR==NULL) YYERROR;
1668              iiRETURNEXPR[myynest].Init();
1669              iiRETURNEXPR[myynest].rtyp=NONE;
1670              if (exitBuffer(BT_proc)) YYERROR;
1671            }
1672          }
1673        ;
Note: See TracBrowser for help on using the repository browser.