source: git/Singular/grammar.y @ a3bc95e

spielwiese
Last change on this file since a3bc95e was a3bc95e, checked in by Hans Schönemann <hannes@…>, 23 years ago
*hannes: namespaces ->ns git-svn-id: file:///usr/local/Singular/svn/trunk@5651 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 45.9 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: grammar.y,v 1.94 2001-10-09 16:36: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            #ifdef HAVE_NS
851            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
852              YYERROR;
853            #else
854            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
855            #endif
856          }
857        | ROOT_DECL_LIST elemexpr
858          {
859            #ifdef HAVE_NS
860            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
861              YYERROR;
862            #else
863            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
864            #endif
865          }
866        | RING_DECL elemexpr
867          {
868            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
869          }
870        | currring_lists elemexpr
871          {
872            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
873          }
874        | MATRIX_CMD elemexpr '[' expr ']' '[' expr ']'
875          {
876            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
877            int r; TESTSETINT($4,r);
878            int c; TESTSETINT($7,c);
879            if (r < 1)
880              MYYERROR("rows must be greater than 0");
881            if (c < 0)
882              MYYERROR("cols must be greater than -1");
883            leftv v=&$$;
884            //while (v->next!=NULL) { v=v->next; }
885            idhdl h=(idhdl)v->data;
886            idDelete(&IDIDEAL(h));
887            IDMATRIX(h) = mpNew(r,c);
888            if (IDMATRIX(h)==NULL) YYERROR;
889          }
890        | MATRIX_CMD elemexpr
891          {
892            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
893          }
894        | INTMAT_CMD elemexpr '[' expr ']' '[' expr ']'
895          {
896            int r; TESTSETINT($4,r);
897            int c; TESTSETINT($7,c);
898            if (r < 1)
899              MYYERROR("rows must be greater than 0");
900            if (c < 0)
901              MYYERROR("cols must be greater than -1");
902            #ifdef HAVE_NS
903            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
904              YYERROR;
905            #else
906            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
907            #endif
908            leftv v=&$$;
909            idhdl h=(idhdl)v->data;
910            delete IDINTVEC(h);
911            IDINTVEC(h) = new intvec(r,c,0);
912            if (IDINTVEC(h)==NULL) YYERROR;
913          }
914        | INTMAT_CMD elemexpr
915          {
916            #ifdef HAVE_NS
917            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
918              YYERROR;
919            #else
920            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
921            #endif
922            leftv v=&$$;
923            idhdl h;
924            do
925            {
926               h=(idhdl)v->data;
927               delete IDINTVEC(h);
928               IDINTVEC(h) = new intvec(1,1,0);
929               v=v->next;
930            } while (v!=NULL);
931          }
932        | declare_ip_variable ',' elemexpr
933          {
934            int t=$1.Typ();
935            sleftv r;
936            memset(&r,0,sizeof(sleftv));
937            if ((BEGIN_RING<t) && (t<END_RING))
938            {
939              if (iiDeclCommand(&r,&$3,myynest,t,&(currRing->idroot), TRUE))
940                YYERROR;
941            }
942            else
943            {
944              #ifdef HAVE_NS
945              if (iiDeclCommand(&r,&$3,myynest,t,&($3.req_packhdl->idroot)))
946                YYERROR;
947              #else
948              if (iiDeclCommand(&r,&$3,myynest,t,&IDROOT)) YYERROR;
949              #endif
950            }
951            leftv v=&$1;
952            while (v->next!=NULL) v=v->next;
953            v->next=(leftv)omAllocBin(sleftv_bin);
954            memcpy(v->next,&r,sizeof(sleftv));
955            $$=$1;
956          }
957        | PROC_CMD elemexpr
958          {
959            #ifdef HAVE_NS
960            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
961              YYERROR;
962            #else
963            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
964            #endif
965          }
966        ;
967
968stringexpr:
969        STRINGTOK
970        ;
971
972rlist:
973        expr
974        | '(' expr ',' exprlist ')'
975          {
976            leftv v = &$2;
977            while (v->next!=NULL)
978            {
979              v=v->next;
980            }
981            v->next = (leftv)omAllocBin(sleftv_bin);
982            memcpy(v->next,&($4),sizeof(sleftv));
983            $$ = $2;
984          }
985        ;
986
987ordername:
988        UNKNOWN_IDENT
989        {
990          // let rInit take care of any errors
991          $$=rOrderName($1);
992        }
993        ;
994
995orderelem:
996        ordername
997          {
998            memset(&$$,0,sizeof($$));
999            intvec *iv = new intvec(2);
1000            (*iv)[0] = 1;
1001            (*iv)[1] = $1;
1002            $$.rtyp = INTVEC_CMD;
1003            $$.data = (void *)iv;
1004          }
1005        | ordername '(' exprlist ')'
1006          {
1007            memset(&$$,0,sizeof($$));
1008            leftv sl = &$3;
1009            int slLength;
1010            {
1011              slLength =  exprlist_length(sl);
1012              int l = 2 +  slLength;
1013              intvec *iv = new intvec(l);
1014              (*iv)[0] = slLength;
1015              (*iv)[1] = $1;
1016
1017              int i = 2;
1018              while ((i<l) && (sl!=NULL))
1019              {
1020                if (sl->Typ() == INT_CMD)
1021                {
1022                  (*iv)[i++] = (int)(sl->Data());
1023                }
1024                else if ((sl->Typ() == INTVEC_CMD)
1025                ||(sl->Typ() == INTMAT_CMD))
1026                {
1027                  intvec *ivv = (intvec *)(sl->Data());
1028                  int ll = 0,l = ivv->length();
1029                  for (; l>0; l--)
1030                  {
1031                    (*iv)[i++] = (*ivv)[ll++];
1032                  }
1033                }
1034                else
1035                {
1036                  delete iv;
1037                  $3.CleanUp();
1038                  MYYERROR("wrong type in ordering");
1039                }
1040                sl = sl->next;
1041              }
1042              $$.rtyp = INTVEC_CMD;
1043              $$.data = (void *)iv;
1044            }
1045            $3.CleanUp();
1046          }
1047        ;
1048
1049OrderingList:
1050        orderelem
1051        |  orderelem ',' OrderingList
1052          {
1053            $$ = $1;
1054            $$.next = (sleftv *)omAllocBin(sleftv_bin);
1055            memcpy($$.next,&$3,sizeof(sleftv));
1056          }
1057        ;
1058
1059ordering:
1060        orderelem
1061        | '(' OrderingList ')'
1062          {
1063            $$ = $2;
1064          }
1065        ;
1066
1067cmdeq:  '='
1068          {
1069            expected_parms = TRUE;
1070          }
1071        ;
1072
1073
1074/* --------------------------------------------------------------------*/
1075/* section of pure commands                                            */
1076/* --------------------------------------------------------------------*/
1077
1078filecmd:
1079        '<' stringexpr
1080          { if ($<i>1 != '<') YYERROR;
1081            if((feFilePending=feFopen($2,"r",NULL,TRUE))==NULL) YYERROR; }
1082        ';'
1083          { newFile($2,feFilePending); }
1084        ;
1085
1086helpcmd:
1087        HELP_CMD STRINGTOK ';'
1088          {
1089            feHelp($2);
1090            omFree((ADDRESS)$2);
1091          }
1092        | HELP_CMD ';'
1093          {
1094            feHelp(NULL);
1095          }
1096        ;
1097
1098examplecmd:
1099        EXAMPLE_CMD STRINGTOK ';'
1100          {
1101            singular_example($2);
1102            omFree((ADDRESS)$2);
1103          }
1104       ;
1105
1106exportcmd:
1107        EXPORT_CMD exprlist
1108        {
1109#ifdef HAVE_NAMESPACES
1110          if (iiExport(&$2,0,namespaceroot->get("Top",0,TRUE))) YYERROR;
1111#else /* HAVE_NAMESPACES */
1112          if (iiExport(&$2,0)) YYERROR;
1113#endif /* HAVE_NAMESPACES */
1114            }
1115        | EXPORT_CMD exprlist extendedid expr
1116        {
1117          if ((strcmp($3,"to")!=0) ||
1118          (($4.Typ()!=PACKAGE_CMD) && ($4.Typ()!=INT_CMD) &&
1119           ($4.Typ()!=STRING_CMD)))
1120            MYYERROR("export <id> to <package|int>");
1121          omFree((ADDRESS)$3);
1122          if ($4.Typ()==INT_CMD)
1123          {
1124            if (iiExport(&$2,((int)$4.Data())-1)) YYERROR;
1125          }
1126          else
1127          {
1128#ifdef HAVE_NAMESPACES
1129            if (($4.Typ()==PACKAGE_CMD)
1130            && (iiExport(&$2,0,(idhdl)$4.data)))
1131              YYERROR;
1132#else
1133#ifdef HAVE_NS
1134#else
1135            Print("%s::%s;\n", (char *)$4.Name(),$2.Name());
1136#endif /* HAVE_NS */
1137#endif /* HAVE_NAMESPACES */
1138          }
1139        }
1140        ;
1141
1142killcmd:
1143        KILL_CMD exprlist
1144        {
1145          leftv v=&$2;
1146          do
1147          {
1148            if (v->rtyp!=IDHDL)
1149            {
1150              if (v->name!=NULL) Werror("`%s` is undefined in kill",v->name);
1151              else               WerrorS("kill what ?");
1152            }
1153            else
1154            {
1155            #ifdef HAVE_NAMESPACES
1156              if (v->packhdl != NULL)
1157              {
1158                namespaceroot->push( IDPACKAGE(v->packhdl) , IDID(v->packhdl));
1159                killhdl((idhdl)v->data);
1160                namespaceroot->pop();
1161              }
1162              else
1163              #endif /* HAVE_NAMESPACES */
1164                killhdl((idhdl)v->data);
1165            }
1166            v=v->next;
1167          } while (v!=NULL);
1168          $2.CleanUp();
1169        }
1170        ;
1171
1172listcmd:
1173        LISTVAR_CMD '(' ROOT_DECL ')'
1174          {
1175            list_cmd($3,NULL,"// ",TRUE);
1176          }
1177        | LISTVAR_CMD '(' ROOT_DECL_LIST ')'
1178          {
1179            list_cmd($3,NULL,"// ",TRUE);
1180          }
1181        | LISTVAR_CMD '(' RING_DECL ')'
1182          {
1183            if ($3==QRING_CMD) $3=RING_CMD;
1184            list_cmd($3,NULL,"// ",TRUE);
1185          }
1186        | LISTVAR_CMD '(' currring_lists ')'
1187          {
1188            list_cmd($3,NULL,"// ",TRUE);
1189          }
1190        | LISTVAR_CMD '(' RING_CMD ')'
1191          {
1192            list_cmd(RING_CMD,NULL,"// ",TRUE);
1193          }
1194        | LISTVAR_CMD '(' MATRIX_CMD ')'
1195          {
1196            list_cmd(MATRIX_CMD,NULL,"// ",TRUE);
1197           }
1198        | LISTVAR_CMD '(' INTMAT_CMD ')'
1199          {
1200            list_cmd(INTMAT_CMD,NULL,"// ",TRUE);
1201          }
1202        | LISTVAR_CMD '(' PROC_CMD ')'
1203          {
1204            list_cmd(PROC_CMD,NULL,"// ",TRUE);
1205          }
1206        | LISTVAR_CMD '(' elemexpr ')'
1207          {
1208#ifdef HAVE_NAMESPACES
1209            if($3.Typ() == PACKAGE_CMD) {
1210              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1211                                   ((sleftv)$3).name);
1212              list_cmd(-2,NULL,"// ",TRUE);
1213              namespaceroot->pop();
1214            }
1215            else
1216#endif /* HAVE_NAMESPACES */
1217              list_cmd(0,$3.Fullname(),"// ",TRUE);
1218            $3.CleanUp();
1219          }
1220        | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL ')'
1221          {
1222#ifdef HAVE_NAMESPACES
1223            if($3.Typ() == PACKAGE_CMD) {
1224              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1225                                   ((sleftv)$3).name);
1226              list_cmd($5,NULL,"// ",TRUE);
1227              namespaceroot->pop();
1228            }
1229#endif /* HAVE_NAMESPACES */
1230            $3.CleanUp();
1231          }
1232        | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL_LIST ')'
1233          {
1234#ifdef HAVE_NAMESPACES
1235            if($3.Typ() == PACKAGE_CMD) {
1236              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1237                                   ((sleftv)$3).name);
1238              list_cmd($5,NULL,"// ",TRUE);
1239              namespaceroot->pop();
1240            }
1241#endif /* HAVE_NAMESPACES */
1242            $3.CleanUp();
1243          }
1244        | LISTVAR_CMD '(' elemexpr ',' RING_DECL ')'
1245          {
1246#ifdef HAVE_NAMESPACES
1247            if($3.Typ() == PACKAGE_CMD) {
1248              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1249                                   ((sleftv)$3).name);
1250              if ($5==QRING_CMD) $5=RING_CMD;
1251              list_cmd($5,NULL,"// ",TRUE);
1252              namespaceroot->pop();
1253            }
1254#endif /* HAVE_NAMESPACES */
1255            $3.CleanUp();
1256          }
1257        | LISTVAR_CMD '(' elemexpr ',' currring_lists ')'
1258          {
1259#ifdef HAVE_NAMESPACES
1260            if($3.Typ() == PACKAGE_CMD) {
1261              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1262                                   ((sleftv)$3).name);
1263              list_cmd($5,NULL,"// ",TRUE);
1264              namespaceroot->pop();
1265            }
1266#endif /* HAVE_NAMESPACES */
1267            $3.CleanUp();
1268          }
1269        | LISTVAR_CMD '(' elemexpr ',' RING_CMD ')'
1270          {
1271#ifdef HAVE_NAMESPACES
1272            if($3.Typ() == PACKAGE_CMD) {
1273              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1274                                   ((sleftv)$3).name);
1275              list_cmd(RING_CMD,NULL,"// ",TRUE);
1276              namespaceroot->pop();
1277            }
1278#endif /* HAVE_NAMESPACES */
1279            $3.CleanUp();
1280          }
1281        | LISTVAR_CMD '(' elemexpr ',' MATRIX_CMD ')'
1282          {
1283#ifdef HAVE_NAMESPACES
1284            if($3.Typ() == PACKAGE_CMD) {
1285              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1286                                   ((sleftv)$3).name);
1287              list_cmd(MATRIX_CMD,NULL,"// ",TRUE);
1288              namespaceroot->pop();
1289            }
1290#endif /* HAVE_NAMESPACES */
1291            $3.CleanUp();
1292          }
1293        | LISTVAR_CMD '(' elemexpr ',' INTMAT_CMD ')'
1294          {
1295#ifdef HAVE_NAMESPACES
1296            if($3.Typ() == PACKAGE_CMD) {
1297              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1298                                   ((sleftv)$3).name);
1299              list_cmd(INTMAT_CMD,NULL,"// ",TRUE);
1300              namespaceroot->pop();
1301            }
1302#endif /* HAVE_NAMESPACES */
1303            $3.CleanUp();
1304          }
1305        | LISTVAR_CMD '(' elemexpr ',' PROC_CMD ')'
1306          {
1307#ifdef HAVE_NAMESPACES
1308            if($3.Typ() == PACKAGE_CMD) {
1309              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1310                                   ((sleftv)$3).name);
1311              list_cmd(PROC_CMD,$3.Fullname(),"// ",TRUE);
1312              namespaceroot->pop();
1313            }
1314#endif /* HAVE_NAMESPACES */
1315            $3.CleanUp();
1316          }
1317        | LISTVAR_CMD '(' elemexpr ',' elemexpr ')'
1318          {
1319#ifdef HAVE_NAMESPACES
1320            if($3.Typ() == PACKAGE_CMD) {
1321              namespaceroot->push( IDPACKAGE((idhdl)$3.data),
1322                                   ((sleftv)$3).name);
1323              list_cmd(0,$5.Fullname(),"// ",TRUE);
1324              namespaceroot->pop();
1325            }
1326#endif /* HAVE_NAMESPACES */
1327            $3.CleanUp();
1328          }
1329        | LISTVAR_CMD '(' ')'
1330          {
1331            list_cmd(-1,NULL,"// ",TRUE);
1332          }
1333        ;
1334
1335ringcmd1:
1336       RING_CMD { yyInRingConstruction = TRUE; }
1337       ;
1338
1339ringcmd:
1340        ringcmd1
1341          elemexpr cmdeq
1342          rlist     ','      /* description of coeffs */
1343          rlist     ','      /* var names */
1344          ordering           /* list of (multiplier ordering (weight(s))) */
1345          {
1346            BOOLEAN do_pop = FALSE;
1347            char *ring_name = $2.name;
1348            #ifdef HAVE_NAMESPACES
1349              if (((sleftv)$2).req_packhdl != NULL)
1350              {
1351                namespaceroot->push( IDPACKAGE(((sleftv)$2).req_packhdl) , "");
1352                do_pop = TRUE;
1353                if( (((sleftv)$2).req_packhdl != NULL) &&
1354                    (((sleftv)$2).packhdl != ((sleftv)$2).req_packhdl))
1355                  ring_name = omStrDup($2.name);
1356              }
1357            #endif /* HAVE_NAMESPACES */
1358            ring b=
1359            rInit(&$4,            /* characteristik and list of parameters*/
1360                  &$6,            /* names of ringvariables */
1361                  &$8);            /* ordering */
1362            idhdl newRingHdl=NULL;
1363            if (b!=NULL)
1364            {
1365              newRingHdl=enterid(ring_name, myynest, RING_CMD, &IDROOT);
1366              if (newRingHdl!=NULL)
1367              {
1368                omFreeSize(IDRING(newRingHdl),sizeof(ip_sring));
1369                IDRING(newRingHdl)=b;
1370              }
1371              else
1372              {
1373                rKill(b);
1374              }
1375            }
1376            #ifdef HAVE_NAMESPACES
1377              if(do_pop) namespaceroot->pop();
1378            #endif /* HAVE_NAMESPACES */
1379            yyInRingConstruction = FALSE;
1380            if (newRingHdl==NULL)
1381            {
1382              MYYERROR("cannot make ring");
1383            }
1384            else
1385            {
1386              rSetHdl(newRingHdl);
1387            }
1388          }
1389        | ringcmd1 elemexpr
1390          {
1391            BOOLEAN do_pop = FALSE;
1392            char *ring_name = $2.name;
1393            #ifdef HAVE_NAMESPACES
1394              if (((sleftv)$2).req_packhdl != NULL)
1395              {
1396                namespaceroot->push( IDPACKAGE(((sleftv)$2).req_packhdl) , "");
1397                do_pop = TRUE;
1398                if( (((sleftv)$2).req_packhdl != NULL) &&
1399                  (((sleftv)$2).packhdl != ((sleftv)$2).req_packhdl))
1400                  ring_name = omStrDup($2.name);
1401              }
1402            #endif /* HAVE_NAMESPACES */
1403            if (!inerror) rDefault(ring_name);
1404            #ifdef HAVE_NAMESPACES
1405              if(do_pop) namespaceroot->pop();
1406            #endif /* HAVE_NAMESPACES */
1407            yyInRingConstruction = FALSE;
1408          }
1409        ;
1410
1411scriptcmd:
1412         SYSVAR stringexpr
1413          {
1414            if (($1!=LIB_CMD)||(iiLibCmd($2)))
1415            YYERROR;
1416          }
1417        ;
1418
1419setrings:  SETRING_CMD | KEEPRING_CMD ;
1420
1421setringcmd:
1422        setrings expr
1423          {
1424            if (($1==KEEPRING_CMD) && (myynest==0))
1425               MYYERROR("only inside a proc allowed");
1426            const char * n=$2.Name();
1427            if ((($2.Typ()==RING_CMD)||($2.Typ()==QRING_CMD))
1428            && ($2.rtyp==IDHDL))
1429            {
1430              idhdl h=(idhdl)$2.data;
1431              if ($2.e!=NULL) h=rFindHdl((ring)$2.Data(),NULL, NULL);
1432              //Print("setring %s lev %d (ptr:%x)\n",IDID(h),IDLEV(h),IDRING(h));
1433              if ($1==KEEPRING_CMD)
1434              {
1435                if (h!=NULL)
1436                {
1437                  if (IDLEV(h)!=0)
1438                  {
1439#ifdef HAVE_NAMESPACES
1440                    if(namespaceroot->isroot) {
1441                      if (iiExport(&$2,myynest-1)) YYERROR;
1442                    } else {
1443                      if (iiExport(&$2,myynest-1,
1444                        namespaceroot->get(namespaceroot->next->name,0,TRUE)))
1445                        YYERROR;
1446                    }
1447#else /* HAVE_NAMESPACES */
1448                    if (iiExport(&$2,myynest-1)) YYERROR;
1449#endif /* HAVE_NAMESPACES */
1450                    //if (TEST_OPT_KEEPVARS)
1451                    //{
1452                      idhdl p=IDRING(h)->idroot;
1453                      idhdl root=p;
1454                      int prevlev=myynest-1;
1455                      while (p!=NULL)
1456                      {
1457                        if (IDLEV(p)==myynest)
1458                        {
1459                          idhdl old=root->get(IDID(p),prevlev);
1460                          if (old!=NULL)
1461                          {
1462                            if (BVERBOSE(V_REDEFINE))
1463                              Warn("redefining %s",IDID(p));
1464                            killhdl2(old,&root);
1465                          }
1466                          IDLEV(p)=prevlev;
1467                        }
1468                        p=IDNEXT(p);
1469                      }
1470                      IDRING(h)->idroot=root;
1471                    //}
1472                  }
1473#ifdef USE_IILOCALRING
1474                  iiLocalRing[myynest-1]=IDRING(h);
1475#endif
1476                  procstack->currRing=IDRING(h);
1477                  procstack->currRingHdl=h;
1478                }
1479                else
1480                {
1481                  Werror("%s is no identifier",n);
1482                  $2.CleanUp();
1483                  YYERROR;
1484                }
1485              }
1486              if (h!=NULL) rSetHdl(h);
1487              else
1488              {
1489                Werror("cannot find the name of the basering %s",n);
1490                $2.CleanUp();
1491                YYERROR;
1492              }
1493              $2.CleanUp();
1494            }
1495            else
1496            {
1497              Werror("%s is no name of a ring/qring",n);
1498              $2.CleanUp();
1499              YYERROR;
1500            }
1501          }
1502        ;
1503
1504typecmd:
1505        TYPE_CMD expr
1506          {
1507            if ($2.rtyp!=IDHDL) MYYERROR("identifier expected");
1508            idhdl h = (idhdl)$2.data;
1509            type_cmd(h);
1510          }
1511        | exprlist
1512          {
1513            //Print("typ is %d, rtyp:%d\n",$1.Typ(),$1.rtyp);
1514            #ifdef SIQ
1515            if ($1.rtyp!=COMMAND)
1516            {
1517            #endif
1518              if ($1.Typ()==UNKNOWN)
1519              {
1520                if ($1.name!=NULL)
1521                {
1522                  Werror("`%s` is undefined",$1.name);
1523                  omFree((ADDRESS)$1.name);
1524                }
1525                YYERROR;
1526              }
1527            #ifdef SIQ
1528            }
1529            #endif
1530            $1.Print(&sLastPrinted);
1531            $1.CleanUp();
1532            if (errorreported) YYERROR;
1533          }
1534        ;
1535
1536/* --------------------------------------------------------------------*/
1537/* section of flow control                                             */
1538/* --------------------------------------------------------------------*/
1539
1540ifcmd: IF_CMD '(' expr ')' BLOCKTOK
1541          {
1542            int i; TESTSETINT($3,i);
1543            if (i!=0)
1544            {
1545              newBuffer( $5, BT_if);
1546            }
1547            else
1548            {
1549              omFree((ADDRESS)$5);
1550              currentVoice->ifsw=1;
1551            }
1552          }
1553        | ELSE_CMD BLOCKTOK
1554          {
1555            if (currentVoice->ifsw==1)
1556            {
1557              currentVoice->ifsw=0;
1558              newBuffer( $2, BT_else);
1559            }
1560            else
1561            {
1562              if (currentVoice->ifsw!=2)
1563              {
1564                Warn("`else` without `if` in level %d",myynest);
1565              }
1566              omFree((ADDRESS)$2);
1567            }
1568            currentVoice->ifsw=0;
1569          }
1570        | IF_CMD '(' expr ')' BREAK_CMD
1571          {
1572            int i; TESTSETINT($3,i);
1573            if (i)
1574            {
1575              if (exitBuffer(BT_break)) YYERROR;
1576            }
1577            currentVoice->ifsw=0;
1578          }
1579        | BREAK_CMD
1580          {
1581            if (exitBuffer(BT_break)) YYERROR;
1582            currentVoice->ifsw=0;
1583          }
1584        | CONTINUE_CMD
1585          {
1586            if (contBuffer(BT_break)) YYERROR;
1587            currentVoice->ifsw=0;
1588          }
1589      ;
1590
1591whilecmd:
1592        WHILE_CMD STRINGTOK BLOCKTOK
1593          {
1594            /* -> if(!$2) break; $3; continue;*/
1595            char * s = (char *)omAlloc( strlen($2) + strlen($3) + 36);
1596            sprintf(s,"whileif (!(%s)) break;\n%scontinue;\n " ,$2,$3);
1597            newBuffer(s,BT_break);
1598            omFree((ADDRESS)$2);
1599            omFree((ADDRESS)$3);
1600          }
1601        ;
1602
1603forcmd:
1604        FOR_CMD STRINGTOK STRINGTOK STRINGTOK BLOCKTOK
1605          {
1606            /* $2 */
1607            /* if (!$3) break; $5; $4; continue; */
1608            char * s = (char *)omAlloc( strlen($3)+strlen($4)+strlen($5)+36);
1609            sprintf(s,"forif (!(%s)) break;\n%s%s;\ncontinue;\n "
1610                   ,$3,$5,$4);
1611            omFree((ADDRESS)$3);
1612            omFree((ADDRESS)$4);
1613            omFree((ADDRESS)$5);
1614            newBuffer(s,BT_break);
1615            s = (char *)omAlloc( strlen($2) + 3);
1616            sprintf(s,"%s;\n",$2);
1617            omFree((ADDRESS)$2);
1618            newBuffer(s,BT_if);
1619          }
1620        ;
1621
1622proccmd:
1623        PROC_CMD extendedid BLOCKTOK
1624          {
1625            procinfov pi;
1626            idhdl h = enterid($2,myynest,PROC_CMD,&IDROOT,TRUE);
1627            if (h==NULL) {omFree((ADDRESS)$3); YYERROR;}
1628            iiInitSingularProcinfo(IDPROC(h),"", $2, 0, 0);
1629            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+31);;
1630            sprintf(IDPROC(h)->data.s.body,"parameter list #;\n%s;return();\n\n",$3);
1631            omFree((ADDRESS)$3);
1632          }
1633        | PROC_DEF STRINGTOK BLOCKTOK
1634          {
1635            idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE);
1636            if (h==NULL)
1637            {
1638              omFree((ADDRESS)$2);
1639              omFree((ADDRESS)$3);
1640              YYERROR;
1641            }
1642            char *args=iiProcArgs($2,FALSE);
1643            omFree((ADDRESS)$2);
1644            procinfov pi;
1645            iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0);
1646            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+strlen(args)+14);;
1647            sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$3);
1648            omFree((ADDRESS)args);
1649            omFree((ADDRESS)$3);
1650          }
1651        | PROC_DEF STRINGTOK STRINGTOK BLOCKTOK
1652          {
1653            omFree((ADDRESS)$3);
1654            idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE);
1655            if (h==NULL)
1656            {
1657              omFree((ADDRESS)$2);
1658              omFree((ADDRESS)$4);
1659              YYERROR;
1660            }
1661            char *args=iiProcArgs($2,FALSE);
1662            omFree((ADDRESS)$2);
1663            procinfov pi;
1664            iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0);
1665            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($4)+strlen(args)+14);;
1666            sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$4);
1667            omFree((ADDRESS)args);
1668            omFree((ADDRESS)$4);
1669          }
1670        ;
1671
1672parametercmd:
1673        PARAMETER declare_ip_variable
1674          {
1675            //Print("par:%s, %d\n",$2.Name(),$2.Typ());
1676            //yylineno--;
1677            if (iiParameter(&$2)) YYERROR;
1678          }
1679        | PARAMETER expr
1680          {
1681            //Print("par:%s, %d\n",$2.Name(),$2.Typ());
1682            sleftv tmp_expr;
1683            //yylineno--;
1684            if ((iiDeclCommand(&tmp_expr,&$2,myynest,DEF_CMD,&IDROOT))
1685            || (iiParameter(&tmp_expr)))
1686              YYERROR;
1687          }
1688        ;
1689
1690returncmd:
1691        RETURN '(' exprlist ')'
1692          {
1693            if(iiRETURNEXPR==NULL) YYERROR;
1694            iiRETURNEXPR[myynest].Copy(&$3);
1695            $3.CleanUp();
1696            if (exitBuffer(BT_proc)) YYERROR;
1697          }
1698        | RETURN '(' ')'
1699          {
1700            if ($1==RETURN)
1701            {
1702              if(iiRETURNEXPR==NULL) YYERROR;
1703              iiRETURNEXPR[myynest].Init();
1704              iiRETURNEXPR[myynest].rtyp=NONE;
1705              if (exitBuffer(BT_proc)) YYERROR;
1706            }
1707          }
1708        ;
Note: See TracBrowser for help on using the repository browser.