source: git/Singular/grammar.y @ 206e202

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