source: git/Singular/grammar.y @ 84a6a7

spielwiese
Last change on this file since 84a6a7 was 22ed4c, checked in by Hans Schönemann <hannes@…>, 19 years ago
*hannes: fixed LIB(...) git-svn-id: file:///usr/local/Singular/svn/trunk@8662 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.117 2005-09-24 15:02:03 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)((long)(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        ;
475
476command: assign
477         | exportcmd
478         | killcmd
479         | listcmd
480         | parametercmd
481         | ringcmd
482         | scriptcmd
483         | setringcmd
484         | typecmd
485         ;
486
487assign: left_value exprlist
488          {
489            if(iiAssign(&$1,&$2)) YYERROR;
490          }
491        ;
492
493elemexpr:
494        RINGVAR
495          {
496            if (currRing==NULL) MYYERROR("no ring active");
497            syMake(&$$,omStrDup($1));
498          }
499        | extendedid
500          {
501            syMake(&$$,$1);
502          }
503        | elemexpr COLONCOLON elemexpr
504          {
505            if(iiExprArith2(&$$, &$1, COLONCOLON, &$3)) YYERROR;
506          }
507        | elemexpr '('  ')'
508          {
509            if(iiExprArith1(&$$,&$1,'(')) YYERROR;
510          }
511        | elemexpr '(' exprlist ')'
512          {
513            if ($1.rtyp==LIB_CMD)
514            {
515              if(iiExprArith1(&$$,&$3,LIB_CMD)) YYERROR;
516            }
517            else
518            {
519              if ($1.Typ()==UNKNOWN)
520              {
521                if(iiExprArith2(&$$,&$1,'(',&$3)) YYERROR;
522              }
523              else
524              {
525                $1.next=(leftv)omAllocBin(sleftv_bin);
526                memcpy($1.next,&$3,sizeof(sleftv));
527                if(iiExprArithM(&$$,&$1,'(')) YYERROR;
528              }
529            }
530          }
531        | '[' exprlist ']'
532          {
533            if (currRingHdl==NULL) MYYERROR("no ring active");
534            int j = 0;
535            memset(&$$,0,sizeof(sleftv));
536            $$.rtyp=VECTOR_CMD;
537            leftv v = &$2;
538            while (v!=NULL)
539            {
540              int i,t;
541              sleftv tmp;
542              memset(&tmp,0,sizeof(tmp));
543              i=iiTestConvert((t=v->Typ()),POLY_CMD);
544              if((i==0) || (iiConvert(t /*v->Typ()*/,POLY_CMD,i,v,&tmp)))
545              {
546                pDelete((poly *)&$$.data);
547                $2.CleanUp();
548                MYYERROR("expected '[poly,...'");
549              }
550              poly p = (poly)tmp.CopyD(POLY_CMD);
551              pSetCompP(p,++j);
552              $$.data = (void *)pAdd((poly)$$.data,p);
553              v->next=tmp.next;tmp.next=NULL;
554              tmp.CleanUp();
555              v=v->next;
556            }
557            $2.CleanUp();
558          }
559        | INT_CONST
560          {
561            memset(&$$,0,sizeof($$));
562            int i = atoi($1);
563            /*remember not to omFree($1)
564            *because it is a part of the scanner buffer*/
565            $$.rtyp  = INT_CMD;
566            $$.data = (void *)i;
567
568            /* check: out of range input */
569            int l = strlen($1)+2;
570            if (l >= MAX_INT_LEN)
571            {
572              char tmp[MAX_INT_LEN+5];
573              sprintf(tmp,"%d",i);
574              if (strcmp(tmp,$1)!=0)
575              {
576                if (currRing==NULL)
577                {
578                  Werror("`%s` greater than %d(max. integer representation)"
579                         ,$1,MAX_INT_VAL);
580                  YYERROR;
581                }
582                char *t1=omStrDup($1);
583                syMake(&$$,t1);
584              }
585            }
586          }
587        | SYSVAR
588          {
589            memset(&$$,0,sizeof($$));
590            $$.rtyp = $1;
591            $$.data = $$.Data();
592          }
593        | stringexpr
594          {
595            memset(&$$,0,sizeof($$));
596            $$.rtyp  = STRING_CMD;
597            $$.data = $1;
598          }
599        ;
600
601exprlist:
602        exprlist ',' expr
603          {
604            leftv v = &$1;
605            while (v->next!=NULL)
606            {
607              v=v->next;
608            }
609            v->next = (leftv)omAllocBin(sleftv_bin);
610            memcpy(v->next,&($3),sizeof(sleftv));
611            $$ = $1;
612          }
613        | expr
614          {
615            $$ = $1;
616          }
617        ;
618
619expr:   expr_arithmetic
620          {
621            /*if ($1.typ == eunknown) YYERROR;*/
622            $$ = $1;
623          }
624        | elemexpr       { $$ = $1; }
625        | '(' exprlist ')'    { $$ = $2; }
626        | expr '[' expr ',' expr ']'
627          {
628            if(iiExprArith3(&$$,'[',&$1,&$3,&$5)) YYERROR;
629          }
630        | expr '[' expr ']'
631          {
632            if(iiExprArith2(&$$,&$1,'[',&$3)) YYERROR;
633          }
634        | ROOT_DECL '(' expr ')'
635          {
636            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
637          }
638        | ROOT_DECL_LIST '(' exprlist ')'
639          {
640            if(iiExprArithM(&$$,&$3,$1)) YYERROR;
641          }
642        | ROOT_DECL_LIST '(' ')'
643          {
644            if(iiExprArithM(&$$,NULL,$1)) YYERROR;
645          }
646        | RING_DECL '(' expr ')'
647          {
648            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
649          }
650        | currring_lists '(' exprlist ')'
651          {
652            if(iiExprArithM(&$$,&$3,$1)) YYERROR;
653          }
654        | currring_lists '(' ')'
655          {
656            if(iiExprArithM(&$$,NULL,$1)) YYERROR;
657          }
658        | CMD_1 '(' expr ')'
659          {
660            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
661          }
662        | CMD_2 '(' expr ',' expr ')'
663          {
664            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
665          }
666        | CMD_3 '(' expr ',' expr ',' expr ')'
667          {
668            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
669          }
670        | CMD_23 '(' expr ',' expr ')'
671          {
672            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
673          }
674        | CMD_23 '(' expr ',' expr ',' expr ')'
675          {
676            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
677          }
678        | CMD_12 '(' expr ')'
679          {
680            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
681          }
682        | CMD_13 '(' expr ')'
683          {
684            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
685          }
686        | CMD_12 '(' expr ',' expr ')'
687          {
688            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
689          }
690        | CMD_123 '(' expr ')'
691          {
692            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
693          }
694        | CMD_123 '(' expr ',' expr ')'
695          {
696            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
697          }
698        | CMD_13 '(' expr ',' expr ',' expr ')'
699          {
700            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
701          }
702        | CMD_123 '(' expr ',' expr ',' expr ')'
703          {
704            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
705          }
706        | CMD_M '(' ')'
707          {
708            if(iiExprArithM(&$$,NULL,$1)) YYERROR;
709          }
710        | CMD_M '(' exprlist ')'
711          {
712            if(iiExprArithM(&$$,&$3,$1)) YYERROR;
713          }
714        | MATRIX_CMD '(' expr ',' expr ',' expr ')'
715          {
716            if(iiExprArith3(&$$,MATRIX_CMD,&$3,&$5,&$7)) YYERROR;
717          }
718        | MATRIX_CMD '(' expr ')'
719          {
720            if(iiExprArith1(&$$,&$3,MATRIX_CMD)) YYERROR;
721          }
722        | INTMAT_CMD '(' expr ',' expr ',' expr ')'
723          {
724            if(iiExprArith3(&$$,INTMAT_CMD,&$3,&$5,&$7)) YYERROR;
725          }
726        | INTMAT_CMD '(' expr ')'
727          {
728            if(iiExprArith1(&$$,&$3,INTMAT_CMD)) YYERROR;
729          }
730        | RING_CMD '(' rlist ',' rlist ',' ordering ')'
731          {
732            if(iiExprArith3(&$$,RING_CMD,&$3,&$5,&$7)) YYERROR;
733          }
734        | RING_CMD '(' expr ')'
735          {
736            if(iiExprArith1(&$$,&$3,RING_CMD)) YYERROR;
737          }
738        | quote_start expr quote_end
739          {
740            $$=$2;
741          }
742        | quote_start expr '=' expr quote_end
743          {
744            #ifdef SIQ
745            siq++;
746            if (siq>0)
747            { if (iiExprArith2(&$$,&$2,'=',&$4)) YYERROR; }
748            else
749            #endif
750            {
751              memset(&$$,0,sizeof($$));
752              $$.rtyp=NONE;
753              if (iiAssign(&$2,&$4)) YYERROR;
754            }
755            #ifdef SIQ
756            siq--;
757            #endif
758          }
759        | EVAL  '('
760          {
761            #ifdef SIQ
762            siq--;
763            #endif
764          }
765          expr ')'
766          {
767            #ifdef SIQ
768            if (siq<=0) $4.Eval();
769            #endif
770            $$=$4;
771            #ifdef SIQ
772            siq++;
773            #endif
774          }
775          ;
776
777quote_start:    QUOTE  '('
778          {
779            #ifdef SIQ
780            siq++;
781            #endif
782          }
783          ;
784
785quote_end: ')'
786          {
787            #ifdef SIQ
788            siq--;
789            #endif
790          }
791          ;
792
793expr_arithmetic:
794          expr PLUSPLUS     %prec PLUSPLUS
795          {
796            if(iiExprArith1(&$$,&$1,PLUSPLUS)) YYERROR;
797          }
798        | expr MINUSMINUS   %prec MINUSMINUS
799          {
800            if(iiExprArith1(&$$,&$1,MINUSMINUS)) YYERROR;
801          }
802        | expr '+' expr
803          {
804            if(iiExprArith2(&$$,&$1,'+',&$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,'^',&$3)) YYERROR;
817          }
818        | expr '<' expr
819          {
820            if(iiExprArith2(&$$,&$1,$<i>2,&$3)) YYERROR;
821          }
822        | expr '&' expr
823          {
824            if(iiExprArith2(&$$,&$1,$<i>2,&$3)) YYERROR;
825          }
826        | expr NOTEQUAL expr
827          {
828            if(iiExprArith2(&$$,&$1,NOTEQUAL,&$3)) YYERROR;
829          }
830        | expr EQUAL_EQUAL expr
831          {
832            if(iiExprArith2(&$$,&$1,EQUAL_EQUAL,&$3)) YYERROR;
833          }
834        | expr DOTDOT expr
835          {
836            if(iiExprArith2(&$$,&$1,DOTDOT,&$3)) YYERROR;
837          }
838        | NOT expr
839          {
840            memset(&$$,0,sizeof($$));
841            int i; TESTSETINT($2,i);
842            $$.rtyp  = INT_CMD;
843            $$.data = (void *)(i == 0 ? 1 : 0);
844          }
845        | '-' expr %prec UMINUS
846          {
847            if(iiExprArith1(&$$,&$2,'-')) YYERROR;
848          }
849        ;
850
851left_value:
852        declare_ip_variable cmdeq  { $$ = $1; }
853        | exprlist '='
854          {
855            if ($1.rtyp==0)
856            {
857              Werror("`%s` is undefined",$1.Fullname());
858              YYERROR;
859            }
860            $$ = $1;
861          }
862        ;
863
864
865extendedid:
866        UNKNOWN_IDENT
867        | '`' expr '`'
868          {
869            if ($2.Typ()!=STRING_CMD)
870            {
871              MYYERROR("string expression expected");
872            }
873            $$ = (char *)$2.CopyD(STRING_CMD);
874            $2.CleanUp();
875          }
876        ;
877
878currring_lists:
879        IDEAL_CMD | MODUL_CMD
880        /* put variables into the current ring */
881        ;
882
883declare_ip_variable:
884        ROOT_DECL elemexpr
885          {
886            #ifdef HAVE_NS
887            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
888              YYERROR;
889            #else
890            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
891            #endif
892          }
893        | ROOT_DECL_LIST elemexpr
894          {
895            #ifdef HAVE_NS
896            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
897              YYERROR;
898            #else
899            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
900            #endif
901          }
902        | RING_DECL elemexpr
903          {
904            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
905          }
906        | currring_lists elemexpr
907          {
908            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
909          }
910        | MATRIX_CMD elemexpr '[' expr ']' '[' expr ']'
911          {
912            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
913            int r; TESTSETINT($4,r);
914            int c; TESTSETINT($7,c);
915            if (r < 1)
916              MYYERROR("rows must be greater than 0");
917            if (c < 0)
918              MYYERROR("cols must be greater than -1");
919            leftv v=&$$;
920            //while (v->next!=NULL) { v=v->next; }
921            idhdl h=(idhdl)v->data;
922            idDelete(&IDIDEAL(h));
923            IDMATRIX(h) = mpNew(r,c);
924            if (IDMATRIX(h)==NULL) YYERROR;
925          }
926        | MATRIX_CMD elemexpr
927          {
928            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
929          }
930        | INTMAT_CMD elemexpr '[' expr ']' '[' expr ']'
931          {
932            int r; TESTSETINT($4,r);
933            int c; TESTSETINT($7,c);
934            if (r < 1)
935              MYYERROR("rows must be greater than 0");
936            if (c < 0)
937              MYYERROR("cols must be greater than -1");
938            #ifdef HAVE_NS
939            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
940              YYERROR;
941            #else
942            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
943            #endif
944            leftv v=&$$;
945            idhdl h=(idhdl)v->data;
946            delete IDINTVEC(h);
947            IDINTVEC(h) = new intvec(r,c,0);
948            if (IDINTVEC(h)==NULL) YYERROR;
949          }
950        | INTMAT_CMD elemexpr
951          {
952            #ifdef HAVE_NS
953            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
954              YYERROR;
955            #else
956            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
957            #endif
958            leftv v=&$$;
959            idhdl h;
960            do
961            {
962               h=(idhdl)v->data;
963               delete IDINTVEC(h);
964               IDINTVEC(h) = new intvec(1,1,0);
965               v=v->next;
966            } while (v!=NULL);
967          }
968        | declare_ip_variable ',' elemexpr
969          {
970            int t=$1.Typ();
971            sleftv r;
972            memset(&r,0,sizeof(sleftv));
973            if ((BEGIN_RING<t) && (t<END_RING))
974            {
975              if (iiDeclCommand(&r,&$3,myynest,t,&(currRing->idroot), TRUE))
976                YYERROR;
977            }
978            else
979            {
980              #ifdef HAVE_NS
981              if (iiDeclCommand(&r,&$3,myynest,t,&($3.req_packhdl->idroot)))
982                YYERROR;
983              #else
984              if (iiDeclCommand(&r,&$3,myynest,t,&IDROOT)) YYERROR;
985              #endif
986            }
987            leftv v=&$1;
988            while (v->next!=NULL) v=v->next;
989            v->next=(leftv)omAllocBin(sleftv_bin);
990            memcpy(v->next,&r,sizeof(sleftv));
991            $$=$1;
992          }
993        | PROC_CMD elemexpr
994          {
995            #ifdef HAVE_NS
996            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
997              YYERROR;
998            #else
999            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
1000            #endif
1001          }
1002        ;
1003
1004stringexpr:
1005        STRINGTOK
1006        ;
1007
1008rlist:
1009        expr
1010        | '(' expr ',' exprlist ')'
1011          {
1012            leftv v = &$2;
1013            while (v->next!=NULL)
1014            {
1015              v=v->next;
1016            }
1017            v->next = (leftv)omAllocBin(sleftv_bin);
1018            memcpy(v->next,&($4),sizeof(sleftv));
1019            $$ = $2;
1020          }
1021        ;
1022
1023ordername:
1024        UNKNOWN_IDENT
1025        {
1026          // let rInit take care of any errors
1027          $$=rOrderName($1);
1028        }
1029        ;
1030
1031orderelem:
1032        ordername
1033          {
1034            memset(&$$,0,sizeof($$));
1035            intvec *iv = new intvec(2);
1036            (*iv)[0] = 1;
1037            (*iv)[1] = $1;
1038            $$.rtyp = INTVEC_CMD;
1039            $$.data = (void *)iv;
1040          }
1041        | ordername '(' exprlist ')'
1042          {
1043            memset(&$$,0,sizeof($$));
1044            leftv sl = &$3;
1045            int slLength;
1046            {
1047              slLength =  exprlist_length(sl);
1048              int l = 2 +  slLength;
1049              intvec *iv = new intvec(l);
1050              (*iv)[0] = slLength;
1051              (*iv)[1] = $1;
1052
1053              int i = 2;
1054              while ((i<l) && (sl!=NULL))
1055              {
1056                if (sl->Typ() == INT_CMD)
1057                {
1058                  (*iv)[i++] = (int)((long)(sl->Data()));
1059                }
1060                else if ((sl->Typ() == INTVEC_CMD)
1061                ||(sl->Typ() == INTMAT_CMD))
1062                {
1063                  intvec *ivv = (intvec *)(sl->Data());
1064                  int ll = 0,l = ivv->length();
1065                  for (; l>0; l--)
1066                  {
1067                    (*iv)[i++] = (*ivv)[ll++];
1068                  }
1069                }
1070                else
1071                {
1072                  delete iv;
1073                  $3.CleanUp();
1074                  MYYERROR("wrong type in ordering");
1075                }
1076                sl = sl->next;
1077              }
1078              $$.rtyp = INTVEC_CMD;
1079              $$.data = (void *)iv;
1080            }
1081            $3.CleanUp();
1082          }
1083        ;
1084
1085OrderingList:
1086        orderelem
1087        |  orderelem ',' OrderingList
1088          {
1089            $$ = $1;
1090            $$.next = (sleftv *)omAllocBin(sleftv_bin);
1091            memcpy($$.next,&$3,sizeof(sleftv));
1092          }
1093        ;
1094
1095ordering:
1096        orderelem
1097        | '(' OrderingList ')'
1098          {
1099            $$ = $2;
1100          }
1101        ;
1102
1103cmdeq:  '='
1104          {
1105            expected_parms = TRUE;
1106          }
1107        ;
1108
1109
1110/* --------------------------------------------------------------------*/
1111/* section of pure commands                                            */
1112/* --------------------------------------------------------------------*/
1113
1114filecmd:
1115        '<' stringexpr
1116          { if ($<i>1 != '<') YYERROR;
1117            if((feFilePending=feFopen($2,"r",NULL,TRUE))==NULL) YYERROR; }
1118        ';'
1119          { newFile($2,feFilePending); }
1120        ;
1121
1122helpcmd:
1123        HELP_CMD STRINGTOK ';'
1124          {
1125            feHelp($2);
1126            omFree((ADDRESS)$2);
1127          }
1128        | HELP_CMD ';'
1129          {
1130            feHelp(NULL);
1131          }
1132        ;
1133
1134examplecmd:
1135        EXAMPLE_CMD STRINGTOK ';'
1136          {
1137            singular_example($2);
1138            omFree((ADDRESS)$2);
1139          }
1140       ;
1141
1142exportcmd:
1143        EXPORT_CMD exprlist
1144        {
1145#ifdef HAVE_NS
1146          if (basePack!=$2.req_packhdl)
1147          {
1148            if(iiExport(&$2,0,currPackHdl)) YYERROR;
1149          }
1150          else
1151#endif /* HAVE_NS */
1152            if (iiExport(&$2,0)) YYERROR;
1153        }
1154        ;
1155
1156killcmd:
1157        KILL_CMD elemexpr
1158        {
1159          leftv v=&$2;
1160          if (v->rtyp!=IDHDL)
1161          {
1162            if (v->name!=NULL)
1163            {
1164               Werror("`%s` is undefined in kill",v->name);
1165            }
1166            else               WerrorS("kill what ?");
1167          }
1168          else
1169          {
1170            #ifdef HAVE_NS
1171            killhdl((idhdl)v->data,v->req_packhdl);
1172            #else
1173            killhdl((idhdl)v->data);
1174            #endif
1175          }
1176        }
1177        | killcmd ',' elemexpr
1178        {
1179          leftv v=&$3;
1180          if (v->rtyp!=IDHDL)
1181          {
1182            if (v->name!=NULL)
1183            {
1184               Werror("`%s` is undefined in kill",v->name);
1185            }
1186            else               WerrorS("kill what ?");
1187          }
1188          else
1189          {
1190            #ifdef HAVE_NS
1191            killhdl((idhdl)v->data,v->req_packhdl);
1192            #else
1193            killhdl((idhdl)v->data);
1194            #endif
1195          }
1196        }
1197        ;
1198
1199listcmd:
1200        LISTVAR_CMD '(' ROOT_DECL ')'
1201          {
1202            list_cmd($3,NULL,"// ",TRUE);
1203          }
1204        | LISTVAR_CMD '(' ROOT_DECL_LIST ')'
1205          {
1206            list_cmd($3,NULL,"// ",TRUE);
1207          }
1208        | LISTVAR_CMD '(' RING_DECL ')'
1209          {
1210            if ($3==QRING_CMD) $3=RING_CMD;
1211            list_cmd($3,NULL,"// ",TRUE);
1212          }
1213        | LISTVAR_CMD '(' currring_lists ')'
1214          {
1215            list_cmd($3,NULL,"// ",TRUE);
1216          }
1217        | LISTVAR_CMD '(' RING_CMD ')'
1218          {
1219            list_cmd(RING_CMD,NULL,"// ",TRUE);
1220          }
1221        | LISTVAR_CMD '(' MATRIX_CMD ')'
1222          {
1223            list_cmd(MATRIX_CMD,NULL,"// ",TRUE);
1224           }
1225        | LISTVAR_CMD '(' INTMAT_CMD ')'
1226          {
1227            list_cmd(INTMAT_CMD,NULL,"// ",TRUE);
1228          }
1229        | LISTVAR_CMD '(' PROC_CMD ')'
1230          {
1231            list_cmd(PROC_CMD,NULL,"// ",TRUE);
1232          }
1233        | LISTVAR_CMD '(' elemexpr ')'
1234          {
1235            list_cmd(0,$3.Fullname(),"// ",TRUE);
1236            $3.CleanUp();
1237          }
1238        | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL ')'
1239          {
1240#ifdef HAVE_NS
1241            PrintS("?????\n");
1242            if($3.Typ() == PACKAGE_CMD)
1243              list_cmd($5,NULL,"// ",TRUE);
1244#endif /* HAVE_NS */
1245            $3.CleanUp();
1246          }
1247        | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL_LIST ')'
1248          {
1249#ifdef HAVE_NS
1250            PrintS("?????\n");
1251            if($3.Typ() == PACKAGE_CMD)
1252              list_cmd($5,NULL,"// ",TRUE);
1253#endif /* HAVE_NS */
1254            $3.CleanUp();
1255          }
1256        | LISTVAR_CMD '(' elemexpr ',' RING_DECL ')'
1257          {
1258#ifdef HAVE_NS
1259            PrintS("?????\n");
1260            if($3.Typ() == PACKAGE_CMD)
1261              list_cmd($5,NULL,"// ",TRUE);
1262#endif /* HAVE_NS */
1263            $3.CleanUp();
1264          }
1265        | LISTVAR_CMD '(' elemexpr ',' currring_lists ')'
1266          {
1267#ifdef HAVE_NS
1268            PrintS("?????\n");
1269            if($3.Typ() == PACKAGE_CMD)
1270              list_cmd($5,NULL,"// ",TRUE);
1271#endif /* HAVE_NS */
1272            $3.CleanUp();
1273          }
1274        | LISTVAR_CMD '(' elemexpr ',' RING_CMD ')'
1275          {
1276#ifdef HAVE_NS
1277            PrintS("?????\n");
1278            if($3.Typ() == PACKAGE_CMD)
1279              list_cmd($5,NULL,"// ",TRUE);
1280#endif /* HAVE_NS */
1281            $3.CleanUp();
1282          }
1283        | LISTVAR_CMD '(' elemexpr ',' MATRIX_CMD ')'
1284          {
1285#ifdef HAVE_NS
1286            PrintS("?????\n");
1287            if($3.Typ() == PACKAGE_CMD)
1288              list_cmd($5,NULL,"// ",TRUE);
1289#endif /* HAVE_NS */
1290            $3.CleanUp();
1291          }
1292        | LISTVAR_CMD '(' elemexpr ',' INTMAT_CMD ')'
1293          {
1294#ifdef HAVE_NS
1295            PrintS("?????\n");
1296            if($3.Typ() == PACKAGE_CMD)
1297              list_cmd($5,NULL,"// ",TRUE);
1298#endif /* HAVE_NS */
1299            $3.CleanUp();
1300          }
1301        | LISTVAR_CMD '(' elemexpr ',' PROC_CMD ')'
1302          {
1303#ifdef HAVE_NS
1304            PrintS("?????\n");
1305            if($3.Typ() == PACKAGE_CMD)
1306              list_cmd($5,NULL,"// ",TRUE);
1307#endif /* HAVE_NS */
1308            $3.CleanUp();
1309          }
1310        | LISTVAR_CMD '(' elemexpr ',' elemexpr ')'
1311          {
1312#ifdef HAVE_NS
1313            PrintS("?????\n");
1314            //if($3.Typ() == PACKAGE_CMD)
1315            //  list_cmd($5,NULL,"// ",TRUE);
1316#endif /* HAVE_NS */
1317            $3.CleanUp();
1318          }
1319        | LISTVAR_CMD '(' ')'
1320          {
1321            list_cmd(-1,NULL,"// ",TRUE);
1322          }
1323        ;
1324
1325ringcmd1:
1326       RING_CMD { yyInRingConstruction = TRUE; }
1327       ;
1328
1329ringcmd:
1330        ringcmd1
1331          elemexpr cmdeq
1332          rlist     ','      /* description of coeffs */
1333          rlist     ','      /* var names */
1334          ordering           /* list of (multiplier ordering (weight(s))) */
1335          {
1336            BOOLEAN do_pop = FALSE;
1337            char *ring_name = $2.name;
1338            ring b=
1339            rInit(&$4,            /* characteristik and list of parameters*/
1340                  &$6,            /* names of ringvariables */
1341                  &$8);            /* ordering */
1342            idhdl newRingHdl=NULL;
1343            if (b!=NULL)
1344            {
1345              newRingHdl=enterid(ring_name, myynest, RING_CMD, &IDROOT);
1346              $2.CleanUp();
1347              if (newRingHdl!=NULL)
1348              {
1349                omFreeSize(IDRING(newRingHdl),sizeof(ip_sring));
1350                IDRING(newRingHdl)=b;
1351              }
1352              else
1353              {
1354                rKill(b);
1355              }
1356            }
1357            yyInRingConstruction = FALSE;
1358            if (newRingHdl==NULL)
1359            {
1360              MYYERROR("cannot make ring");
1361            }
1362            else
1363            {
1364              rSetHdl(newRingHdl);
1365            }
1366          }
1367        | ringcmd1 elemexpr
1368          {
1369            BOOLEAN do_pop = FALSE;
1370            char *ring_name = $2.name;
1371            if (!inerror) rDefault(ring_name);
1372            yyInRingConstruction = FALSE;
1373            $2.CleanUp();
1374          }
1375        ;
1376
1377scriptcmd:
1378         SYSVAR stringexpr
1379          {
1380            if (($1!=LIB_CMD)||(iiLibCmd($2,TRUE,TRUE,TRUE)))
1381            //if ($1==LIB_CMD)
1382            //{
1383            //  sleftv tmp;
1384            //  if(iiExprArith1(&tmp,&$2,LIB_CMD)) YYERROR;
1385            //}
1386            //else
1387                YYERROR;
1388          }
1389        ;
1390
1391setrings:  SETRING_CMD | KEEPRING_CMD ;
1392
1393setringcmd:
1394        setrings expr
1395          {
1396            if (($1==KEEPRING_CMD) && (myynest==0))
1397               MYYERROR("only inside a proc allowed");
1398            const char * n=$2.Name();
1399            if ((($2.Typ()==RING_CMD)||($2.Typ()==QRING_CMD))
1400            && ($2.rtyp==IDHDL))
1401            {
1402              idhdl h=(idhdl)$2.data;
1403              if ($2.e!=NULL) h=rFindHdl((ring)$2.Data(),NULL, NULL);
1404              //Print("setring %s lev %d (ptr:%x)\n",IDID(h),IDLEV(h),IDRING(h));
1405              if ($1==KEEPRING_CMD)
1406              {
1407                if (h!=NULL)
1408                {
1409                  if (IDLEV(h)!=0)
1410                  {
1411                    if (iiExport(&$2,myynest-1)) YYERROR;
1412#if 1
1413                    //if (TEST_OPT_KEEPVARS)
1414                    //{
1415                      idhdl p=IDRING(h)->idroot;
1416                      idhdl root=p;
1417                      int prevlev=myynest-1;
1418                      while (p!=NULL)
1419                      {
1420                        if (IDLEV(p)==myynest)
1421                        {
1422                          idhdl old=root->get(IDID(p),prevlev);
1423                          if (old!=NULL)
1424                          {
1425                            if (BVERBOSE(V_REDEFINE))
1426                              Warn("redefining %s",IDID(p));
1427                            killhdl2(old,&root,IDRING(h));
1428                            IDRING(h)->idroot=root;
1429                          }
1430                          IDLEV(p)=prevlev;
1431                        }
1432                        p=IDNEXT(p);
1433                      }
1434                      //IDRING(h)->idroot=root;
1435#endif
1436                    //}
1437                  }
1438#ifdef USE_IILOCALRING
1439                  iiLocalRing[myynest-1]=IDRING(h);
1440#endif
1441                  procstack->cRing=IDRING(h);
1442                  procstack->cRingHdl=h;
1443                }
1444                else
1445                {
1446                  Werror("%s is no identifier",n);
1447                  $2.CleanUp();
1448                  YYERROR;
1449                }
1450              }
1451              if (h!=NULL) rSetHdl(h);
1452              else
1453              {
1454                Werror("cannot find the name of the basering %s",n);
1455                $2.CleanUp();
1456                YYERROR;
1457              }
1458              $2.CleanUp();
1459            }
1460            else
1461            {
1462              Werror("%s is no name of a ring/qring",n);
1463              $2.CleanUp();
1464              YYERROR;
1465            }
1466          }
1467        ;
1468
1469typecmd:
1470        TYPE_CMD expr
1471          {
1472            if ($2.rtyp!=IDHDL) MYYERROR("identifier expected");
1473            idhdl h = (idhdl)$2.data;
1474            type_cmd(h);
1475          }
1476        | exprlist
1477          {
1478            //Print("typ is %d, rtyp:%d\n",$1.Typ(),$1.rtyp);
1479            #ifdef SIQ
1480            if ($1.rtyp!=COMMAND)
1481            {
1482            #endif
1483              if ($1.Typ()==UNKNOWN)
1484              {
1485                if ($1.name!=NULL)
1486                {
1487                  Werror("`%s` is undefined",$1.name);
1488                  omFree((ADDRESS)$1.name);
1489                }
1490                YYERROR;
1491              }
1492            #ifdef SIQ
1493            }
1494            #endif
1495            $1.Print(&sLastPrinted);
1496            $1.CleanUp(currRing);
1497            if (errorreported) YYERROR;
1498          }
1499        ;
1500
1501/* --------------------------------------------------------------------*/
1502/* section of flow control                                             */
1503/* --------------------------------------------------------------------*/
1504
1505ifcmd: IF_CMD '(' expr ')' BLOCKTOK
1506          {
1507            int i; TESTSETINT($3,i);
1508            if (i!=0)
1509            {
1510              newBuffer( $5, BT_if);
1511            }
1512            else
1513            {
1514              omFree((ADDRESS)$5);
1515              currentVoice->ifsw=1;
1516            }
1517          }
1518        | ELSE_CMD BLOCKTOK
1519          {
1520            if (currentVoice->ifsw==1)
1521            {
1522              currentVoice->ifsw=0;
1523              newBuffer( $2, BT_else);
1524            }
1525            else
1526            {
1527              if (currentVoice->ifsw!=2)
1528              {
1529                Warn("`else` without `if` in level %d",myynest);
1530              }
1531              omFree((ADDRESS)$2);
1532            }
1533            currentVoice->ifsw=0;
1534          }
1535        | IF_CMD '(' expr ')' BREAK_CMD
1536          {
1537            int i; TESTSETINT($3,i);
1538            if (i)
1539            {
1540              if (exitBuffer(BT_break)) YYERROR;
1541            }
1542            currentVoice->ifsw=0;
1543          }
1544        | BREAK_CMD
1545          {
1546            if (exitBuffer(BT_break)) YYERROR;
1547            currentVoice->ifsw=0;
1548          }
1549        | CONTINUE_CMD
1550          {
1551            if (contBuffer(BT_break)) YYERROR;
1552            currentVoice->ifsw=0;
1553          }
1554      ;
1555
1556whilecmd:
1557        WHILE_CMD STRINGTOK BLOCKTOK
1558          {
1559            /* -> if(!$2) break; $3; continue;*/
1560            char * s = (char *)omAlloc( strlen($2) + strlen($3) + 36);
1561            sprintf(s,"whileif (!(%s)) break;\n%scontinue;\n " ,$2,$3);
1562            newBuffer(s,BT_break);
1563            omFree((ADDRESS)$2);
1564            omFree((ADDRESS)$3);
1565          }
1566        ;
1567
1568forcmd:
1569        FOR_CMD STRINGTOK STRINGTOK STRINGTOK BLOCKTOK
1570          {
1571            /* $2 */
1572            /* if (!$3) break; $5; $4; continue; */
1573            char * s = (char *)omAlloc( strlen($3)+strlen($4)+strlen($5)+36);
1574            sprintf(s,"forif (!(%s)) break;\n%s%s;\ncontinue;\n "
1575                   ,$3,$5,$4);
1576            omFree((ADDRESS)$3);
1577            omFree((ADDRESS)$4);
1578            omFree((ADDRESS)$5);
1579            newBuffer(s,BT_break);
1580            s = (char *)omAlloc( strlen($2) + 3);
1581            sprintf(s,"%s;\n",$2);
1582            omFree((ADDRESS)$2);
1583            newBuffer(s,BT_if);
1584          }
1585        ;
1586
1587proccmd:
1588        PROC_CMD extendedid BLOCKTOK
1589          {
1590            procinfov pi;
1591            idhdl h = enterid($2,myynest,PROC_CMD,&IDROOT,TRUE);
1592            if (h==NULL) {omFree((ADDRESS)$2);omFree((ADDRESS)$3); YYERROR;}
1593            iiInitSingularProcinfo(IDPROC(h),"", $2, 0, 0);
1594            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+31);;
1595            sprintf(IDPROC(h)->data.s.body,"parameter list #;\n%s;return();\n\n",$3);
1596            omFree((ADDRESS)$3);
1597            omFree((ADDRESS)$2);
1598          }
1599        | PROC_DEF STRINGTOK BLOCKTOK
1600          {
1601            idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE);
1602            if (h==NULL)
1603            {
1604              omFree((ADDRESS)$1);
1605              omFree((ADDRESS)$2);
1606              omFree((ADDRESS)$3);
1607              YYERROR;
1608            }
1609            char *args=iiProcArgs($2,FALSE);
1610            omFree((ADDRESS)$2);
1611            procinfov pi;
1612            iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0);
1613            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+strlen(args)+14);;
1614            sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$3);
1615            omFree((ADDRESS)args);
1616            omFree((ADDRESS)$3);
1617            omFree((ADDRESS)$1);
1618          }
1619        | PROC_DEF STRINGTOK STRINGTOK BLOCKTOK
1620          {
1621            omFree((ADDRESS)$3);
1622            idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE);
1623            if (h==NULL)
1624            {
1625              omFree((ADDRESS)$1);
1626              omFree((ADDRESS)$2);
1627              omFree((ADDRESS)$4);
1628              YYERROR;
1629            }
1630            char *args=iiProcArgs($2,FALSE);
1631            omFree((ADDRESS)$2);
1632            procinfov pi;
1633            iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0);
1634            omFree((ADDRESS)$1);
1635            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($4)+strlen(args)+14);;
1636            sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$4);
1637            omFree((ADDRESS)args);
1638            omFree((ADDRESS)$4);
1639          }
1640        ;
1641
1642parametercmd:
1643        PARAMETER declare_ip_variable
1644          {
1645            //Print("par:%s, %d\n",$2.Name(),$2.Typ());
1646            //yylineno--;
1647            if (iiParameter(&$2)) YYERROR;
1648          }
1649        | PARAMETER expr
1650          {
1651            //Print("par:%s, %d\n",$2.Name(),$2.Typ());
1652            sleftv tmp_expr;
1653            //yylineno--;
1654            if ((iiDeclCommand(&tmp_expr,&$2,myynest,DEF_CMD,&IDROOT))
1655            || (iiParameter(&tmp_expr)))
1656              YYERROR;
1657          }
1658        ;
1659
1660returncmd:
1661        RETURN '(' exprlist ')'
1662          {
1663            if(iiRETURNEXPR==NULL) YYERROR;
1664            iiRETURNEXPR[myynest].Copy(&$3);
1665            $3.CleanUp();
1666            if (exitBuffer(BT_proc)) YYERROR;
1667          }
1668        | RETURN '(' ')'
1669          {
1670            if ($1==RETURN)
1671            {
1672              if(iiRETURNEXPR==NULL) YYERROR;
1673              iiRETURNEXPR[myynest].Init();
1674              iiRETURNEXPR[myynest].rtyp=NONE;
1675              if (exitBuffer(BT_proc)) YYERROR;
1676            }
1677          }
1678        ;
Note: See TracBrowser for help on using the repository browser.