source: git/Singular/grammar.y @ aee346d

spielwiese
Last change on this file since aee346d 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
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> 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
337%type <i>    error
338%type <i>    ordername
339%type <i>    cmdeq
340%type <i>    setrings
341%type <i>    ringcmd1
342%type <i>    mat_cmd
343
344%type <i>    '=' '<' '>' '+' '-' COLONCOLON
345%type <i>    '/' '[' ']' '^' ',' ';'
346
347
348/*%nonassoc '=' PLUSEQUAL DOTDOT*/
349/*%nonassoc '=' DOTDOT COLONCOLON*/
350%nonassoc '=' DOTDOT
351%left ','
352%left '&'
353%left EQUAL_EQUAL NOTEQUAL
354%left '<'
355%left '+' '-' ':'
356%left '/' '*'
357%left UMINUS NOT
358%left  '^'
359%left '[' ']'
360%left '(' ')'
361%left PLUSPLUS MINUSMINUS
362%left COLONCOLON
363%left '.'
364
365%%
366lines:
367        /**/
368        | lines pprompt
369          {
370            if (timerv)
371            {
372              writeTime("used time:");
373              startTimer();
374            }
375            if (rtimerv)
376            {
377              writeRTime("used real time:");
378              startRTimer();
379            }
380            prompt_char = '>';
381#ifdef HAVE_SDB
382            if (sdb_flags & 2) { sdb_flags=1; YYERROR; }
383#endif
384            if(siCntrlc)
385            {
386              WerrorS("abort...");
387              while((currentVoice!=NULL) && (currentVoice->prev!=NULL)) exitVoice();
388              if (currentVoice!=NULL) currentVoice->ifsw=0;
389            }
390            if (errorreported) /* also catches abort... */
391            {
392              yyerror("");
393            }
394            if (inerror==2) PrintLn();
395            errorreported = inerror = cmdtok = 0;
396            lastreserved = currid = NULL;
397            expected_parms = siCntrlc = FALSE;
398          }
399        ;
400
401pprompt:
402        flowctrl                       /* if, while, for, proc */
403        | command ';'                  /* commands returning no value */
404          {currentVoice->ifsw=0;}
405        | declare_ip_variable ';'      /* default initialization */
406          { $1.CleanUp(); currentVoice->ifsw=0;}
407        | returncmd
408          {
409            YYACCEPT;
410          }
411        | SYS_BREAK
412          {
413            currentVoice->ifsw=0;
414            iiDebug();
415          }
416        | ';'                    /* ignore empty statements */
417          {currentVoice->ifsw=0;}
418        | error ';'
419          {
420            #ifdef SIQ
421            siq=0;
422            #endif
423            yyInRingConstruction = FALSE;
424            currentVoice->ifsw=0;
425            if (inerror)
426            {
427/*  bison failed here*/
428              if ((inerror!=3) && ($1<UMINUS) && ($1>' '))
429              {
430                // 1: yyerror called
431                // 2: scanner put actual string
432                // 3: error rule put token+\n
433                inerror=3;
434                Print(" error at token `%s`\n",iiTwoOps($1));
435              }
436/**/
437
438            }
439            if (!errorreported) WerrorS("...parse error");
440            yyerror("");
441            yyerrok;
442#ifdef HAVE_SDB
443            if ((sdb_flags & 1) && currentVoice->pi!=NULL)
444            {
445              currentVoice->pi->trace_flag |=1;
446            }
447            else
448#endif
449            if (myynest>0)
450            {
451              feBufferTypes t=currentVoice->Typ();
452              //PrintS("leaving yyparse\n");
453              exitBuffer(BT_proc);
454              if (t==BT_example)
455                YYACCEPT;
456              else
457                YYABORT;
458            }
459            else if (currentVoice->prev!=NULL)
460            {
461              exitVoice();
462            }
463#ifdef HAVE_SDB
464            if (sdb_flags &2) sdb_flags=1;
465#endif
466          }
467        ;
468
469flowctrl: ifcmd
470          | whilecmd
471          | example_dummy
472          | forcmd
473          | proccmd
474          | filecmd
475          | helpcmd
476          | examplecmd
477            {if (currentVoice!=NULL) currentVoice->ifsw=0;}
478        ;
479
480example_dummy : EXAMPLE_CMD BLOCKTOK { omFree((ADDRESS)$2); }
481        ;
482
483command: assign
484         | exportcmd
485         | killcmd
486         | listcmd
487         | parametercmd
488         | ringcmd
489         | scriptcmd
490         | setringcmd
491         | typecmd
492         ;
493
494assign: left_value exprlist
495          {
496            if(iiAssign(&$1,&$2)) YYERROR;
497          }
498        ;
499
500elemexpr:
501        RINGVAR
502          {
503            if (currRing==NULL) MYYERROR("no ring active");
504            syMake(&$$,omStrDup($1));
505          }
506        | extendedid
507          {
508            syMake(&$$,$1);
509          }
510        | elemexpr COLONCOLON elemexpr
511          {
512            if(iiExprArith2(&$$, &$1, COLONCOLON, &$3)) YYERROR;
513          }
514        | expr '.' elemexpr
515          {
516            if(iiExprArith2(&$$, &$1, '.', &$3)) YYERROR;
517          }
518        | elemexpr '('  ')'
519          {
520            if(iiExprArith1(&$$,&$1,'(')) YYERROR;
521          }
522        | elemexpr '(' exprlist ')'
523          {
524            if ($1.rtyp==UNKNOWN)
525            { // for x(i)(j)
526              if(iiExprArith2(&$$,&$1,'(',&$3)) YYERROR;
527            }
528            else
529            {
530              $1.next=(leftv)omAllocBin(sleftv_bin);
531              memcpy($1.next,&$3,sizeof(sleftv));
532              if(iiExprArithM(&$$,&$1,'(')) YYERROR;
533            }
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            {
544              int i,t;
545              sleftv tmp;
546              memset(&tmp,0,sizeof(tmp));
547              i=iiTestConvert((t=v->Typ()),POLY_CMD);
548              if((i==0) || (iiConvert(t /*v->Typ()*/,POLY_CMD,i,v,&tmp)))
549              {
550                pDelete((poly *)&$$.data);
551                $2.CleanUp();
552                MYYERROR("expected '[poly,...'");
553              }
554              poly p = (poly)tmp.CopyD(POLY_CMD);
555              pSetCompP(p,++j);
556              $$.data = (void *)pAdd((poly)$$.data,p);
557              v->next=tmp.next;tmp.next=NULL;
558              tmp.CleanUp();
559              v=v->next;
560            }
561            $2.CleanUp();
562          }
563        | INT_CONST
564          {
565            memset(&$$,0,sizeof($$));
566            int i = atoi($1);
567            /*remember not to omFree($1)
568            *because it is a part of the scanner buffer*/
569            $$.rtyp  = INT_CMD;
570            $$.data = (void *)(long)i;
571
572            /* check: out of range input */
573            int l = strlen($1)+2;
574            number n;
575            if (l >= MAX_INT_LEN)
576            {
577              char tmp[MAX_INT_LEN+5];
578              sprintf(tmp,"%d",i);
579              if (strcmp(tmp,$1)!=0)
580              {
581                n_Read($1,&n,coeffs_BIGINT);
582                $$.rtyp=BIGINT_CMD;
583                $$.data = n;
584              }
585            }
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          }
599        | PROC_CMD '(' expr ')'
600          {
601            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
602          }
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          }
619        | RING_DECL_LIST '(' exprlist ')'
620          {
621            if(iiExprArithM(&$$,&$3,$1)) YYERROR;
622          }
623        | RING_DECL_LIST '(' ')'
624          {
625            if(iiExprArithM(&$$,NULL,$1)) YYERROR;
626          }
627        | CMD_1 '(' expr ')'
628          {
629            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
630          }
631        | CMD_12 '(' expr ')'
632          {
633            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
634          }
635        | CMD_13 '(' expr ')'
636          {
637            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
638          }
639        | CMD_123 '(' expr ')'
640          {
641            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
642          }
643        | CMD_2 '(' expr ',' expr ')'
644          {
645            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
646          }
647        | CMD_12 '(' expr ',' expr ')'
648          {
649            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
650          }
651        | CMD_23 '(' expr ',' expr ')'
652          {
653            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
654          }
655        | CMD_123 '(' expr ',' expr ')'
656          {
657            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
658          }
659        | CMD_3 '(' expr ',' expr ',' expr ')'
660          {
661            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
662          }
663        | CMD_13 '(' expr ',' expr ',' expr ')'
664          {
665            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
666          }
667        | CMD_23 '(' expr ',' expr ',' expr ')'
668          {
669            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
670          }
671        | CMD_123 '(' expr ',' expr ',' expr ')'
672          {
673            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
674          }
675        | CMD_M '(' ')'
676          {
677            if(iiExprArithM(&$$,NULL,$1)) YYERROR;
678          }
679        | CMD_M '(' exprlist ')'
680          {
681            if(iiExprArithM(&$$,&$3,$1)) YYERROR;
682          }
683        | mat_cmd '(' expr ',' expr ',' expr ')'
684          {
685            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
686          }
687        | mat_cmd '(' expr ')'
688          {
689            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
690          }
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          }
699        ;
700
701exprlist:
702        exprlist ',' expr
703          {
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;
733          }
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          }
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:
814          expr PLUSPLUS     %prec PLUSPLUS
815          {
816            if(iiExprArith1(&$$,&$1,PLUSPLUS)) YYERROR;
817          }
818        | expr MINUSMINUS   %prec MINUSMINUS
819          {
820            if(iiExprArith1(&$$,&$1,MINUSMINUS)) YYERROR;
821          }
822        | expr '+' expr
823          {
824            if(iiExprArith2(&$$,&$1,'+',&$3)) YYERROR;
825          }
826        | expr '-' expr
827          {
828            if(iiExprArith2(&$$,&$1,'-',&$3)) YYERROR;
829          }
830        | expr '/' expr
831          {
832            if(iiExprArith2(&$$,&$1,$<i>2,&$3)) YYERROR;
833          }
834        | expr '^' expr
835          {
836            if(iiExprArith2(&$$,&$1,'^',&$3)) YYERROR;
837          }
838        | expr '<' expr
839          {
840            if(iiExprArith2(&$$,&$1,$<i>2,&$3)) YYERROR;
841          }
842        | expr '&' expr
843          {
844            if(iiExprArith2(&$$,&$1,$<i>2,&$3)) YYERROR;
845          }
846        | expr NOTEQUAL expr
847          {
848            if(iiExprArith2(&$$,&$1,NOTEQUAL,&$3)) YYERROR;
849          }
850        | expr EQUAL_EQUAL expr
851          {
852            if(iiExprArith2(&$$,&$1,EQUAL_EQUAL,&$3)) YYERROR;
853          }
854        | expr DOTDOT expr
855          {
856            if(iiExprArith2(&$$,&$1,DOTDOT,&$3)) YYERROR;
857          }
858        | expr ':' expr
859          {
860            if(iiExprArith2(&$$,&$1,':',&$3)) YYERROR;
861          }
862        | NOT expr
863          {
864            memset(&$$,0,sizeof($$));
865            int i; TESTSETINT($2,i);
866            $$.rtyp  = INT_CMD;
867            $$.data = (void *)(long)(i == 0 ? 1 : 0);
868          }
869        | '-' expr %prec UMINUS
870          {
871            if(iiExprArith1(&$$,&$2,'-')) YYERROR;
872          }
873        ;
874
875left_value:
876        declare_ip_variable cmdeq  { $$ = $1; }
877        | exprlist '='
878          {
879            if ($1.rtyp==0)
880            {
881              Werror("`%s` is undefined",$1.Fullname());
882              YYERROR;
883            }
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            }
890            $$ = $1;
891          }
892        ;
893
894
895extendedid:
896        UNKNOWN_IDENT
897        | '`' expr '`'
898          {
899            if ($2.Typ()!=STRING_CMD)
900            {
901              MYYERROR("string expression expected");
902            }
903            $$ = (char *)$2.CopyD(STRING_CMD);
904            $2.CleanUp();
905          }
906        ;
907
908declare_ip_variable:
909        ROOT_DECL elemexpr
910          {
911            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
912              YYERROR;
913          }
914        | ROOT_DECL_LIST elemexpr
915          {
916            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
917              YYERROR;
918          }
919        | RING_DECL elemexpr
920          {
921            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
922          }
923        | RING_DECL_LIST elemexpr
924          {
925            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
926          }
927        | mat_cmd elemexpr '[' expr ']' '[' expr ']'
928          {
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");
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);
963              IDBIMAT(h) = new bigintmat(r, c, coeffs_BIGINT);
964              if (IDBIMAT(h)==NULL) YYERROR;
965            }
966          }
967        | mat_cmd elemexpr
968          {
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 */
988            {
989              if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
990                YYERROR;
991            }
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            {
1000              if (iiDeclCommand(&r,&$3,myynest,t,&(currRing->idroot), TRUE))
1001                YYERROR;
1002            }
1003            else
1004            {
1005              if (iiDeclCommand(&r,&$3,myynest,t,&($3.req_packhdl->idroot)))
1006                YYERROR;
1007            }
1008            leftv v=&$1;
1009            while (v->next!=NULL) v=v->next;
1010            v->next=(leftv)omAllocBin(sleftv_bin);
1011            memcpy(v->next,&r,sizeof(sleftv));
1012            $$=$1;
1013          }
1014        | PROC_CMD elemexpr
1015          {
1016            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
1017              YYERROR;
1018          }
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            }
1034            v->next = (leftv)omAllocBin(sleftv_bin);
1035            memcpy(v->next,&($4),sizeof(sleftv));
1036            $$ = $2;
1037          }
1038        ;
1039
1040ordername:
1041        UNKNOWN_IDENT
1042        {
1043          // let rInit take care of any errors
1044          $$=rOrderName($1);
1045        }
1046        ;
1047
1048orderelem:
1049        ordername
1050          {
1051            memset(&$$,0,sizeof($$));
1052            intvec *iv = new intvec(2);
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;
1066              intvec *iv = new intvec(l);
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                {
1075                  (*iv)[i++] = (int)((long)(sl->Data()));
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;
1107            $$.next = (sleftv *)omAllocBin(sleftv_bin);
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
1126
1127mat_cmd: MATRIX_CMD
1128            { $$ = $1; }
1129        | INTMAT_CMD
1130            { $$ = $1; }
1131        | BIGINTMAT_CMD
1132            { $$ = $1; }
1133          ;
1134
1135/* --------------------------------------------------------------------*/
1136/* section of pure commands                                            */
1137/* --------------------------------------------------------------------*/
1138
1139filecmd:
1140        '<' stringexpr
1141          { if ($<i>1 != '<') YYERROR;
1142            if((feFilePending=feFopen($2,"r",NULL,TRUE))==NULL) YYERROR; }
1143        ';'
1144          { newFile($2,feFilePending); }
1145        ;
1146
1147helpcmd:
1148        HELP_CMD STRINGTOK ';'
1149          {
1150            feHelp($2);
1151            omFree((ADDRESS)$2);
1152          }
1153        | HELP_CMD ';'
1154          {
1155            feHelp(NULL);
1156          }
1157        ;
1158
1159examplecmd:
1160        EXAMPLE_CMD STRINGTOK ';'
1161          {
1162            singular_example($2);
1163            omFree((ADDRESS)$2);
1164          }
1165       ;
1166
1167exportcmd:
1168        EXPORT_CMD exprlist
1169        {
1170          if (basePack!=$2.req_packhdl)
1171          {
1172            if(iiExport(&$2,0,currPack)) YYERROR;
1173          }
1174          else
1175            if (iiExport(&$2,0)) YYERROR;
1176        }
1177        ;
1178
1179killcmd:
1180        KILL_CMD elemexpr
1181        {
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          }
1195        }
1196        | killcmd ',' elemexpr
1197        {
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          }
1211        }
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          }
1228        | LISTVAR_CMD '(' RING_DECL_LIST ')'
1229          {
1230            list_cmd($3,NULL,"// ",TRUE);
1231          }
1232        | LISTVAR_CMD '(' RING_CMD ')'
1233          {
1234            list_cmd(RING_CMD,NULL,"// ",TRUE);
1235          }
1236        | LISTVAR_CMD '(' mat_cmd ')'
1237          {
1238            list_cmd($3,NULL,"// ",TRUE);
1239           }
1240        | LISTVAR_CMD '(' PROC_CMD ')'
1241          {
1242            list_cmd(PROC_CMD,NULL,"// ",TRUE);
1243          }
1244        | LISTVAR_CMD '(' elemexpr ')'
1245          {
1246            list_cmd(0,$3.Fullname(),"// ",TRUE);
1247            $3.CleanUp();
1248          }
1249        | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL ')'
1250          {
1251            if($3.Typ() == PACKAGE_CMD)
1252              list_cmd($5,NULL,"// ",TRUE);
1253            $3.CleanUp();
1254          }
1255        | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL_LIST ')'
1256          {
1257            if($3.Typ() == PACKAGE_CMD)
1258              list_cmd($5,NULL,"// ",TRUE);
1259            $3.CleanUp();
1260          }
1261        | LISTVAR_CMD '(' elemexpr ',' RING_DECL ')'
1262          {
1263            if($3.Typ() == PACKAGE_CMD)
1264              list_cmd($5,NULL,"// ",TRUE);
1265            $3.CleanUp();
1266          }
1267        | LISTVAR_CMD '(' elemexpr ',' RING_DECL_LIST ')'
1268          {
1269            if($3.Typ() == PACKAGE_CMD)
1270              list_cmd($5,NULL,"// ",TRUE);
1271            $3.CleanUp();
1272          }
1273        | LISTVAR_CMD '(' elemexpr ',' RING_CMD ')'
1274          {
1275            if($3.Typ() == PACKAGE_CMD)
1276              list_cmd($5,NULL,"// ",TRUE);
1277            $3.CleanUp();
1278          }
1279        | LISTVAR_CMD '(' elemexpr ',' mat_cmd ')'
1280          {
1281            if($3.Typ() == PACKAGE_CMD)
1282              list_cmd($5,NULL,"// ",TRUE);
1283            $3.CleanUp();
1284          }
1285        | LISTVAR_CMD '(' elemexpr ',' PROC_CMD ')'
1286          {
1287            if($3.Typ() == PACKAGE_CMD)
1288              list_cmd($5,NULL,"// ",TRUE);
1289            $3.CleanUp();
1290          }
1291        //| LISTVAR_CMD '(' elemexpr ',' elemexpr ')'
1292        //  {
1293        //    //if($3.Typ() == PACKAGE_CMD)
1294        //    //  list_cmd($5,NULL,"// ",TRUE);
1295        //    $3.CleanUp();
1296        //  }
1297        | LISTVAR_CMD '(' ')'
1298          {
1299            list_cmd(-1,NULL,"// ",TRUE);
1300          }
1301        ;
1302
1303ringcmd1:
1304       RING_CMD { yyInRingConstruction = TRUE; }
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          {
1314            const char *ring_name = $2.name;
1315            ring b=
1316            rInit(&$4,            /* characteristik and list of parameters*/
1317                  &$6,            /* names of ringvariables */
1318                  &$8);            /* ordering */
1319            idhdl newRingHdl=NULL;
1320
1321            if (b!=NULL)
1322            {
1323              newRingHdl=enterid(ring_name, myynest, RING_CMD,
1324                                   &($2.req_packhdl->idroot),FALSE);
1325              $2.CleanUp();
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)
1337            {
1338              MYYERROR("cannot make ring");
1339            }
1340            else
1341            {
1342              rSetHdl(newRingHdl);
1343            }
1344          }
1345        | ringcmd1 elemexpr
1346          {
1347            const char *ring_name = $2.name;
1348            if (!inerror) rDefault(ring_name);
1349            yyInRingConstruction = FALSE;
1350            $2.CleanUp();
1351          }
1352        ;
1353
1354scriptcmd:
1355         SYSVAR stringexpr
1356          {
1357            if (($1!=LIB_CMD)||(jjLOAD($2,TRUE))) YYERROR;
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;
1373              if ($2.e!=NULL) h=rFindHdl((ring)$2.Data(),NULL, NULL);
1374              //Print("setring %s lev %d (ptr:%x)\n",IDID(h),IDLEV(h),IDRING(h));
1375              if ($1==KEEPRING_CMD)
1376              {
1377                if (h!=NULL)
1378                {
1379                  if (IDLEV(h)!=0)
1380                  {
1381                    if (iiExport(&$2,myynest-1)) YYERROR;
1382#if 1
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)
1389                      {
1390                        idhdl old=root->get(IDID(p),prevlev);
1391                        if (old!=NULL)
1392                        {
1393                          if (BVERBOSE(V_REDEFINE))
1394                            Warn("redefining %s",IDID(p));
1395                          killhdl2(old,&root,IDRING(h));
1396                          IDRING(h)->idroot=root;
1397                        }
1398                        IDLEV(p)=prevlev;
1399                      }
1400                      p=IDNEXT(p);
1401                    }
1402#endif
1403                  }
1404#ifdef USE_IILOCALRING
1405                  iiLocalRing[myynest-1]=IDRING(h);
1406#endif
1407                  procstack->cRing=IDRING(h);
1408                  procstack->cRingHdl=h;
1409                }
1410                else
1411                {
1412                  Werror("%s is no identifier",n);
1413                  $2.CleanUp();
1414                  YYERROR;
1415                }
1416              }
1417              if (h!=NULL) rSetHdl(h);
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          {
1438            type_cmd(&($2));
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);
1452                  omFree((ADDRESS)$1.name);
1453                }
1454                YYERROR;
1455              }
1456            #ifdef SIQ
1457            }
1458            #endif
1459            $1.Print(&sLastPrinted);
1460            $1.CleanUp(currRing);
1461            if (errorreported) YYERROR;
1462          }
1463        ;
1464
1465/* --------------------------------------------------------------------*/
1466/* section of flow control                                             */
1467/* --------------------------------------------------------------------*/
1468
1469ifcmd: IF_CMD '(' expr ')' BLOCKTOK
1470          {
1471            int i; TESTSETINT($3,i);
1472            if (i!=0)
1473            {
1474              newBuffer( $5, BT_if);
1475            }
1476            else
1477            {
1478              omFree((ADDRESS)$5);
1479              currentVoice->ifsw=1;
1480            }
1481          }
1482        | ELSE_CMD BLOCKTOK
1483          {
1484            if (currentVoice->ifsw==1)
1485            {
1486              currentVoice->ifsw=0;
1487              newBuffer( $2, BT_else);
1488            }
1489            else
1490            {
1491              if (currentVoice->ifsw!=2)
1492              {
1493                Warn("`else` without `if` in level %d",myynest);
1494              }
1495              omFree((ADDRESS)$2);
1496            }
1497            currentVoice->ifsw=0;
1498          }
1499        | IF_CMD '(' expr ')' BREAK_CMD
1500          {
1501            int i; TESTSETINT($3,i);
1502            if (i)
1503            {
1504              if (exitBuffer(BT_break)) YYERROR;
1505            }
1506            currentVoice->ifsw=0;
1507          }
1508        | BREAK_CMD
1509          {
1510            if (exitBuffer(BT_break)) YYERROR;
1511            currentVoice->ifsw=0;
1512          }
1513        | CONTINUE_CMD
1514          {
1515            if (contBuffer(BT_break)) YYERROR;
1516            currentVoice->ifsw=0;
1517          }
1518      ;
1519
1520whilecmd:
1521        WHILE_CMD STRINGTOK BLOCKTOK
1522          {
1523            /* -> if(!$2) break; $3; continue;*/
1524            char * s = (char *)omAlloc( strlen($2) + strlen($3) + 36);
1525            sprintf(s,"whileif (!(%s)) break;\n%scontinue;\n " ,$2,$3);
1526            newBuffer(s,BT_break);
1527            omFree((ADDRESS)$2);
1528            omFree((ADDRESS)$3);
1529          }
1530        ;
1531
1532forcmd:
1533        FOR_CMD STRINGTOK STRINGTOK STRINGTOK BLOCKTOK
1534          {
1535            /* $2 */
1536            /* if (!$3) break; $5; $4; continue; */
1537            char * s = (char *)omAlloc( strlen($3)+strlen($4)+strlen($5)+36);
1538            sprintf(s,"forif (!(%s)) break;\n%s%s;\ncontinue;\n "
1539                   ,$3,$5,$4);
1540            omFree((ADDRESS)$3);
1541            omFree((ADDRESS)$4);
1542            omFree((ADDRESS)$5);
1543            newBuffer(s,BT_break);
1544            s = (char *)omAlloc( strlen($2) + 3);
1545            sprintf(s,"%s;\n",$2);
1546            omFree((ADDRESS)$2);
1547            newBuffer(s,BT_if);
1548          }
1549        ;
1550
1551proccmd:
1552        PROC_CMD extendedid BLOCKTOK
1553          {
1554            idhdl h = enterid($2,myynest,PROC_CMD,&IDROOT,TRUE);
1555            if (h==NULL) {omFree((ADDRESS)$2);omFree((ADDRESS)$3); YYERROR;}
1556            iiInitSingularProcinfo(IDPROC(h),"", $2, 0, 0);
1557            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+31);;
1558            sprintf(IDPROC(h)->data.s.body,"parameter list #;\n%s;return();\n\n",$3);
1559            omFree((ADDRESS)$3);
1560            omFree((ADDRESS)$2);
1561          }
1562        | PROC_DEF STRINGTOK BLOCKTOK
1563          {
1564            idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE);
1565            if (h==NULL)
1566            {
1567              omFree((ADDRESS)$1);
1568              omFree((ADDRESS)$2);
1569              omFree((ADDRESS)$3);
1570              YYERROR;
1571            }
1572            char *args=iiProcArgs($2,FALSE);
1573            omFree((ADDRESS)$2);
1574            iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0);
1575            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+strlen(args)+14);;
1576            sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$3);
1577            omFree((ADDRESS)args);
1578            omFree((ADDRESS)$3);
1579            omFree((ADDRESS)$1);
1580          }
1581        | PROC_DEF STRINGTOK STRINGTOK BLOCKTOK
1582          {
1583            omFree((ADDRESS)$3);
1584            idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE);
1585            if (h==NULL)
1586            {
1587              omFree((ADDRESS)$1);
1588              omFree((ADDRESS)$2);
1589              omFree((ADDRESS)$4);
1590              YYERROR;
1591            }
1592            char *args=iiProcArgs($2,FALSE);
1593            omFree((ADDRESS)$2);
1594            iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0);
1595            omFree((ADDRESS)$1);
1596            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($4)+strlen(args)+14);;
1597            sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$4);
1598            omFree((ADDRESS)args);
1599            omFree((ADDRESS)$4);
1600          }
1601        ;
1602
1603parametercmd:
1604        PARAMETER declare_ip_variable
1605          {
1606            // decl. of type proc p(int i)
1607            if ($1==PARAMETER)  { if (iiParameter(&$2)) YYERROR; }
1608            else                { if (iiAlias(&$2)) YYERROR; }
1609          }
1610        | PARAMETER expr
1611          {
1612            // decl. of type proc p(i)
1613            sleftv tmp_expr;
1614            if ($1==ALIAS_CMD) MYYERROR("alias requires a type");
1615            if ((iiDeclCommand(&tmp_expr,&$2,myynest,DEF_CMD,&IDROOT))
1616            || (iiParameter(&tmp_expr)))
1617              YYERROR;
1618          }
1619        ;
1620
1621returncmd:
1622        RETURN '(' exprlist ')'
1623          {
1624            iiRETURNEXPR.Copy(&$3);
1625            $3.CleanUp();
1626            if (exitBuffer(BT_proc)) YYERROR;
1627          }
1628        | RETURN '(' ')'
1629          {
1630            if ($1==RETURN)
1631            {
1632              iiRETURNEXPR.Init();
1633              iiRETURNEXPR.rtyp=NONE;
1634              if (exitBuffer(BT_proc)) YYERROR;
1635            }
1636          }
1637        ;
Note: See TracBrowser for help on using the repository browser.