source: git/Singular/grammar.y @ ea947e

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