source: git/Singular/grammar.y @ 894057

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