source: git/Singular/grammar.y @ ba5e9e

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