source: git/Singular/grammar.y @ 22f6bc

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