source: git/Singular/grammar.y @ bee06d

spielwiese
Last change on this file since bee06d was 4b889d, checked in by Hans Schoenemann <hannes@…>, 14 years ago
RTIMER simplification git-svn-id: file:///usr/local/Singular/svn/trunk@13480 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • 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 <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            if (!errorreported) WerrorS("...parse error");
430            yyerror("");
431            yyerrok;
432#ifdef HAVE_SDB
433            if ((sdb_flags & 1) && currentVoice->pi!=NULL)
434            {
435              currentVoice->pi->trace_flag |=1;
436            }
437            else
438#endif
439            if (myynest>0)
440            {
441              feBufferTypes t=currentVoice->Typ();
442              //PrintS("leaving yyparse\n");
443              exitBuffer(BT_proc);
444              if (t==BT_example)
445                YYACCEPT;
446              else
447                YYABORT;
448            }
449            else if (currentVoice->prev!=NULL)
450            {
451              exitVoice();
452            }
453#ifdef HAVE_SDB
454            if (sdb_flags &2) sdb_flags=1;
455#endif
456          }
457        ;
458
459flowctrl: ifcmd
460          | whilecmd
461          | example_dummy
462          | forcmd
463          | proccmd
464          | filecmd
465          | helpcmd
466          | examplecmd
467            {if (currentVoice!=NULL) currentVoice->ifsw=0;}
468        ;
469
470example_dummy : EXAMPLE_CMD BLOCKTOK { omFree((ADDRESS)$2); }
471        ;
472
473command: assign
474         | exportcmd
475         | killcmd
476         | listcmd
477         | parametercmd
478         | ringcmd
479         | scriptcmd
480         | setringcmd
481         | typecmd
482         ;
483
484assign: left_value exprlist
485          {
486            if(iiAssign(&$1,&$2)) YYERROR;
487          }
488        ;
489
490elemexpr:
491        RINGVAR
492          {
493            if (currRing==NULL) MYYERROR("no ring active");
494            syMake(&$$,omStrDup($1));
495          }
496        | extendedid
497          {
498            syMake(&$$,$1);
499          }
500        | elemexpr COLONCOLON elemexpr
501          {
502            if(iiExprArith2(&$$, &$1, COLONCOLON, &$3)) YYERROR;
503          }
504        | elemexpr '('  ')'
505          {
506            if(iiExprArith1(&$$,&$1,'(')) YYERROR;
507          }
508        | elemexpr '(' exprlist ')'
509          {
510            if ($1.rtyp==LIB_CMD)
511            {
512              if(iiExprArith1(&$$,&$3,LIB_CMD)) YYERROR;
513            }
514            else
515            {
516              if ($1.Typ()==UNKNOWN)
517              {
518                if(iiExprArith2(&$$,&$1,'(',&$3)) YYERROR;
519              }
520              else
521              {
522                $1.next=(leftv)omAllocBin(sleftv_bin);
523                memcpy($1.next,&$3,sizeof(sleftv));
524                if(iiExprArithM(&$$,&$1,'(')) YYERROR;
525              }
526            }
527          }
528        | '[' exprlist ']'
529          {
530            if (currRingHdl==NULL) MYYERROR("no ring active");
531            int j = 0;
532            memset(&$$,0,sizeof(sleftv));
533            $$.rtyp=VECTOR_CMD;
534            leftv v = &$2;
535            while (v!=NULL)
536            {
537              int i,t;
538              sleftv tmp;
539              memset(&tmp,0,sizeof(tmp));
540              i=iiTestConvert((t=v->Typ()),POLY_CMD);
541              if((i==0) || (iiConvert(t /*v->Typ()*/,POLY_CMD,i,v,&tmp)))
542              {
543                pDelete((poly *)&$$.data);
544                $2.CleanUp();
545                MYYERROR("expected '[poly,...'");
546              }
547              poly p = (poly)tmp.CopyD(POLY_CMD);
548              pSetCompP(p,++j);
549              $$.data = (void *)pAdd((poly)$$.data,p);
550              v->next=tmp.next;tmp.next=NULL;
551              tmp.CleanUp();
552              v=v->next;
553            }
554            $2.CleanUp();
555          }
556        | INT_CONST
557          {
558            memset(&$$,0,sizeof($$));
559            int i = atoi($1);
560            /*remember not to omFree($1)
561            *because it is a part of the scanner buffer*/
562            $$.rtyp  = INT_CMD;
563            $$.data = (void *)(long)i;
564
565            /* check: out of range input */
566            int l = strlen($1)+2;
567            number n;
568            if (l >= MAX_INT_LEN)
569            {
570              char tmp[MAX_INT_LEN+5];
571              sprintf(tmp,"%d",i);
572              if (strcmp(tmp,$1)!=0)
573              {
574                nlRead($1,&n);
575                $$.rtyp=BIGINT_CMD;
576                $$.data = n;
577              }
578            }
579          }
580        | SYSVAR
581          {
582            memset(&$$,0,sizeof($$));
583            $$.rtyp = $1;
584            $$.data = $$.Data();
585          }
586        | stringexpr
587          {
588            memset(&$$,0,sizeof($$));
589            $$.rtyp  = STRING_CMD;
590            $$.data = $1;
591          }
592        ;
593
594exprlist:
595        exprlist ',' expr
596          {
597            leftv v = &$1;
598            while (v->next!=NULL)
599            {
600              v=v->next;
601            }
602            v->next = (leftv)omAllocBin(sleftv_bin);
603            memcpy(v->next,&($3),sizeof(sleftv));
604            $$ = $1;
605          }
606        | expr
607          {
608            $$ = $1;
609          }
610        ;
611
612expr:   expr_arithmetic
613          {
614            /*if ($1.typ == eunknown) YYERROR;*/
615            $$ = $1;
616          }
617        | elemexpr       { $$ = $1; }
618        | '(' exprlist ')'    { $$ = $2; }
619        | expr '[' expr ',' expr ']'
620          {
621            if(iiExprArith3(&$$,'[',&$1,&$3,&$5)) YYERROR;
622          }
623        | expr '[' expr ']'
624          {
625            if(iiExprArith2(&$$,&$1,'[',&$3)) YYERROR;
626          }
627        | ROOT_DECL '(' expr ')'
628          {
629            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
630          }
631        | ROOT_DECL_LIST '(' exprlist ')'
632          {
633            if(iiExprArithM(&$$,&$3,$1)) YYERROR;
634          }
635        | ROOT_DECL_LIST '(' ')'
636          {
637            if(iiExprArithM(&$$,NULL,$1)) YYERROR;
638          }
639        | RING_DECL '(' expr ')'
640          {
641            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
642          }
643        | currring_lists '(' exprlist ')'
644          {
645            if(iiExprArithM(&$$,&$3,$1)) YYERROR;
646          }
647        | currring_lists '(' ')'
648          {
649            if(iiExprArithM(&$$,NULL,$1)) YYERROR;
650          }
651        | CMD_1 '(' expr ')'
652          {
653            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
654          }
655        | CMD_2 '(' expr ',' expr ')'
656          {
657            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
658          }
659        | CMD_3 '(' expr ',' expr ',' expr ')'
660          {
661            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
662          }
663        | CMD_23 '(' expr ',' expr ')'
664          {
665            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
666          }
667        | CMD_23 '(' expr ',' expr ',' expr ')'
668          {
669            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
670          }
671        | CMD_12 '(' expr ')'
672          {
673            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
674          }
675        | CMD_13 '(' expr ')'
676          {
677            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
678          }
679        | CMD_12 '(' expr ',' expr ')'
680          {
681            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
682          }
683        | CMD_123 '(' expr ')'
684          {
685            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
686          }
687        | CMD_123 '(' expr ',' expr ')'
688          {
689            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
690          }
691        | CMD_13 '(' expr ',' expr ',' expr ')'
692          {
693            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
694          }
695        | CMD_123 '(' expr ',' expr ',' expr ')'
696          {
697            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
698          }
699        | CMD_M '(' ')'
700          {
701            if(iiExprArithM(&$$,NULL,$1)) YYERROR;
702          }
703        | CMD_M '(' exprlist ')'
704          {
705            if(iiExprArithM(&$$,&$3,$1)) YYERROR;
706          }
707        | MATRIX_CMD '(' expr ',' expr ',' expr ')'
708          {
709            if(iiExprArith3(&$$,MATRIX_CMD,&$3,&$5,&$7)) YYERROR;
710          }
711        | MATRIX_CMD '(' expr ')'
712          {
713            if(iiExprArith1(&$$,&$3,MATRIX_CMD)) YYERROR;
714          }
715        | INTMAT_CMD '(' expr ',' expr ',' expr ')'
716          {
717            if(iiExprArith3(&$$,INTMAT_CMD,&$3,&$5,&$7)) YYERROR;
718          }
719        | INTMAT_CMD '(' expr ')'
720          {
721            if(iiExprArith1(&$$,&$3,INTMAT_CMD)) YYERROR;
722          }
723        | RING_CMD '(' rlist ',' rlist ',' ordering ')'
724          {
725            if(iiExprArith3(&$$,RING_CMD,&$3,&$5,&$7)) YYERROR;
726          }
727        | RING_CMD '(' expr ')'
728          {
729            if(iiExprArith1(&$$,&$3,RING_CMD)) YYERROR;
730          }
731        | quote_start expr quote_end
732          {
733            $$=$2;
734          }
735        | quote_start expr '=' expr quote_end
736          {
737            #ifdef SIQ
738            siq++;
739            if (siq>0)
740            { if (iiExprArith2(&$$,&$2,'=',&$4)) YYERROR; }
741            else
742            #endif
743            {
744              memset(&$$,0,sizeof($$));
745              $$.rtyp=NONE;
746              if (iiAssign(&$2,&$4)) YYERROR;
747            }
748            #ifdef SIQ
749            siq--;
750            #endif
751          }
752        | EVAL  '('
753          {
754            #ifdef SIQ
755            siq--;
756            #endif
757          }
758          expr ')'
759          {
760            #ifdef SIQ
761            if (siq<=0) $4.Eval();
762            #endif
763            $$=$4;
764            #ifdef SIQ
765            siq++;
766            #endif
767          }
768          ;
769
770quote_start:    QUOTE  '('
771          {
772            #ifdef SIQ
773            siq++;
774            #endif
775          }
776          ;
777
778quote_end: ')'
779          {
780            #ifdef SIQ
781            siq--;
782            #endif
783          }
784          ;
785
786expr_arithmetic:
787          expr PLUSPLUS     %prec PLUSPLUS
788          {
789            if(iiExprArith1(&$$,&$1,PLUSPLUS)) YYERROR;
790          }
791        | expr MINUSMINUS   %prec MINUSMINUS
792          {
793            if(iiExprArith1(&$$,&$1,MINUSMINUS)) YYERROR;
794          }
795        | expr '+' expr
796          {
797            if(iiExprArith2(&$$,&$1,'+',&$3)) YYERROR;
798          }
799        | expr '-' expr
800          {
801            if(iiExprArith2(&$$,&$1,'-',&$3)) YYERROR;
802          }
803        | expr '/' expr
804          {
805            if(iiExprArith2(&$$,&$1,$<i>2,&$3)) YYERROR;
806          }
807        | expr '^' expr
808          {
809            if(iiExprArith2(&$$,&$1,'^',&$3)) YYERROR;
810          }
811        | expr '<' expr
812          {
813            if(iiExprArith2(&$$,&$1,$<i>2,&$3)) YYERROR;
814          }
815        | expr '&' expr
816          {
817            if(iiExprArith2(&$$,&$1,$<i>2,&$3)) YYERROR;
818          }
819        | expr NOTEQUAL expr
820          {
821            if(iiExprArith2(&$$,&$1,NOTEQUAL,&$3)) YYERROR;
822          }
823        | expr EQUAL_EQUAL expr
824          {
825            if(iiExprArith2(&$$,&$1,EQUAL_EQUAL,&$3)) YYERROR;
826          }
827        | expr DOTDOT expr
828          {
829            if(iiExprArith2(&$$,&$1,DOTDOT,&$3)) YYERROR;
830          }
831        | expr ':' expr
832          {
833            if(iiExprArith2(&$$,&$1,':',&$3)) YYERROR;
834          }
835        | NOT expr
836          {
837            memset(&$$,0,sizeof($$));
838            int i; TESTSETINT($2,i);
839            $$.rtyp  = INT_CMD;
840            $$.data = (void *)(long)(i == 0 ? 1 : 0);
841          }
842        | '-' expr %prec UMINUS
843          {
844            if(iiExprArith1(&$$,&$2,'-')) YYERROR;
845          }
846        ;
847
848left_value:
849        declare_ip_variable cmdeq  { $$ = $1; }
850        | exprlist '='
851          {
852            if ($1.rtyp==0)
853            {
854              Werror("`%s` is undefined",$1.Fullname());
855              YYERROR;
856            }
857            else if (($1.rtyp==MODUL_CMD)
858            // matrix m; m[2]=...
859            && ($1.e!=NULL) && ($1.e->next==NULL))
860            {
861              MYYERROR("matrix must have 2 indices");
862            }
863            $$ = $1;
864          }
865        ;
866
867
868extendedid:
869        UNKNOWN_IDENT
870        | '`' expr '`'
871          {
872            if ($2.Typ()!=STRING_CMD)
873            {
874              MYYERROR("string expression expected");
875            }
876            $$ = (char *)$2.CopyD(STRING_CMD);
877            $2.CleanUp();
878          }
879        ;
880
881currring_lists:
882        IDEAL_CMD | MODUL_CMD
883        /* put variables into the current ring */
884        ;
885
886declare_ip_variable:
887        ROOT_DECL elemexpr
888          {
889            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
890              YYERROR;
891          }
892        | ROOT_DECL_LIST elemexpr
893          {
894            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
895              YYERROR;
896          }
897        | RING_DECL elemexpr
898          {
899            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
900          }
901        | currring_lists elemexpr
902          {
903            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
904          }
905        | MATRIX_CMD elemexpr '[' expr ']' '[' expr ']'
906          {
907            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
908            int r; TESTSETINT($4,r);
909            int c; TESTSETINT($7,c);
910            if (r < 1)
911              MYYERROR("rows must be greater than 0");
912            if (c < 0)
913              MYYERROR("cols must be greater than -1");
914            leftv v=&$$;
915            //while (v->next!=NULL) { v=v->next; }
916            idhdl h=(idhdl)v->data;
917            idDelete(&IDIDEAL(h));
918            IDMATRIX(h) = mpNew(r,c);
919            if (IDMATRIX(h)==NULL) YYERROR;
920          }
921        | MATRIX_CMD elemexpr
922          {
923            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
924          }
925        | INTMAT_CMD elemexpr '[' expr ']' '[' expr ']'
926          {
927            int r; TESTSETINT($4,r);
928            int c; TESTSETINT($7,c);
929            if (r < 1)
930              MYYERROR("rows must be greater than 0");
931            if (c < 0)
932              MYYERROR("cols must be greater than -1");
933            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
934              YYERROR;
935            leftv v=&$$;
936            idhdl h=(idhdl)v->data;
937            delete IDINTVEC(h);
938            IDINTVEC(h) = new intvec(r,c,0);
939            if (IDINTVEC(h)==NULL) YYERROR;
940          }
941        | INTMAT_CMD elemexpr
942          {
943            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
944              YYERROR;
945            leftv v=&$$;
946            idhdl h;
947            do
948            {
949               h=(idhdl)v->data;
950               delete IDINTVEC(h);
951               IDINTVEC(h) = new intvec(1,1,0);
952               v=v->next;
953            } while (v!=NULL);
954          }
955        | declare_ip_variable ',' elemexpr
956          {
957            int t=$1.Typ();
958            sleftv r;
959            memset(&r,0,sizeof(sleftv));
960            if ((BEGIN_RING<t) && (t<END_RING))
961            {
962              if (iiDeclCommand(&r,&$3,myynest,t,&(currRing->idroot), TRUE))
963                YYERROR;
964            }
965            else
966            {
967              if (iiDeclCommand(&r,&$3,myynest,t,&($3.req_packhdl->idroot)))
968                YYERROR;
969            }
970            leftv v=&$1;
971            while (v->next!=NULL) v=v->next;
972            v->next=(leftv)omAllocBin(sleftv_bin);
973            memcpy(v->next,&r,sizeof(sleftv));
974            $$=$1;
975          }
976        | PROC_CMD elemexpr
977          {
978            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
979              YYERROR;
980          }
981        ;
982
983stringexpr:
984        STRINGTOK
985        ;
986
987rlist:
988        expr
989        | '(' expr ',' exprlist ')'
990          {
991            leftv v = &$2;
992            while (v->next!=NULL)
993            {
994              v=v->next;
995            }
996            v->next = (leftv)omAllocBin(sleftv_bin);
997            memcpy(v->next,&($4),sizeof(sleftv));
998            $$ = $2;
999          }
1000        ;
1001
1002ordername:
1003        UNKNOWN_IDENT
1004        {
1005          // let rInit take care of any errors
1006          $$=rOrderName($1);
1007        }
1008        ;
1009
1010orderelem:
1011        ordername
1012          {
1013            memset(&$$,0,sizeof($$));
1014            intvec *iv = new intvec(2);
1015            (*iv)[0] = 1;
1016            (*iv)[1] = $1;
1017            $$.rtyp = INTVEC_CMD;
1018            $$.data = (void *)iv;
1019          }
1020        | ordername '(' exprlist ')'
1021          {
1022            memset(&$$,0,sizeof($$));
1023            leftv sl = &$3;
1024            int slLength;
1025            {
1026              slLength =  exprlist_length(sl);
1027              int l = 2 +  slLength;
1028              intvec *iv = new intvec(l);
1029              (*iv)[0] = slLength;
1030              (*iv)[1] = $1;
1031
1032              int i = 2;
1033              while ((i<l) && (sl!=NULL))
1034              {
1035                if (sl->Typ() == INT_CMD)
1036                {
1037                  (*iv)[i++] = (int)((long)(sl->Data()));
1038                }
1039                else if ((sl->Typ() == INTVEC_CMD)
1040                ||(sl->Typ() == INTMAT_CMD))
1041                {
1042                  intvec *ivv = (intvec *)(sl->Data());
1043                  int ll = 0,l = ivv->length();
1044                  for (; l>0; l--)
1045                  {
1046                    (*iv)[i++] = (*ivv)[ll++];
1047                  }
1048                }
1049                else
1050                {
1051                  delete iv;
1052                  $3.CleanUp();
1053                  MYYERROR("wrong type in ordering");
1054                }
1055                sl = sl->next;
1056              }
1057              $$.rtyp = INTVEC_CMD;
1058              $$.data = (void *)iv;
1059            }
1060            $3.CleanUp();
1061          }
1062        ;
1063
1064OrderingList:
1065        orderelem
1066        |  orderelem ',' OrderingList
1067          {
1068            $$ = $1;
1069            $$.next = (sleftv *)omAllocBin(sleftv_bin);
1070            memcpy($$.next,&$3,sizeof(sleftv));
1071          }
1072        ;
1073
1074ordering:
1075        orderelem
1076        | '(' OrderingList ')'
1077          {
1078            $$ = $2;
1079          }
1080        ;
1081
1082cmdeq:  '='
1083          {
1084            expected_parms = TRUE;
1085          }
1086        ;
1087
1088
1089/* --------------------------------------------------------------------*/
1090/* section of pure commands                                            */
1091/* --------------------------------------------------------------------*/
1092
1093filecmd:
1094        '<' stringexpr
1095          { if ($<i>1 != '<') YYERROR;
1096            if((feFilePending=feFopen($2,"r",NULL,TRUE))==NULL) YYERROR; }
1097        ';'
1098          { newFile($2,feFilePending); }
1099        ;
1100
1101helpcmd:
1102        HELP_CMD STRINGTOK ';'
1103          {
1104            feHelp($2);
1105            omFree((ADDRESS)$2);
1106          }
1107        | HELP_CMD ';'
1108          {
1109            feHelp(NULL);
1110          }
1111        ;
1112
1113examplecmd:
1114        EXAMPLE_CMD STRINGTOK ';'
1115          {
1116            singular_example($2);
1117            omFree((ADDRESS)$2);
1118          }
1119       ;
1120
1121exportcmd:
1122        EXPORT_CMD exprlist
1123        {
1124          if (basePack!=$2.req_packhdl)
1125          {
1126            if(iiExport(&$2,0,currPackHdl)) YYERROR;
1127          }
1128          else
1129            if (iiExport(&$2,0)) YYERROR;
1130        }
1131        ;
1132
1133killcmd:
1134        KILL_CMD elemexpr
1135        {
1136          leftv v=&$2;
1137          if (v->rtyp!=IDHDL)
1138          {
1139            if (v->name!=NULL)
1140            {
1141               Werror("`%s` is undefined in kill",v->name);
1142            }
1143            else               WerrorS("kill what ?");
1144          }
1145          else
1146          {
1147            killhdl((idhdl)v->data,v->req_packhdl);
1148          }
1149        }
1150        | killcmd ',' elemexpr
1151        {
1152          leftv v=&$3;
1153          if (v->rtyp!=IDHDL)
1154          {
1155            if (v->name!=NULL)
1156            {
1157               Werror("`%s` is undefined in kill",v->name);
1158            }
1159            else               WerrorS("kill what ?");
1160          }
1161          else
1162          {
1163            killhdl((idhdl)v->data,v->req_packhdl);
1164          }
1165        }
1166        ;
1167
1168listcmd:
1169        LISTVAR_CMD '(' ROOT_DECL ')'
1170          {
1171            list_cmd($3,NULL,"// ",TRUE);
1172          }
1173        | LISTVAR_CMD '(' ROOT_DECL_LIST ')'
1174          {
1175            list_cmd($3,NULL,"// ",TRUE);
1176          }
1177        | LISTVAR_CMD '(' RING_DECL ')'
1178          {
1179            if ($3==QRING_CMD) $3=RING_CMD;
1180            list_cmd($3,NULL,"// ",TRUE);
1181          }
1182        | LISTVAR_CMD '(' currring_lists ')'
1183          {
1184            list_cmd($3,NULL,"// ",TRUE);
1185          }
1186        | LISTVAR_CMD '(' RING_CMD ')'
1187          {
1188            list_cmd(RING_CMD,NULL,"// ",TRUE);
1189          }
1190        | LISTVAR_CMD '(' MATRIX_CMD ')'
1191          {
1192            list_cmd(MATRIX_CMD,NULL,"// ",TRUE);
1193           }
1194        | LISTVAR_CMD '(' INTMAT_CMD ')'
1195          {
1196            list_cmd(INTMAT_CMD,NULL,"// ",TRUE);
1197          }
1198        | LISTVAR_CMD '(' PROC_CMD ')'
1199          {
1200            list_cmd(PROC_CMD,NULL,"// ",TRUE);
1201          }
1202        | LISTVAR_CMD '(' elemexpr ')'
1203          {
1204            list_cmd(0,$3.Fullname(),"// ",TRUE);
1205            $3.CleanUp();
1206          }
1207        | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL ')'
1208          {
1209            if($3.Typ() == PACKAGE_CMD)
1210              list_cmd($5,NULL,"// ",TRUE);
1211            $3.CleanUp();
1212          }
1213        | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL_LIST ')'
1214          {
1215            if($3.Typ() == PACKAGE_CMD)
1216              list_cmd($5,NULL,"// ",TRUE);
1217            $3.CleanUp();
1218          }
1219        | LISTVAR_CMD '(' elemexpr ',' RING_DECL ')'
1220          {
1221            if($3.Typ() == PACKAGE_CMD)
1222              list_cmd($5,NULL,"// ",TRUE);
1223            $3.CleanUp();
1224          }
1225        | LISTVAR_CMD '(' elemexpr ',' currring_lists ')'
1226          {
1227            if($3.Typ() == PACKAGE_CMD)
1228              list_cmd($5,NULL,"// ",TRUE);
1229            $3.CleanUp();
1230          }
1231        | LISTVAR_CMD '(' elemexpr ',' RING_CMD ')'
1232          {
1233            if($3.Typ() == PACKAGE_CMD)
1234              list_cmd($5,NULL,"// ",TRUE);
1235            $3.CleanUp();
1236          }
1237        | LISTVAR_CMD '(' elemexpr ',' MATRIX_CMD ')'
1238          {
1239            if($3.Typ() == PACKAGE_CMD)
1240              list_cmd($5,NULL,"// ",TRUE);
1241            $3.CleanUp();
1242          }
1243        | LISTVAR_CMD '(' elemexpr ',' INTMAT_CMD ')'
1244          {
1245            if($3.Typ() == PACKAGE_CMD)
1246              list_cmd($5,NULL,"// ",TRUE);
1247            $3.CleanUp();
1248          }
1249        | LISTVAR_CMD '(' elemexpr ',' PROC_CMD ')'
1250          {
1251            if($3.Typ() == PACKAGE_CMD)
1252              list_cmd($5,NULL,"// ",TRUE);
1253            $3.CleanUp();
1254          }
1255        //| LISTVAR_CMD '(' elemexpr ',' elemexpr ')'
1256        //  {
1257        //    //if($3.Typ() == PACKAGE_CMD)
1258        //    //  list_cmd($5,NULL,"// ",TRUE);
1259        //    $3.CleanUp();
1260        //  }
1261        | LISTVAR_CMD '(' ')'
1262          {
1263            list_cmd(-1,NULL,"// ",TRUE);
1264          }
1265        ;
1266
1267ringcmd1:
1268       RING_CMD { yyInRingConstruction = TRUE; }
1269       ;
1270
1271ringcmd:
1272        ringcmd1
1273          elemexpr cmdeq
1274          rlist     ','      /* description of coeffs */
1275          rlist     ','      /* var names */
1276          ordering           /* list of (multiplier ordering (weight(s))) */
1277          {
1278            const char *ring_name = $2.name;
1279            ring b=
1280            rInit(&$4,            /* characteristik and list of parameters*/
1281                  &$6,            /* names of ringvariables */
1282                  &$8);            /* ordering */
1283            idhdl newRingHdl=NULL;
1284
1285            if (b!=NULL)
1286            {
1287                newRingHdl=enterid(ring_name, myynest, RING_CMD,
1288                                   &($2.req_packhdl->idroot));
1289              $2.CleanUp();
1290              if (newRingHdl!=NULL)
1291              {
1292                omFreeSize(IDRING(newRingHdl),sizeof(ip_sring));
1293                IDRING(newRingHdl)=b;
1294              }
1295              else
1296              {
1297                rKill(b);
1298              }
1299            }
1300            yyInRingConstruction = FALSE;
1301            if (newRingHdl==NULL)
1302            {
1303              MYYERROR("cannot make ring");
1304            }
1305            else
1306            {
1307              rSetHdl(newRingHdl);
1308            }
1309          }
1310        | ringcmd1 elemexpr
1311          {
1312            const char *ring_name = $2.name;
1313            if (!inerror) rDefault(ring_name);
1314            yyInRingConstruction = FALSE;
1315            $2.CleanUp();
1316          }
1317        ;
1318
1319scriptcmd:
1320         SYSVAR stringexpr
1321          {
1322            if (($1!=LIB_CMD)||(iiLibCmd($2,TRUE,TRUE,TRUE)))
1323            //if ($1==LIB_CMD)
1324            //{
1325            //  sleftv tmp;
1326            //  if(iiExprArith1(&tmp,&$2,LIB_CMD)) YYERROR;
1327            //}
1328            //else
1329                YYERROR;
1330          }
1331        ;
1332
1333setrings:  SETRING_CMD | KEEPRING_CMD ;
1334
1335setringcmd:
1336        setrings expr
1337          {
1338            if (($1==KEEPRING_CMD) && (myynest==0))
1339               MYYERROR("only inside a proc allowed");
1340            const char * n=$2.Name();
1341            if ((($2.Typ()==RING_CMD)||($2.Typ()==QRING_CMD))
1342            && ($2.rtyp==IDHDL))
1343            {
1344              idhdl h=(idhdl)$2.data;
1345              if ($2.e!=NULL) h=rFindHdl((ring)$2.Data(),NULL, NULL);
1346              //Print("setring %s lev %d (ptr:%x)\n",IDID(h),IDLEV(h),IDRING(h));
1347              if ($1==KEEPRING_CMD)
1348              {
1349                if (h!=NULL)
1350                {
1351                  if (IDLEV(h)!=0)
1352                  {
1353                    if (iiExport(&$2,myynest-1)) YYERROR;
1354#if 1
1355                    idhdl p=IDRING(h)->idroot;
1356                    idhdl root=p;
1357                    int prevlev=myynest-1;
1358                    while (p!=NULL)
1359                    {
1360                      if (IDLEV(p)==myynest)
1361                      {
1362                        idhdl old=root->get(IDID(p),prevlev);
1363                        if (old!=NULL)
1364                        {
1365                          if (BVERBOSE(V_REDEFINE))
1366                            Warn("redefining %s",IDID(p));
1367                          killhdl2(old,&root,IDRING(h));
1368                          IDRING(h)->idroot=root;
1369                        }
1370                        IDLEV(p)=prevlev;
1371                      }
1372                      p=IDNEXT(p);
1373                    }
1374#endif
1375                  }
1376#ifdef USE_IILOCALRING
1377                  iiLocalRing[myynest-1]=IDRING(h);
1378#endif
1379                  procstack->cRing=IDRING(h);
1380                  procstack->cRingHdl=h;
1381                }
1382                else
1383                {
1384                  Werror("%s is no identifier",n);
1385                  $2.CleanUp();
1386                  YYERROR;
1387                }
1388              }
1389              if (h!=NULL) rSetHdl(h);
1390              else
1391              {
1392                Werror("cannot find the name of the basering %s",n);
1393                $2.CleanUp();
1394                YYERROR;
1395              }
1396              $2.CleanUp();
1397            }
1398            else
1399            {
1400              Werror("%s is no name of a ring/qring",n);
1401              $2.CleanUp();
1402              YYERROR;
1403            }
1404          }
1405        ;
1406
1407typecmd:
1408        TYPE_CMD expr
1409          {
1410            if ($2.rtyp!=IDHDL) MYYERROR("identifier expected");
1411            idhdl h = (idhdl)$2.data;
1412            type_cmd(h);
1413          }
1414        | exprlist
1415          {
1416            //Print("typ is %d, rtyp:%d\n",$1.Typ(),$1.rtyp);
1417            #ifdef SIQ
1418            if ($1.rtyp!=COMMAND)
1419            {
1420            #endif
1421              if ($1.Typ()==UNKNOWN)
1422              {
1423                if ($1.name!=NULL)
1424                {
1425                  Werror("`%s` is undefined",$1.name);
1426                  omFree((ADDRESS)$1.name);
1427                }
1428                YYERROR;
1429              }
1430            #ifdef SIQ
1431            }
1432            #endif
1433            $1.Print(&sLastPrinted);
1434            $1.CleanUp(currRing);
1435            if (errorreported) YYERROR;
1436          }
1437        ;
1438
1439/* --------------------------------------------------------------------*/
1440/* section of flow control                                             */
1441/* --------------------------------------------------------------------*/
1442
1443ifcmd: IF_CMD '(' expr ')' BLOCKTOK
1444          {
1445            int i; TESTSETINT($3,i);
1446            if (i!=0)
1447            {
1448              newBuffer( $5, BT_if);
1449            }
1450            else
1451            {
1452              omFree((ADDRESS)$5);
1453              currentVoice->ifsw=1;
1454            }
1455          }
1456        | ELSE_CMD BLOCKTOK
1457          {
1458            if (currentVoice->ifsw==1)
1459            {
1460              currentVoice->ifsw=0;
1461              newBuffer( $2, BT_else);
1462            }
1463            else
1464            {
1465              if (currentVoice->ifsw!=2)
1466              {
1467                Warn("`else` without `if` in level %d",myynest);
1468              }
1469              omFree((ADDRESS)$2);
1470            }
1471            currentVoice->ifsw=0;
1472          }
1473        | IF_CMD '(' expr ')' BREAK_CMD
1474          {
1475            int i; TESTSETINT($3,i);
1476            if (i)
1477            {
1478              if (exitBuffer(BT_break)) YYERROR;
1479            }
1480            currentVoice->ifsw=0;
1481          }
1482        | BREAK_CMD
1483          {
1484            if (exitBuffer(BT_break)) YYERROR;
1485            currentVoice->ifsw=0;
1486          }
1487        | CONTINUE_CMD
1488          {
1489            if (contBuffer(BT_break)) YYERROR;
1490            currentVoice->ifsw=0;
1491          }
1492      ;
1493
1494whilecmd:
1495        WHILE_CMD STRINGTOK BLOCKTOK
1496          {
1497            /* -> if(!$2) break; $3; continue;*/
1498            char * s = (char *)omAlloc( strlen($2) + strlen($3) + 36);
1499            sprintf(s,"whileif (!(%s)) break;\n%scontinue;\n " ,$2,$3);
1500            newBuffer(s,BT_break);
1501            omFree((ADDRESS)$2);
1502            omFree((ADDRESS)$3);
1503          }
1504        ;
1505
1506forcmd:
1507        FOR_CMD STRINGTOK STRINGTOK STRINGTOK BLOCKTOK
1508          {
1509            /* $2 */
1510            /* if (!$3) break; $5; $4; continue; */
1511            char * s = (char *)omAlloc( strlen($3)+strlen($4)+strlen($5)+36);
1512            sprintf(s,"forif (!(%s)) break;\n%s%s;\ncontinue;\n "
1513                   ,$3,$5,$4);
1514            omFree((ADDRESS)$3);
1515            omFree((ADDRESS)$4);
1516            omFree((ADDRESS)$5);
1517            newBuffer(s,BT_break);
1518            s = (char *)omAlloc( strlen($2) + 3);
1519            sprintf(s,"%s;\n",$2);
1520            omFree((ADDRESS)$2);
1521            newBuffer(s,BT_if);
1522          }
1523        ;
1524
1525proccmd:
1526        PROC_CMD extendedid BLOCKTOK
1527          {
1528            procinfov pi;
1529            idhdl h = enterid($2,myynest,PROC_CMD,&IDROOT,TRUE);
1530            if (h==NULL) {omFree((ADDRESS)$2);omFree((ADDRESS)$3); YYERROR;}
1531            iiInitSingularProcinfo(IDPROC(h),"", $2, 0, 0);
1532            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+31);;
1533            sprintf(IDPROC(h)->data.s.body,"parameter list #;\n%s;return();\n\n",$3);
1534            omFree((ADDRESS)$3);
1535            omFree((ADDRESS)$2);
1536          }
1537        | PROC_DEF STRINGTOK BLOCKTOK
1538          {
1539            idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE);
1540            if (h==NULL)
1541            {
1542              omFree((ADDRESS)$1);
1543              omFree((ADDRESS)$2);
1544              omFree((ADDRESS)$3);
1545              YYERROR;
1546            }
1547            char *args=iiProcArgs($2,FALSE);
1548            omFree((ADDRESS)$2);
1549            procinfov pi;
1550            iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0);
1551            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+strlen(args)+14);;
1552            sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$3);
1553            omFree((ADDRESS)args);
1554            omFree((ADDRESS)$3);
1555            omFree((ADDRESS)$1);
1556          }
1557        | PROC_DEF STRINGTOK STRINGTOK BLOCKTOK
1558          {
1559            omFree((ADDRESS)$3);
1560            idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE);
1561            if (h==NULL)
1562            {
1563              omFree((ADDRESS)$1);
1564              omFree((ADDRESS)$2);
1565              omFree((ADDRESS)$4);
1566              YYERROR;
1567            }
1568            char *args=iiProcArgs($2,FALSE);
1569            omFree((ADDRESS)$2);
1570            procinfov pi;
1571            iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0);
1572            omFree((ADDRESS)$1);
1573            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($4)+strlen(args)+14);;
1574            sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$4);
1575            omFree((ADDRESS)args);
1576            omFree((ADDRESS)$4);
1577          }
1578        ;
1579
1580parametercmd:
1581        PARAMETER declare_ip_variable
1582          {
1583            // decl. of type proc p(int i)
1584            if ($1==PARAMETER)  { if (iiParameter(&$2)) YYERROR; }
1585            else                { if (iiAlias(&$2)) YYERROR; }
1586          }
1587        | PARAMETER expr
1588          {
1589            // decl. of type proc p(i)
1590            sleftv tmp_expr;
1591            if ($1==ALIAS_CMD) MYYERROR("alias requires a type");
1592            if ((iiDeclCommand(&tmp_expr,&$2,myynest,DEF_CMD,&IDROOT))
1593            || (iiParameter(&tmp_expr)))
1594              YYERROR;
1595          }
1596        ;
1597
1598returncmd:
1599        RETURN '(' exprlist ')'
1600          {
1601            if(iiRETURNEXPR==NULL) YYERROR;
1602            iiRETURNEXPR[myynest].Copy(&$3);
1603            $3.CleanUp();
1604            if (exitBuffer(BT_proc)) YYERROR;
1605          }
1606        | RETURN '(' ')'
1607          {
1608            if ($1==RETURN)
1609            {
1610              if(iiRETURNEXPR==NULL) YYERROR;
1611              iiRETURNEXPR[myynest].Init();
1612              iiRETURNEXPR[myynest].rtyp=NONE;
1613              if (exitBuffer(BT_proc)) YYERROR;
1614            }
1615          }
1616        ;
Note: See TracBrowser for help on using the repository browser.