source: git/Singular/grammar.y @ 111cfe

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