source: git/Singular/grammar.y @ fe02b1

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