source: git/Singular/grammar.y @ f69c6c

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