source: git/Singular/grammar.y @ ae7cad0

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