source: git/Singular/grammar.y @ 16f511

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