source: git/Singular/grammar.y @ 2e553a

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