source: git/Singular/grammar.y @ fb8ba27

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