source: git/Singular/grammar.y @ 971e31

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