source: git/Singular/grammar.y @ d186d3

spielwiese
Last change on this file since d186d3 was 6b5a71, checked in by Hans Schoenemann <hannes@…>, 10 years ago
introduce ASSUME(<level>,<int expr>) Conflicts: Singular/ipshell.h
  • Property mode set to 100644
File size: 42.6 KB
Line 
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
15#ifdef HAVE_CONFIG_H
16#include "singularconfig.h"
17#endif /* HAVE_CONFIG_H */
18#include <misc/auxiliary.h>
19
20#include <kernel/mod2.h>
21#include <misc/mylimits.h>
22#include <omalloc/omalloc.h>
23#include <Singular/tok.h>
24#include <misc/options.h>
25#include <Singular/stype.h>
26#include <Singular/fehelp.h>
27#include <Singular/ipid.h>
28#include <misc/intvec.h>
29#include <kernel/febase.h>
30#include <polys/matpol.h>
31#include <polys/monomials/ring.h>
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>
38#include <coeffs/numbers.h>
39#include <kernel/polys.h>
40#include <kernel/stairc.h>
41#include <kernel/timer.h>
42#include <Singular/cntrlc.h>
43#include <polys/monomials/maps.h>
44#include <kernel/syz.h>
45#include <Singular/lists.h>
46#include <libpolys/coeffs/longrat.h>
47#include <Singular/libparse.h>
48#include <coeffs/bigintmat.h>
49
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
89/* From the bison docu:
90
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.
96
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*/
106#define YYMAXDEPTH MAX_INT_VAL
107
108extern int   yylineno;
109extern FILE* yyin;
110
111const  char *  currid;
112BOOLEAN    yyInRingConstruction=FALSE;
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   }                                                   \
123   (i) = (int)((long)(a).Data());(a).CleanUp()
124
125#define MYYERROR(a) { WerrorS(a); YYERROR; }
126
127void yyerror(const char * fmt)
128{
129
130  BOOLEAN old_errorreported=errorreported;
131  errorreported = TRUE;
132  if (currid!=NULL)
133  {
134    killid(currid,&IDROOT);
135    currid = NULL;
136  }
137  if(inerror==0)
138  {
139    {
140      if ((strlen(fmt)>1)
141      && (strncmp(fmt,"parse",5)!=0)
142      && (strncmp(fmt,"syntax",6)!=0))
143        WerrorS(fmt);
144      Werror( "error occurred in or before %s line %d: `%s`"
145             ,VoiceName(), yylineno, my_yylinebuf);
146    }
147    if (cmdtok!=0)
148    {
149      const char *s=Tok2Cmdname(cmdtok);
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    }
163    inerror=1;
164  }
165  if ((currentVoice!=NULL)
166  && (currentVoice->prev!=NULL)
167  && (myynest>0)
168#ifdef HAVE_SDB
169  && ((sdb_flags &1)==0)
170#endif
171  )
172  {
173    Werror("leaving %s",VoiceName());
174  }
175  // libfac:
176  extern int libfac_interruptflag;
177  libfac_interruptflag=0;
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
194%token COLONCOLON
195
196/* types, part 1 (ring indep.)*/
197%token <i> GRING_CMD
198%token <i> BIGINTMAT_CMD
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
212%token <i> RESOLUTION_CMD
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
225%token <i> DIVISION_CMD
226%token <i> ELIMINATION_CMD
227%token <i> E_CMD
228%token <i> FAREY_CMD
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
245%token <i> LEADMONOM_CMD
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
253%token <i> MONOM_CMD
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
265%token <i> SBA_CMD
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
291%token <i> CMD_13
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 */
301%token <i> RING_DECL_LIST
302        /* put variables of this type into the currRing list */
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 */
316%token <i> APPLY
317%token <i> ASSUME_CMD
318%token <i> BREAK_CMD
319%token <i> CONTINUE_CMD
320%token <i> ELSE_CMD
321%token <i> EVAL
322%token <i> QUOTE
323%token <i> FOR_CMD
324%token <i> IF_CMD
325%token <i> SYS_BREAK
326%token <i> WHILE_CMD
327%token <i> RETURN
328%token <i> PARAMETER
329
330/* system variables */
331%token <i> SYSVAR
332
333%type <name> extendedid
334%type <lv>   rlist ordering OrderingList orderelem
335%type <name> stringexpr
336%type <lv>   expr elemexpr exprlist expr_arithmetic
337%type <lv>   declare_ip_variable left_value
338%type <i>    error
339%type <i>    ordername
340%type <i>    cmdeq
341%type <i>    setrings
342%type <i>    ringcmd1
343%type <i>    mat_cmd
344
345%type <i>    '=' '<' '>' '+' '-' COLONCOLON
346%type <i>    '/' '[' ']' '^' ',' ';'
347
348
349/*%nonassoc '=' PLUSEQUAL DOTDOT*/
350/*%nonassoc '=' DOTDOT COLONCOLON*/
351%nonassoc '=' DOTDOT
352%left ','
353%left '&'
354%left EQUAL_EQUAL NOTEQUAL
355%left '<'
356%left '+' '-' ':'
357%left '/' '*'
358%left UMINUS NOT
359%left  '^'
360%left '[' ']'
361%left '(' ')'
362%left PLUSPLUS MINUSMINUS
363%left COLONCOLON
364%left '.'
365
366%%
367lines:
368        /**/
369        | lines pprompt
370          {
371            if (timerv)
372            {
373              writeTime("used time:");
374              startTimer();
375            }
376            if (rtimerv)
377            {
378              writeRTime("used real time:");
379              startRTimer();
380            }
381            prompt_char = '>';
382#ifdef HAVE_SDB
383            if (sdb_flags & 2) { sdb_flags=1; YYERROR; }
384#endif
385            if(siCntrlc)
386            {
387              WerrorS("abort...");
388              while((currentVoice!=NULL) && (currentVoice->prev!=NULL)) exitVoice();
389              if (currentVoice!=NULL) currentVoice->ifsw=0;
390            }
391            if (errorreported) /* also catches abort... */
392            {
393              yyerror("");
394            }
395            if (inerror==2) PrintLn();
396            errorreported = inerror = cmdtok = 0;
397            lastreserved = currid = NULL;
398            expected_parms = siCntrlc = FALSE;
399          }
400        ;
401
402pprompt:
403        flowctrl                       /* if, while, for, proc */
404        | command ';'                  /* commands returning no value */
405          {currentVoice->ifsw=0;}
406        | declare_ip_variable ';'      /* default initialization */
407          { $1.CleanUp(); currentVoice->ifsw=0;}
408        | returncmd
409          {
410            YYACCEPT;
411          }
412        | SYS_BREAK
413          {
414            currentVoice->ifsw=0;
415            iiDebug();
416          }
417        | ';'                    /* ignore empty statements */
418          {currentVoice->ifsw=0;}
419        | error ';'
420          {
421            #ifdef SIQ
422            siq=0;
423            #endif
424            yyInRingConstruction = FALSE;
425            currentVoice->ifsw=0;
426            if (inerror)
427            {
428/*  bison failed here*/
429              if ((inerror!=3) && ($1<UMINUS) && ($1>' '))
430              {
431                // 1: yyerror called
432                // 2: scanner put actual string
433                // 3: error rule put token+\n
434                inerror=3;
435                Print(" error at token `%s`\n",iiTwoOps($1));
436              }
437/**/
438
439            }
440            if (!errorreported) WerrorS("...parse error");
441            yyerror("");
442            yyerrok;
443#ifdef HAVE_SDB
444            if ((sdb_flags & 1) && currentVoice->pi!=NULL)
445            {
446              currentVoice->pi->trace_flag |=1;
447            }
448            else
449#endif
450            if (myynest>0)
451            {
452              feBufferTypes t=currentVoice->Typ();
453              //PrintS("leaving yyparse\n");
454              exitBuffer(BT_proc);
455              if (t==BT_example)
456                YYACCEPT;
457              else
458                YYABORT;
459            }
460            else if (currentVoice->prev!=NULL)
461            {
462              exitVoice();
463            }
464#ifdef HAVE_SDB
465            if (sdb_flags &2) sdb_flags=1;
466#endif
467          }
468        ;
469
470flowctrl: ifcmd
471          | whilecmd
472          | example_dummy
473          | forcmd
474          | proccmd
475          | filecmd
476          | helpcmd
477          | examplecmd
478            {if (currentVoice!=NULL) currentVoice->ifsw=0;}
479        ;
480
481example_dummy : EXAMPLE_CMD BLOCKTOK { omFree((ADDRESS)$2); }
482        ;
483
484command: assign
485         | exportcmd
486         | killcmd
487         | listcmd
488         | parametercmd
489         | ringcmd
490         | scriptcmd
491         | setringcmd
492         | typecmd
493         ;
494
495assign: left_value exprlist
496          {
497            if(iiAssign(&$1,&$2)) YYERROR;
498          }
499        ;
500
501elemexpr:
502        RINGVAR
503          {
504            if (currRing==NULL) MYYERROR("no ring active");
505            syMake(&$$,omStrDup($1));
506          }
507        | extendedid
508          {
509            syMake(&$$,$1);
510          }
511        | elemexpr COLONCOLON elemexpr
512          {
513            if(iiExprArith2(&$$, &$1, COLONCOLON, &$3)) YYERROR;
514          }
515        | expr '.' elemexpr
516          {
517            if(iiExprArith2(&$$, &$1, '.', &$3)) YYERROR;
518          }
519        | elemexpr '('  ')'
520          {
521            if(iiExprArith1(&$$,&$1,'(')) YYERROR;
522          }
523        | elemexpr '(' exprlist ')'
524          {
525            if ($1.rtyp==UNKNOWN)
526            { // for x(i)(j)
527              if(iiExprArith2(&$$,&$1,'(',&$3)) YYERROR;
528            }
529            else
530            {
531              $1.next=(leftv)omAllocBin(sleftv_bin);
532              memcpy($1.next,&$3,sizeof(sleftv));
533              if(iiExprArithM(&$$,&$1,'(')) YYERROR;
534            }
535          }
536        | '[' exprlist ']'
537          {
538            if (currRingHdl==NULL) MYYERROR("no ring active");
539            int j = 0;
540            memset(&$$,0,sizeof(sleftv));
541            $$.rtyp=VECTOR_CMD;
542            leftv v = &$2;
543            while (v!=NULL)
544            {
545              int i,t;
546              sleftv tmp;
547              memset(&tmp,0,sizeof(tmp));
548              i=iiTestConvert((t=v->Typ()),POLY_CMD);
549              if((i==0) || (iiConvert(t /*v->Typ()*/,POLY_CMD,i,v,&tmp)))
550              {
551                pDelete((poly *)&$$.data);
552                $2.CleanUp();
553                MYYERROR("expected '[poly,...'");
554              }
555              poly p = (poly)tmp.CopyD(POLY_CMD);
556              pSetCompP(p,++j);
557              $$.data = (void *)pAdd((poly)$$.data,p);
558              v->next=tmp.next;tmp.next=NULL;
559              tmp.CleanUp();
560              v=v->next;
561            }
562            $2.CleanUp();
563          }
564        | INT_CONST
565          {
566            memset(&$$,0,sizeof($$));
567            int i = atoi($1);
568            /*remember not to omFree($1)
569            *because it is a part of the scanner buffer*/
570            $$.rtyp  = INT_CMD;
571            $$.data = (void *)(long)i;
572
573            /* check: out of range input */
574            int l = strlen($1)+2;
575            number n;
576            if (l >= MAX_INT_LEN)
577            {
578              char tmp[MAX_INT_LEN+5];
579              sprintf(tmp,"%d",i);
580              if (strcmp(tmp,$1)!=0)
581              {
582                n_Read($1,&n,coeffs_BIGINT);
583                $$.rtyp=BIGINT_CMD;
584                $$.data = n;
585              }
586            }
587          }
588        | SYSVAR
589          {
590            memset(&$$,0,sizeof($$));
591            $$.rtyp = $1;
592            $$.data = $$.Data();
593          }
594        | stringexpr
595          {
596            memset(&$$,0,sizeof($$));
597            $$.rtyp  = STRING_CMD;
598            $$.data = $1;
599          }
600        | PROC_CMD '(' expr ')'
601          {
602            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
603          }
604        | ROOT_DECL '(' expr ')'
605          {
606            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
607          }
608        | ROOT_DECL_LIST '(' exprlist ')'
609          {
610            if(iiExprArithM(&$$,&$3,$1)) YYERROR;
611          }
612        | ROOT_DECL_LIST '(' ')'
613          {
614            if(iiExprArithM(&$$,NULL,$1)) YYERROR;
615          }
616        | RING_DECL '(' expr ')'
617          {
618            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
619          }
620        | RING_DECL_LIST '(' exprlist ')'
621          {
622            if(iiExprArithM(&$$,&$3,$1)) YYERROR;
623          }
624        | RING_DECL_LIST '(' ')'
625          {
626            if(iiExprArithM(&$$,NULL,$1)) YYERROR;
627          }
628        | CMD_1 '(' expr ')'
629          {
630            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
631          }
632        | CMD_12 '(' expr ')'
633          {
634            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
635          }
636        | CMD_13 '(' expr ')'
637          {
638            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
639          }
640        | CMD_123 '(' expr ')'
641          {
642            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
643          }
644        | CMD_2 '(' expr ',' expr ')'
645          {
646            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
647          }
648        | CMD_12 '(' expr ',' expr ')'
649          {
650            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
651          }
652        | CMD_23 '(' expr ',' expr ')'
653          {
654            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
655          }
656        | CMD_123 '(' expr ',' expr ')'
657          {
658            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
659          }
660        | CMD_3 '(' expr ',' expr ',' expr ')'
661          {
662            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
663          }
664        | CMD_13 '(' expr ',' expr ',' expr ')'
665          {
666            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
667          }
668        | CMD_23 '(' expr ',' expr ',' expr ')'
669          {
670            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
671          }
672        | CMD_123 '(' expr ',' expr ',' expr ')'
673          {
674            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
675          }
676        | CMD_M '(' ')'
677          {
678            if(iiExprArithM(&$$,NULL,$1)) YYERROR;
679          }
680        | CMD_M '(' exprlist ')'
681          {
682            if(iiExprArithM(&$$,&$3,$1)) YYERROR;
683          }
684        | mat_cmd '(' expr ',' expr ',' expr ')'
685          {
686            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
687          }
688        | mat_cmd '(' expr ')'
689          {
690            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
691          }
692        | RING_CMD '(' rlist ',' rlist ',' ordering ')'
693          {
694            if(iiExprArith3(&$$,RING_CMD,&$3,&$5,&$7)) YYERROR;
695          }
696        | RING_CMD '(' expr ')'
697          {
698            if(iiExprArith1(&$$,&$3,RING_CMD)) YYERROR;
699          }
700        ;
701
702exprlist:
703        exprlist ',' expr
704          {
705            leftv v = &$1;
706            while (v->next!=NULL)
707            {
708              v=v->next;
709            }
710            v->next = (leftv)omAllocBin(sleftv_bin);
711            memcpy(v->next,&($3),sizeof(sleftv));
712            $$ = $1;
713          }
714        | expr
715          {
716            $$ = $1;
717          }
718        ;
719
720expr:   expr_arithmetic
721          {
722            /*if ($1.typ == eunknown) YYERROR;*/
723            $$ = $1;
724          }
725        | elemexpr       { $$ = $1; }
726        | '(' exprlist ')'    { $$ = $2; }
727        | expr '[' expr ',' expr ']'
728          {
729            if(iiExprArith3(&$$,'[',&$1,&$3,&$5)) YYERROR;
730          }
731        | expr '[' expr ']'
732          {
733            if(iiExprArith2(&$$,&$1,'[',&$3)) YYERROR;
734          }
735        | APPLY '('  expr ',' CMD_1 ')'
736          {
737            if (iiApply(&$$, &$3, $5, NULL)) YYERROR;
738          }
739        | APPLY '('  expr ',' CMD_12 ')'
740          {
741            if (iiApply(&$$, &$3, $5, NULL)) YYERROR;
742          }
743        | APPLY '('  expr ',' CMD_13 ')'
744          {
745            if (iiApply(&$$, &$3, $5, NULL)) YYERROR;
746          }
747        | APPLY '('  expr ',' CMD_123 ')'
748          {
749            if (iiApply(&$$, &$3, $5, NULL)) YYERROR;
750          }
751        | APPLY '('  expr ',' CMD_M ')'
752          {
753            if (iiApply(&$$, &$3, $5, NULL)) YYERROR;
754          }
755        | APPLY '('  expr ',' expr ')'
756          {
757            if (iiApply(&$$, &$3, 0, &$5)) YYERROR;
758          }
759        | quote_start expr quote_end
760          {
761            $$=$2;
762          }
763        | quote_start expr '=' expr quote_end
764          {
765            #ifdef SIQ
766            siq++;
767            if (siq>0)
768            { if (iiExprArith2(&$$,&$2,'=',&$4)) YYERROR; }
769            else
770            #endif
771            {
772              memset(&$$,0,sizeof($$));
773              $$.rtyp=NONE;
774              if (iiAssign(&$2,&$4)) YYERROR;
775            }
776            #ifdef SIQ
777            siq--;
778            #endif
779          }
780        | assume_start expr ',' expr quote_end
781          {
782            iiTestAssume(&$2,&$4);
783            memset(&$$,0,sizeof($$));
784            $$.rtyp=NONE;
785          }
786        | EVAL  '('
787          {
788            #ifdef SIQ
789            siq--;
790            #endif
791          }
792          expr ')'
793          {
794            #ifdef SIQ
795            if (siq<=0) $4.Eval();
796            #endif
797            $$=$4;
798            #ifdef SIQ
799            siq++;
800            #endif
801          }
802          ;
803
804quote_start:    QUOTE  '('
805          {
806            #ifdef SIQ
807            siq++;
808            #endif
809          }
810          ;
811
812assume_start:    ASSUME_CMD '('
813          {
814            #ifdef SIQ
815            siq++;
816            #endif
817          }
818          ;
819
820quote_end: ')'
821          {
822            #ifdef SIQ
823            siq--;
824            #endif
825          }
826          ;
827
828expr_arithmetic:
829          expr PLUSPLUS     %prec PLUSPLUS
830          {
831            if(iiExprArith1(&$$,&$1,PLUSPLUS)) YYERROR;
832          }
833        | expr MINUSMINUS   %prec MINUSMINUS
834          {
835            if(iiExprArith1(&$$,&$1,MINUSMINUS)) YYERROR;
836          }
837        | expr '+' expr
838          {
839            if(iiExprArith2(&$$,&$1,'+',&$3)) YYERROR;
840          }
841        | expr '-' expr
842          {
843            if(iiExprArith2(&$$,&$1,'-',&$3)) YYERROR;
844          }
845        | expr '/' expr
846          {
847            if(iiExprArith2(&$$,&$1,$<i>2,&$3)) YYERROR;
848          }
849        | expr '^' expr
850          {
851            if(iiExprArith2(&$$,&$1,'^',&$3)) YYERROR;
852          }
853        | expr '<' expr
854          {
855            if(iiExprArith2(&$$,&$1,$<i>2,&$3)) YYERROR;
856          }
857        | expr '&' expr
858          {
859            if(iiExprArith2(&$$,&$1,$<i>2,&$3)) YYERROR;
860          }
861        | expr NOTEQUAL expr
862          {
863            if(iiExprArith2(&$$,&$1,NOTEQUAL,&$3)) YYERROR;
864          }
865        | expr EQUAL_EQUAL expr
866          {
867            if(iiExprArith2(&$$,&$1,EQUAL_EQUAL,&$3)) YYERROR;
868          }
869        | expr DOTDOT expr
870          {
871            if(iiExprArith2(&$$,&$1,DOTDOT,&$3)) YYERROR;
872          }
873        | expr ':' expr
874          {
875            if(iiExprArith2(&$$,&$1,':',&$3)) YYERROR;
876          }
877        | NOT expr
878          {
879            memset(&$$,0,sizeof($$));
880            int i; TESTSETINT($2,i);
881            $$.rtyp  = INT_CMD;
882            $$.data = (void *)(long)(i == 0 ? 1 : 0);
883          }
884        | '-' expr %prec UMINUS
885          {
886            if(iiExprArith1(&$$,&$2,'-')) YYERROR;
887          }
888        ;
889
890left_value:
891        declare_ip_variable cmdeq  { $$ = $1; }
892        | exprlist '='
893          {
894            if ($1.rtyp==0)
895            {
896              Werror("`%s` is undefined",$1.Fullname());
897              YYERROR;
898            }
899            else if (($1.rtyp==MODUL_CMD)
900            // matrix m; m[2]=...
901            && ($1.e!=NULL) && ($1.e->next==NULL))
902            {
903              MYYERROR("matrix must have 2 indices");
904            }
905            $$ = $1;
906          }
907        ;
908
909
910extendedid:
911        UNKNOWN_IDENT
912        | '`' expr '`'
913          {
914            if ($2.Typ()!=STRING_CMD)
915            {
916              MYYERROR("string expression expected");
917            }
918            $$ = (char *)$2.CopyD(STRING_CMD);
919            $2.CleanUp();
920          }
921        ;
922
923declare_ip_variable:
924        ROOT_DECL elemexpr
925          {
926            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
927              YYERROR;
928          }
929        | ROOT_DECL_LIST elemexpr
930          {
931            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
932              YYERROR;
933          }
934        | RING_DECL elemexpr
935          {
936            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
937          }
938        | RING_DECL_LIST elemexpr
939          {
940            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
941          }
942        | mat_cmd elemexpr '[' expr ']' '[' expr ']'
943          {
944            int r; TESTSETINT($4,r);
945            int c; TESTSETINT($7,c);
946            if (r < 1)
947              MYYERROR("rows must be greater than 0");
948            if (c < 0)
949              MYYERROR("cols must be greater than -1");
950            leftv v;
951            idhdl h;
952            if ($1 == MATRIX_CMD)
953            {
954              if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
955              v=&$$;
956              h=(idhdl)v->data;
957              idDelete(&IDIDEAL(h));
958              IDMATRIX(h) = mpNew(r,c);
959              if (IDMATRIX(h)==NULL) YYERROR;
960            }
961            else if ($1 == INTMAT_CMD)
962            {
963              if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
964                YYERROR;
965              v=&$$;
966              h=(idhdl)v->data;
967              delete IDINTVEC(h);
968              IDINTVEC(h) = new intvec(r,c,0);
969              if (IDINTVEC(h)==NULL) YYERROR;
970            }
971            else /* BIGINTMAT_CMD */
972            {
973              if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
974                YYERROR;
975              v=&$$;
976              h=(idhdl)v->data;
977              delete IDBIMAT(h);
978              IDBIMAT(h) = new bigintmat(r, c, coeffs_BIGINT);
979              if (IDBIMAT(h)==NULL) YYERROR;
980            }
981          }
982        | mat_cmd elemexpr
983          {
984            if ($1 == MATRIX_CMD)
985            {
986              if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
987            }
988            else if ($1 == INTMAT_CMD)
989            {
990              if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
991                YYERROR;
992              leftv v=&$$;
993              idhdl h;
994              do
995              {
996                 h=(idhdl)v->data;
997                 delete IDINTVEC(h);
998                 IDINTVEC(h) = new intvec(1,1,0);
999                 v=v->next;
1000              } while (v!=NULL);
1001            }
1002            else /* BIGINTMAT_CMD */
1003            {
1004              if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
1005                YYERROR;
1006            }
1007          }
1008        | declare_ip_variable ',' elemexpr
1009          {
1010            int t=$1.Typ();
1011            sleftv r;
1012            memset(&r,0,sizeof(sleftv));
1013            if ((BEGIN_RING<t) && (t<END_RING))
1014            {
1015              if (iiDeclCommand(&r,&$3,myynest,t,&(currRing->idroot), TRUE))
1016                YYERROR;
1017            }
1018            else
1019            {
1020              if (iiDeclCommand(&r,&$3,myynest,t,&($3.req_packhdl->idroot)))
1021                YYERROR;
1022            }
1023            leftv v=&$1;
1024            while (v->next!=NULL) v=v->next;
1025            v->next=(leftv)omAllocBin(sleftv_bin);
1026            memcpy(v->next,&r,sizeof(sleftv));
1027            $$=$1;
1028          }
1029        | PROC_CMD elemexpr
1030          {
1031            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
1032              YYERROR;
1033          }
1034        ;
1035
1036stringexpr:
1037        STRINGTOK
1038        ;
1039
1040rlist:
1041        expr
1042        | '(' expr ',' exprlist ')'
1043          {
1044            leftv v = &$2;
1045            while (v->next!=NULL)
1046            {
1047              v=v->next;
1048            }
1049            v->next = (leftv)omAllocBin(sleftv_bin);
1050            memcpy(v->next,&($4),sizeof(sleftv));
1051            $$ = $2;
1052          }
1053        ;
1054
1055ordername:
1056        UNKNOWN_IDENT
1057        {
1058          // let rInit take care of any errors
1059          $$=rOrderName($1);
1060        }
1061        ;
1062
1063orderelem:
1064        ordername
1065          {
1066            memset(&$$,0,sizeof($$));
1067            intvec *iv = new intvec(2);
1068            (*iv)[0] = 1;
1069            (*iv)[1] = $1;
1070            $$.rtyp = INTVEC_CMD;
1071            $$.data = (void *)iv;
1072          }
1073        | ordername '(' exprlist ')'
1074          {
1075            memset(&$$,0,sizeof($$));
1076            leftv sl = &$3;
1077            int slLength;
1078            {
1079              slLength =  exprlist_length(sl);
1080              int l = 2 +  slLength;
1081              intvec *iv = new intvec(l);
1082              (*iv)[0] = slLength;
1083              (*iv)[1] = $1;
1084
1085              int i = 2;
1086              while ((i<l) && (sl!=NULL))
1087              {
1088                if (sl->Typ() == INT_CMD)
1089                {
1090                  (*iv)[i++] = (int)((long)(sl->Data()));
1091                }
1092                else if ((sl->Typ() == INTVEC_CMD)
1093                ||(sl->Typ() == INTMAT_CMD))
1094                {
1095                  intvec *ivv = (intvec *)(sl->Data());
1096                  int ll = 0,l = ivv->length();
1097                  for (; l>0; l--)
1098                  {
1099                    (*iv)[i++] = (*ivv)[ll++];
1100                  }
1101                }
1102                else
1103                {
1104                  delete iv;
1105                  $3.CleanUp();
1106                  MYYERROR("wrong type in ordering");
1107                }
1108                sl = sl->next;
1109              }
1110              $$.rtyp = INTVEC_CMD;
1111              $$.data = (void *)iv;
1112            }
1113            $3.CleanUp();
1114          }
1115        ;
1116
1117OrderingList:
1118        orderelem
1119        |  orderelem ',' OrderingList
1120          {
1121            $$ = $1;
1122            $$.next = (sleftv *)omAllocBin(sleftv_bin);
1123            memcpy($$.next,&$3,sizeof(sleftv));
1124          }
1125        ;
1126
1127ordering:
1128        orderelem
1129        | '(' OrderingList ')'
1130          {
1131            $$ = $2;
1132          }
1133        ;
1134
1135cmdeq:  '='
1136          {
1137            expected_parms = TRUE;
1138          }
1139        ;
1140
1141
1142mat_cmd: MATRIX_CMD
1143            { $$ = $1; }
1144        | INTMAT_CMD
1145            { $$ = $1; }
1146        | BIGINTMAT_CMD
1147            { $$ = $1; }
1148          ;
1149
1150/* --------------------------------------------------------------------*/
1151/* section of pure commands                                            */
1152/* --------------------------------------------------------------------*/
1153
1154filecmd:
1155        '<' stringexpr
1156          { if ($<i>1 != '<') YYERROR;
1157            if((feFilePending=feFopen($2,"r",NULL,TRUE))==NULL) YYERROR; }
1158        ';'
1159          { newFile($2,feFilePending); }
1160        ;
1161
1162helpcmd:
1163        HELP_CMD STRINGTOK ';'
1164          {
1165            feHelp($2);
1166            omFree((ADDRESS)$2);
1167          }
1168        | HELP_CMD ';'
1169          {
1170            feHelp(NULL);
1171          }
1172        ;
1173
1174examplecmd:
1175        EXAMPLE_CMD STRINGTOK ';'
1176          {
1177            singular_example($2);
1178            omFree((ADDRESS)$2);
1179          }
1180       ;
1181
1182exportcmd:
1183        EXPORT_CMD exprlist
1184        {
1185          if (basePack!=$2.req_packhdl)
1186          {
1187            if(iiExport(&$2,0,currPack)) YYERROR;
1188          }
1189          else
1190            if (iiExport(&$2,0)) YYERROR;
1191        }
1192        ;
1193
1194killcmd:
1195        KILL_CMD elemexpr
1196        {
1197          leftv v=&$2;
1198          if (v->rtyp!=IDHDL)
1199          {
1200            if (v->name!=NULL)
1201            {
1202               Werror("`%s` is undefined in kill",v->name);
1203            }
1204            else               WerrorS("kill what ?");
1205          }
1206          else
1207          {
1208            killhdl((idhdl)v->data,v->req_packhdl);
1209          }
1210        }
1211        | killcmd ',' elemexpr
1212        {
1213          leftv v=&$3;
1214          if (v->rtyp!=IDHDL)
1215          {
1216            if (v->name!=NULL)
1217            {
1218               Werror("`%s` is undefined in kill",v->name);
1219            }
1220            else               WerrorS("kill what ?");
1221          }
1222          else
1223          {
1224            killhdl((idhdl)v->data,v->req_packhdl);
1225          }
1226        }
1227        ;
1228
1229listcmd:
1230        LISTVAR_CMD '(' ROOT_DECL ')'
1231          {
1232            list_cmd($3,NULL,"// ",TRUE);
1233          }
1234        | LISTVAR_CMD '(' ROOT_DECL_LIST ')'
1235          {
1236            list_cmd($3,NULL,"// ",TRUE);
1237          }
1238        | LISTVAR_CMD '(' RING_DECL ')'
1239          {
1240            if ($3==QRING_CMD) $3=RING_CMD;
1241            list_cmd($3,NULL,"// ",TRUE);
1242          }
1243        | LISTVAR_CMD '(' RING_DECL_LIST ')'
1244          {
1245            list_cmd($3,NULL,"// ",TRUE);
1246          }
1247        | LISTVAR_CMD '(' RING_CMD ')'
1248          {
1249            list_cmd(RING_CMD,NULL,"// ",TRUE);
1250          }
1251        | LISTVAR_CMD '(' mat_cmd ')'
1252          {
1253            list_cmd($3,NULL,"// ",TRUE);
1254           }
1255        | LISTVAR_CMD '(' PROC_CMD ')'
1256          {
1257            list_cmd(PROC_CMD,NULL,"// ",TRUE);
1258          }
1259        | LISTVAR_CMD '(' elemexpr ')'
1260          {
1261            list_cmd(0,$3.Fullname(),"// ",TRUE);
1262            $3.CleanUp();
1263          }
1264        | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL ')'
1265          {
1266            if($3.Typ() == PACKAGE_CMD)
1267              list_cmd($5,NULL,"// ",TRUE);
1268            $3.CleanUp();
1269          }
1270        | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL_LIST ')'
1271          {
1272            if($3.Typ() == PACKAGE_CMD)
1273              list_cmd($5,NULL,"// ",TRUE);
1274            $3.CleanUp();
1275          }
1276        | LISTVAR_CMD '(' elemexpr ',' RING_DECL ')'
1277          {
1278            if($3.Typ() == PACKAGE_CMD)
1279              list_cmd($5,NULL,"// ",TRUE);
1280            $3.CleanUp();
1281          }
1282        | LISTVAR_CMD '(' elemexpr ',' RING_DECL_LIST ')'
1283          {
1284            if($3.Typ() == PACKAGE_CMD)
1285              list_cmd($5,NULL,"// ",TRUE);
1286            $3.CleanUp();
1287          }
1288        | LISTVAR_CMD '(' elemexpr ',' RING_CMD ')'
1289          {
1290            if($3.Typ() == PACKAGE_CMD)
1291              list_cmd($5,NULL,"// ",TRUE);
1292            $3.CleanUp();
1293          }
1294        | LISTVAR_CMD '(' elemexpr ',' mat_cmd ')'
1295          {
1296            if($3.Typ() == PACKAGE_CMD)
1297              list_cmd($5,NULL,"// ",TRUE);
1298            $3.CleanUp();
1299          }
1300        | LISTVAR_CMD '(' elemexpr ',' PROC_CMD ')'
1301          {
1302            if($3.Typ() == PACKAGE_CMD)
1303              list_cmd($5,NULL,"// ",TRUE);
1304            $3.CleanUp();
1305          }
1306        //| LISTVAR_CMD '(' elemexpr ',' elemexpr ')'
1307        //  {
1308        //    //if($3.Typ() == PACKAGE_CMD)
1309        //    //  list_cmd($5,NULL,"// ",TRUE);
1310        //    $3.CleanUp();
1311        //  }
1312        | LISTVAR_CMD '(' ')'
1313          {
1314            list_cmd(-1,NULL,"// ",TRUE);
1315          }
1316        ;
1317
1318ringcmd1:
1319       RING_CMD { yyInRingConstruction = TRUE; }
1320       ;
1321
1322ringcmd:
1323        ringcmd1
1324          elemexpr cmdeq
1325          rlist     ','      /* description of coeffs */
1326          rlist     ','      /* var names */
1327          ordering           /* list of (multiplier ordering (weight(s))) */
1328          {
1329            const char *ring_name = $2.name;
1330            ring b=
1331            rInit(&$4,            /* characteristik and list of parameters*/
1332                  &$6,            /* names of ringvariables */
1333                  &$8);            /* ordering */
1334            idhdl newRingHdl=NULL;
1335
1336            if (b!=NULL)
1337            {
1338              newRingHdl=enterid(ring_name, myynest, RING_CMD,
1339                                   &($2.req_packhdl->idroot),FALSE);
1340              $2.CleanUp();
1341              if (newRingHdl!=NULL)
1342              {
1343                IDRING(newRingHdl)=b;
1344              }
1345              else
1346              {
1347                rKill(b);
1348              }
1349            }
1350            yyInRingConstruction = FALSE;
1351            if (newRingHdl==NULL)
1352            {
1353              MYYERROR("cannot make ring");
1354            }
1355            else
1356            {
1357              rSetHdl(newRingHdl);
1358            }
1359          }
1360        | ringcmd1 elemexpr
1361          {
1362            const char *ring_name = $2.name;
1363            if (!inerror) rDefault(ring_name);
1364            yyInRingConstruction = FALSE;
1365            $2.CleanUp();
1366          }
1367        ;
1368
1369scriptcmd:
1370         SYSVAR stringexpr
1371          {
1372            if (($1!=LIB_CMD)||(jjLOAD($2,TRUE))) YYERROR;
1373          }
1374        ;
1375
1376setrings:  SETRING_CMD | KEEPRING_CMD ;
1377
1378setringcmd:
1379        setrings expr
1380          {
1381            if (($1==KEEPRING_CMD) && (myynest==0))
1382               MYYERROR("only inside a proc allowed");
1383            const char * n=$2.Name();
1384            if ((($2.Typ()==RING_CMD)||($2.Typ()==QRING_CMD))
1385            && ($2.rtyp==IDHDL))
1386            {
1387              idhdl h=(idhdl)$2.data;
1388              if ($2.e!=NULL) h=rFindHdl((ring)$2.Data(),NULL, NULL);
1389              //Print("setring %s lev %d (ptr:%x)\n",IDID(h),IDLEV(h),IDRING(h));
1390              if ($1==KEEPRING_CMD)
1391              {
1392                if (h!=NULL)
1393                {
1394                  if (IDLEV(h)!=0)
1395                  {
1396                    if (iiExport(&$2,myynest-1)) YYERROR;
1397#if 1
1398                    idhdl p=IDRING(h)->idroot;
1399                    idhdl root=p;
1400                    int prevlev=myynest-1;
1401                    while (p!=NULL)
1402                    {
1403                      if (IDLEV(p)==myynest)
1404                      {
1405                        idhdl old=root->get(IDID(p),prevlev);
1406                        if (old!=NULL)
1407                        {
1408                          if (BVERBOSE(V_REDEFINE))
1409                            Warn("redefining %s",IDID(p));
1410                          killhdl2(old,&root,IDRING(h));
1411                          IDRING(h)->idroot=root;
1412                        }
1413                        IDLEV(p)=prevlev;
1414                      }
1415                      p=IDNEXT(p);
1416                    }
1417#endif
1418                  }
1419#ifdef USE_IILOCALRING
1420                  iiLocalRing[myynest-1]=IDRING(h);
1421#endif
1422                  procstack->cRing=IDRING(h);
1423                  procstack->cRingHdl=h;
1424                }
1425                else
1426                {
1427                  Werror("%s is no identifier",n);
1428                  $2.CleanUp();
1429                  YYERROR;
1430                }
1431              }
1432              if (h!=NULL) rSetHdl(h);
1433              else
1434              {
1435                Werror("cannot find the name of the basering %s",n);
1436                $2.CleanUp();
1437                YYERROR;
1438              }
1439              $2.CleanUp();
1440            }
1441            else
1442            {
1443              Werror("%s is no name of a ring/qring",n);
1444              $2.CleanUp();
1445              YYERROR;
1446            }
1447          }
1448        ;
1449
1450typecmd:
1451        TYPE_CMD expr
1452          {
1453            type_cmd(&($2));
1454          }
1455        | exprlist
1456          {
1457            //Print("typ is %d, rtyp:%d\n",$1.Typ(),$1.rtyp);
1458            #ifdef SIQ
1459            if ($1.rtyp!=COMMAND)
1460            {
1461            #endif
1462              if ($1.Typ()==UNKNOWN)
1463              {
1464                if ($1.name!=NULL)
1465                {
1466                  Werror("`%s` is undefined",$1.name);
1467                  omFree((ADDRESS)$1.name);
1468                }
1469                YYERROR;
1470              }
1471            #ifdef SIQ
1472            }
1473            #endif
1474            $1.Print(&sLastPrinted);
1475            $1.CleanUp(currRing);
1476            if (errorreported) YYERROR;
1477          }
1478        ;
1479
1480/* --------------------------------------------------------------------*/
1481/* section of flow control                                             */
1482/* --------------------------------------------------------------------*/
1483
1484ifcmd: IF_CMD '(' expr ')' BLOCKTOK
1485          {
1486            int i; TESTSETINT($3,i);
1487            if (i!=0)
1488            {
1489              newBuffer( $5, BT_if);
1490            }
1491            else
1492            {
1493              omFree((ADDRESS)$5);
1494              currentVoice->ifsw=1;
1495            }
1496          }
1497        | ELSE_CMD BLOCKTOK
1498          {
1499            if (currentVoice->ifsw==1)
1500            {
1501              currentVoice->ifsw=0;
1502              newBuffer( $2, BT_else);
1503            }
1504            else
1505            {
1506              if (currentVoice->ifsw!=2)
1507              {
1508                Warn("`else` without `if` in level %d",myynest);
1509              }
1510              omFree((ADDRESS)$2);
1511            }
1512            currentVoice->ifsw=0;
1513          }
1514        | IF_CMD '(' expr ')' BREAK_CMD
1515          {
1516            int i; TESTSETINT($3,i);
1517            if (i)
1518            {
1519              if (exitBuffer(BT_break)) YYERROR;
1520            }
1521            currentVoice->ifsw=0;
1522          }
1523        | BREAK_CMD
1524          {
1525            if (exitBuffer(BT_break)) YYERROR;
1526            currentVoice->ifsw=0;
1527          }
1528        | CONTINUE_CMD
1529          {
1530            if (contBuffer(BT_break)) YYERROR;
1531            currentVoice->ifsw=0;
1532          }
1533      ;
1534
1535whilecmd:
1536        WHILE_CMD STRINGTOK BLOCKTOK
1537          {
1538            /* -> if(!$2) break; $3; continue;*/
1539            char * s = (char *)omAlloc( strlen($2) + strlen($3) + 36);
1540            sprintf(s,"whileif (!(%s)) break;\n%scontinue;\n " ,$2,$3);
1541            newBuffer(s,BT_break);
1542            omFree((ADDRESS)$2);
1543            omFree((ADDRESS)$3);
1544          }
1545        ;
1546
1547forcmd:
1548        FOR_CMD STRINGTOK STRINGTOK STRINGTOK BLOCKTOK
1549          {
1550            /* $2 */
1551            /* if (!$3) break; $5; $4; continue; */
1552            char * s = (char *)omAlloc( strlen($3)+strlen($4)+strlen($5)+36);
1553            sprintf(s,"forif (!(%s)) break;\n%s%s;\ncontinue;\n "
1554                   ,$3,$5,$4);
1555            omFree((ADDRESS)$3);
1556            omFree((ADDRESS)$4);
1557            omFree((ADDRESS)$5);
1558            newBuffer(s,BT_break);
1559            s = (char *)omAlloc( strlen($2) + 3);
1560            sprintf(s,"%s;\n",$2);
1561            omFree((ADDRESS)$2);
1562            newBuffer(s,BT_if);
1563          }
1564        ;
1565
1566proccmd:
1567        PROC_CMD extendedid BLOCKTOK
1568          {
1569            idhdl h = enterid($2,myynest,PROC_CMD,&IDROOT,TRUE);
1570            if (h==NULL) {omFree((ADDRESS)$2);omFree((ADDRESS)$3); YYERROR;}
1571            iiInitSingularProcinfo(IDPROC(h),"", $2, 0, 0);
1572            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+31);;
1573            sprintf(IDPROC(h)->data.s.body,"parameter list #;\n%s;return();\n\n",$3);
1574            omFree((ADDRESS)$3);
1575            omFree((ADDRESS)$2);
1576          }
1577        | PROC_DEF STRINGTOK BLOCKTOK
1578          {
1579            idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE);
1580            if (h==NULL)
1581            {
1582              omFree((ADDRESS)$1);
1583              omFree((ADDRESS)$2);
1584              omFree((ADDRESS)$3);
1585              YYERROR;
1586            }
1587            char *args=iiProcArgs($2,FALSE);
1588            omFree((ADDRESS)$2);
1589            iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0);
1590            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+strlen(args)+14);;
1591            sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$3);
1592            omFree((ADDRESS)args);
1593            omFree((ADDRESS)$3);
1594            omFree((ADDRESS)$1);
1595          }
1596        | PROC_DEF STRINGTOK STRINGTOK BLOCKTOK
1597          {
1598            omFree((ADDRESS)$3);
1599            idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE);
1600            if (h==NULL)
1601            {
1602              omFree((ADDRESS)$1);
1603              omFree((ADDRESS)$2);
1604              omFree((ADDRESS)$4);
1605              YYERROR;
1606            }
1607            char *args=iiProcArgs($2,FALSE);
1608            omFree((ADDRESS)$2);
1609            iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0);
1610            omFree((ADDRESS)$1);
1611            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($4)+strlen(args)+14);;
1612            sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$4);
1613            omFree((ADDRESS)args);
1614            omFree((ADDRESS)$4);
1615          }
1616        ;
1617
1618parametercmd:
1619        PARAMETER declare_ip_variable
1620          {
1621            // decl. of type proc p(int i)
1622            if ($1==PARAMETER)  { if (iiParameter(&$2)) YYERROR; }
1623            else                { if (iiAlias(&$2)) YYERROR; }
1624          }
1625        | PARAMETER expr
1626          {
1627            // decl. of type proc p(i)
1628            sleftv tmp_expr;
1629            if ($1==ALIAS_CMD) MYYERROR("alias requires a type");
1630            if ((iiDeclCommand(&tmp_expr,&$2,myynest,DEF_CMD,&IDROOT))
1631            || (iiParameter(&tmp_expr)))
1632              YYERROR;
1633          }
1634        ;
1635
1636returncmd:
1637        RETURN '(' exprlist ')'
1638          {
1639            iiRETURNEXPR.Copy(&$3);
1640            $3.CleanUp();
1641            if (exitBuffer(BT_proc)) YYERROR;
1642          }
1643        | RETURN '(' ')'
1644          {
1645            if ($1==RETURN)
1646            {
1647              iiRETURNEXPR.Init();
1648              iiRETURNEXPR.rtyp=NONE;
1649              if (exitBuffer(BT_proc)) YYERROR;
1650            }
1651          }
1652        ;
Note: See TracBrowser for help on using the repository browser.