source: git/Singular/grammar.y @ 62b87d

spielwiese
Last change on this file since 62b87d was 62b87d, checked in by Hans Schönemann <hannes@…>, 17 years ago
*hannes: add :(int,int) git-svn-id: file:///usr/local/Singular/svn/trunk@9934 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 43.8 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: grammar.y,v 1.121 2007-03-10 14:40:54 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            {if (currentVoice!=NULL) 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 *)(long)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        | expr ':' expr
839          {
840            if(iiExprArith2(&$$,&$1,':',&$3)) YYERROR;
841          }
842        | NOT expr
843          {
844            memset(&$$,0,sizeof($$));
845            int i; TESTSETINT($2,i);
846            $$.rtyp  = INT_CMD;
847            $$.data = (void *)(long)(i == 0 ? 1 : 0);
848          }
849        | '-' expr %prec UMINUS
850          {
851            if(iiExprArith1(&$$,&$2,'-')) YYERROR;
852          }
853        ;
854
855left_value:
856        declare_ip_variable cmdeq  { $$ = $1; }
857        | exprlist '='
858          {
859            if ($1.rtyp==0)
860            {
861              Werror("`%s` is undefined",$1.Fullname());
862              YYERROR;
863            }
864            $$ = $1;
865          }
866        ;
867
868
869extendedid:
870        UNKNOWN_IDENT
871        | '`' expr '`'
872          {
873            if ($2.Typ()!=STRING_CMD)
874            {
875              MYYERROR("string expression expected");
876            }
877            $$ = (char *)$2.CopyD(STRING_CMD);
878            $2.CleanUp();
879          }
880        ;
881
882currring_lists:
883        IDEAL_CMD | MODUL_CMD
884        /* put variables into the current ring */
885        ;
886
887declare_ip_variable:
888        ROOT_DECL elemexpr
889          {
890            #ifdef HAVE_NS
891            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
892              YYERROR;
893            #else
894            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
895            #endif
896          }
897        | ROOT_DECL_LIST elemexpr
898          {
899            #ifdef HAVE_NS
900            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
901              YYERROR;
902            #else
903            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
904            #endif
905          }
906        | RING_DECL elemexpr
907          {
908            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
909          }
910        | currring_lists elemexpr
911          {
912            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
913          }
914        | MATRIX_CMD elemexpr '[' expr ']' '[' expr ']'
915          {
916            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
917            int r; TESTSETINT($4,r);
918            int c; TESTSETINT($7,c);
919            if (r < 1)
920              MYYERROR("rows must be greater than 0");
921            if (c < 0)
922              MYYERROR("cols must be greater than -1");
923            leftv v=&$$;
924            //while (v->next!=NULL) { v=v->next; }
925            idhdl h=(idhdl)v->data;
926            idDelete(&IDIDEAL(h));
927            IDMATRIX(h) = mpNew(r,c);
928            if (IDMATRIX(h)==NULL) YYERROR;
929          }
930        | MATRIX_CMD elemexpr
931          {
932            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
933          }
934        | INTMAT_CMD elemexpr '[' expr ']' '[' expr ']'
935          {
936            int r; TESTSETINT($4,r);
937            int c; TESTSETINT($7,c);
938            if (r < 1)
939              MYYERROR("rows must be greater than 0");
940            if (c < 0)
941              MYYERROR("cols must be greater than -1");
942            #ifdef HAVE_NS
943            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
944              YYERROR;
945            #else
946            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
947            #endif
948            leftv v=&$$;
949            idhdl h=(idhdl)v->data;
950            delete IDINTVEC(h);
951            IDINTVEC(h) = new intvec(r,c,0);
952            if (IDINTVEC(h)==NULL) YYERROR;
953          }
954        | INTMAT_CMD elemexpr
955          {
956            #ifdef HAVE_NS
957            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
958              YYERROR;
959            #else
960            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
961            #endif
962            leftv v=&$$;
963            idhdl h;
964            do
965            {
966               h=(idhdl)v->data;
967               delete IDINTVEC(h);
968               IDINTVEC(h) = new intvec(1,1,0);
969               v=v->next;
970            } while (v!=NULL);
971          }
972        | declare_ip_variable ',' elemexpr
973          {
974            int t=$1.Typ();
975            sleftv r;
976            memset(&r,0,sizeof(sleftv));
977            if ((BEGIN_RING<t) && (t<END_RING))
978            {
979              if (iiDeclCommand(&r,&$3,myynest,t,&(currRing->idroot), TRUE))
980                YYERROR;
981            }
982            else
983            {
984              #ifdef HAVE_NS
985              if (iiDeclCommand(&r,&$3,myynest,t,&($3.req_packhdl->idroot)))
986                YYERROR;
987              #else
988              if (iiDeclCommand(&r,&$3,myynest,t,&IDROOT)) YYERROR;
989              #endif
990            }
991            leftv v=&$1;
992            while (v->next!=NULL) v=v->next;
993            v->next=(leftv)omAllocBin(sleftv_bin);
994            memcpy(v->next,&r,sizeof(sleftv));
995            $$=$1;
996          }
997        | PROC_CMD elemexpr
998          {
999            #ifdef HAVE_NS
1000            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
1001              YYERROR;
1002            #else
1003            if (iiDeclCommand(&$$,&$2,myynest,$1,&IDROOT)) YYERROR;
1004            #endif
1005          }
1006        ;
1007
1008stringexpr:
1009        STRINGTOK
1010        ;
1011
1012rlist:
1013        expr
1014        | '(' expr ',' exprlist ')'
1015          {
1016            leftv v = &$2;
1017            while (v->next!=NULL)
1018            {
1019              v=v->next;
1020            }
1021            v->next = (leftv)omAllocBin(sleftv_bin);
1022            memcpy(v->next,&($4),sizeof(sleftv));
1023            $$ = $2;
1024          }
1025        ;
1026
1027ordername:
1028        UNKNOWN_IDENT
1029        {
1030          // let rInit take care of any errors
1031          $$=rOrderName($1);
1032        }
1033        ;
1034
1035orderelem:
1036        ordername
1037          {
1038            memset(&$$,0,sizeof($$));
1039            intvec *iv = new intvec(2);
1040            (*iv)[0] = 1;
1041            (*iv)[1] = $1;
1042            $$.rtyp = INTVEC_CMD;
1043            $$.data = (void *)iv;
1044          }
1045        | ordername '(' exprlist ')'
1046          {
1047            memset(&$$,0,sizeof($$));
1048            leftv sl = &$3;
1049            int slLength;
1050            {
1051              slLength =  exprlist_length(sl);
1052              int l = 2 +  slLength;
1053              intvec *iv = new intvec(l);
1054              (*iv)[0] = slLength;
1055              (*iv)[1] = $1;
1056
1057              int i = 2;
1058              while ((i<l) && (sl!=NULL))
1059              {
1060                if (sl->Typ() == INT_CMD)
1061                {
1062                  (*iv)[i++] = (int)((long)(sl->Data()));
1063                }
1064                else if ((sl->Typ() == INTVEC_CMD)
1065                ||(sl->Typ() == INTMAT_CMD))
1066                {
1067                  intvec *ivv = (intvec *)(sl->Data());
1068                  int ll = 0,l = ivv->length();
1069                  for (; l>0; l--)
1070                  {
1071                    (*iv)[i++] = (*ivv)[ll++];
1072                  }
1073                }
1074                else
1075                {
1076                  delete iv;
1077                  $3.CleanUp();
1078                  MYYERROR("wrong type in ordering");
1079                }
1080                sl = sl->next;
1081              }
1082              $$.rtyp = INTVEC_CMD;
1083              $$.data = (void *)iv;
1084            }
1085            $3.CleanUp();
1086          }
1087        ;
1088
1089OrderingList:
1090        orderelem
1091        |  orderelem ',' OrderingList
1092          {
1093            $$ = $1;
1094            $$.next = (sleftv *)omAllocBin(sleftv_bin);
1095            memcpy($$.next,&$3,sizeof(sleftv));
1096          }
1097        ;
1098
1099ordering:
1100        orderelem
1101        | '(' OrderingList ')'
1102          {
1103            $$ = $2;
1104          }
1105        ;
1106
1107cmdeq:  '='
1108          {
1109            expected_parms = TRUE;
1110          }
1111        ;
1112
1113
1114/* --------------------------------------------------------------------*/
1115/* section of pure commands                                            */
1116/* --------------------------------------------------------------------*/
1117
1118filecmd:
1119        '<' stringexpr
1120          { if ($<i>1 != '<') YYERROR;
1121            if((feFilePending=feFopen($2,"r",NULL,TRUE))==NULL) YYERROR; }
1122        ';'
1123          { newFile($2,feFilePending); }
1124        ;
1125
1126helpcmd:
1127        HELP_CMD STRINGTOK ';'
1128          {
1129            feHelp($2);
1130            omFree((ADDRESS)$2);
1131          }
1132        | HELP_CMD ';'
1133          {
1134            feHelp(NULL);
1135          }
1136        ;
1137
1138examplecmd:
1139        EXAMPLE_CMD STRINGTOK ';'
1140          {
1141            singular_example($2);
1142            omFree((ADDRESS)$2);
1143          }
1144       ;
1145
1146exportcmd:
1147        EXPORT_CMD exprlist
1148        {
1149#ifdef HAVE_NS
1150          if (basePack!=$2.req_packhdl)
1151          {
1152            if(iiExport(&$2,0,currPackHdl)) YYERROR;
1153          }
1154          else
1155#endif /* HAVE_NS */
1156            if (iiExport(&$2,0)) YYERROR;
1157        }
1158        ;
1159
1160killcmd:
1161        KILL_CMD elemexpr
1162        {
1163          leftv v=&$2;
1164          if (v->rtyp!=IDHDL)
1165          {
1166            if (v->name!=NULL)
1167            {
1168               Werror("`%s` is undefined in kill",v->name);
1169            }
1170            else               WerrorS("kill what ?");
1171          }
1172          else
1173          {
1174            #ifdef HAVE_NS
1175            killhdl((idhdl)v->data,v->req_packhdl);
1176            #else
1177            killhdl((idhdl)v->data);
1178            #endif
1179          }
1180        }
1181        | killcmd ',' elemexpr
1182        {
1183          leftv v=&$3;
1184          if (v->rtyp!=IDHDL)
1185          {
1186            if (v->name!=NULL)
1187            {
1188               Werror("`%s` is undefined in kill",v->name);
1189            }
1190            else               WerrorS("kill what ?");
1191          }
1192          else
1193          {
1194            #ifdef HAVE_NS
1195            killhdl((idhdl)v->data,v->req_packhdl);
1196            #else
1197            killhdl((idhdl)v->data);
1198            #endif
1199          }
1200        }
1201        ;
1202
1203listcmd:
1204        LISTVAR_CMD '(' ROOT_DECL ')'
1205          {
1206            list_cmd($3,NULL,"// ",TRUE);
1207          }
1208        | LISTVAR_CMD '(' ROOT_DECL_LIST ')'
1209          {
1210            list_cmd($3,NULL,"// ",TRUE);
1211          }
1212        | LISTVAR_CMD '(' RING_DECL ')'
1213          {
1214            if ($3==QRING_CMD) $3=RING_CMD;
1215            list_cmd($3,NULL,"// ",TRUE);
1216          }
1217        | LISTVAR_CMD '(' currring_lists ')'
1218          {
1219            list_cmd($3,NULL,"// ",TRUE);
1220          }
1221        | LISTVAR_CMD '(' RING_CMD ')'
1222          {
1223            list_cmd(RING_CMD,NULL,"// ",TRUE);
1224          }
1225        | LISTVAR_CMD '(' MATRIX_CMD ')'
1226          {
1227            list_cmd(MATRIX_CMD,NULL,"// ",TRUE);
1228           }
1229        | LISTVAR_CMD '(' INTMAT_CMD ')'
1230          {
1231            list_cmd(INTMAT_CMD,NULL,"// ",TRUE);
1232          }
1233        | LISTVAR_CMD '(' PROC_CMD ')'
1234          {
1235            list_cmd(PROC_CMD,NULL,"// ",TRUE);
1236          }
1237        | LISTVAR_CMD '(' elemexpr ')'
1238          {
1239            list_cmd(0,$3.Fullname(),"// ",TRUE);
1240            $3.CleanUp();
1241          }
1242        | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL ')'
1243          {
1244#ifdef HAVE_NS
1245            //PrintS("?????\n");
1246            if($3.Typ() == PACKAGE_CMD)
1247              list_cmd($5,NULL,"// ",TRUE);
1248#endif /* HAVE_NS */
1249            $3.CleanUp();
1250          }
1251        | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL_LIST ')'
1252          {
1253#ifdef HAVE_NS
1254            //PrintS("?????\n");
1255            if($3.Typ() == PACKAGE_CMD)
1256              list_cmd($5,NULL,"// ",TRUE);
1257#endif /* HAVE_NS */
1258            $3.CleanUp();
1259          }
1260        | LISTVAR_CMD '(' elemexpr ',' RING_DECL ')'
1261          {
1262#ifdef HAVE_NS
1263            //PrintS("?????\n");
1264            if($3.Typ() == PACKAGE_CMD)
1265              list_cmd($5,NULL,"// ",TRUE);
1266#endif /* HAVE_NS */
1267            $3.CleanUp();
1268          }
1269        | LISTVAR_CMD '(' elemexpr ',' currring_lists ')'
1270          {
1271#ifdef HAVE_NS
1272            //PrintS("?????\n");
1273            if($3.Typ() == PACKAGE_CMD)
1274              list_cmd($5,NULL,"// ",TRUE);
1275#endif /* HAVE_NS */
1276            $3.CleanUp();
1277          }
1278        | LISTVAR_CMD '(' elemexpr ',' RING_CMD ')'
1279          {
1280#ifdef HAVE_NS
1281            //PrintS("?????\n");
1282            if($3.Typ() == PACKAGE_CMD)
1283              list_cmd($5,NULL,"// ",TRUE);
1284#endif /* HAVE_NS */
1285            $3.CleanUp();
1286          }
1287        | LISTVAR_CMD '(' elemexpr ',' MATRIX_CMD ')'
1288          {
1289#ifdef HAVE_NS
1290            //PrintS("?????\n");
1291            if($3.Typ() == PACKAGE_CMD)
1292              list_cmd($5,NULL,"// ",TRUE);
1293#endif /* HAVE_NS */
1294            $3.CleanUp();
1295          }
1296        | LISTVAR_CMD '(' elemexpr ',' INTMAT_CMD ')'
1297          {
1298#ifdef HAVE_NS
1299            //PrintS("?????\n");
1300            if($3.Typ() == PACKAGE_CMD)
1301              list_cmd($5,NULL,"// ",TRUE);
1302#endif /* HAVE_NS */
1303            $3.CleanUp();
1304          }
1305        | LISTVAR_CMD '(' elemexpr ',' PROC_CMD ')'
1306          {
1307#ifdef HAVE_NS
1308            //PrintS("?????\n");
1309            if($3.Typ() == PACKAGE_CMD)
1310              list_cmd($5,NULL,"// ",TRUE);
1311#endif /* HAVE_NS */
1312            $3.CleanUp();
1313          }
1314        //| LISTVAR_CMD '(' elemexpr ',' elemexpr ')'
1315        //  {
1316        //#ifdef HAVE_NS
1317        //    //PrintS("?????\n");
1318        //    //if($3.Typ() == PACKAGE_CMD)
1319        //    //  list_cmd($5,NULL,"// ",TRUE);
1320        //#endif /* HAVE_NS */
1321        //    $3.CleanUp();
1322        //  }
1323        | LISTVAR_CMD '(' ')'
1324          {
1325            list_cmd(-1,NULL,"// ",TRUE);
1326          }
1327        ;
1328
1329ringcmd1:
1330       RING_CMD { yyInRingConstruction = TRUE; }
1331       ;
1332
1333ringcmd:
1334        ringcmd1
1335          elemexpr cmdeq
1336          rlist     ','      /* description of coeffs */
1337          rlist     ','      /* var names */
1338          ordering           /* list of (multiplier ordering (weight(s))) */
1339          {
1340            BOOLEAN do_pop = FALSE;
1341            char *ring_name = $2.name;
1342            ring b=
1343            rInit(&$4,            /* characteristik and list of parameters*/
1344                  &$6,            /* names of ringvariables */
1345                  &$8);            /* ordering */
1346            idhdl newRingHdl=NULL;
1347
1348            if (b!=NULL)
1349            {
1350              #ifdef HAVE_NS
1351                newRingHdl=enterid(ring_name, myynest, RING_CMD,
1352                                   &($2.req_packhdl->idroot));
1353              #else
1354                newRingHdl=enterid(ring_name, myynest, RING_CMD, &IDROOT);
1355              #endif
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,TRUE,TRUE,TRUE)))
1391            //if ($1==LIB_CMD)
1392            //{
1393            //  sleftv tmp;
1394            //  if(iiExprArith1(&tmp,&$2,LIB_CMD)) YYERROR;
1395            //}
1396            //else
1397                YYERROR;
1398          }
1399        ;
1400
1401setrings:  SETRING_CMD | KEEPRING_CMD ;
1402
1403setringcmd:
1404        setrings expr
1405          {
1406            if (($1==KEEPRING_CMD) && (myynest==0))
1407               MYYERROR("only inside a proc allowed");
1408            const char * n=$2.Name();
1409            if ((($2.Typ()==RING_CMD)||($2.Typ()==QRING_CMD))
1410            && ($2.rtyp==IDHDL))
1411            {
1412              idhdl h=(idhdl)$2.data;
1413              if ($2.e!=NULL) h=rFindHdl((ring)$2.Data(),NULL, NULL);
1414              //Print("setring %s lev %d (ptr:%x)\n",IDID(h),IDLEV(h),IDRING(h));
1415              if ($1==KEEPRING_CMD)
1416              {
1417                if (h!=NULL)
1418                {
1419                  if (IDLEV(h)!=0)
1420                  {
1421                    if (iiExport(&$2,myynest-1)) YYERROR;
1422#if 1
1423                    //if (TEST_OPT_KEEPVARS)
1424                    //{
1425                      idhdl p=IDRING(h)->idroot;
1426                      idhdl root=p;
1427                      int prevlev=myynest-1;
1428                      while (p!=NULL)
1429                      {
1430                        if (IDLEV(p)==myynest)
1431                        {
1432                          idhdl old=root->get(IDID(p),prevlev);
1433                          if (old!=NULL)
1434                          {
1435                            if (BVERBOSE(V_REDEFINE))
1436                              Warn("redefining %s",IDID(p));
1437                            killhdl2(old,&root,IDRING(h));
1438                            IDRING(h)->idroot=root;
1439                          }
1440                          IDLEV(p)=prevlev;
1441                        }
1442                        p=IDNEXT(p);
1443                      }
1444                      //IDRING(h)->idroot=root;
1445#endif
1446                    //}
1447                  }
1448#ifdef USE_IILOCALRING
1449                  iiLocalRing[myynest-1]=IDRING(h);
1450#endif
1451                  procstack->cRing=IDRING(h);
1452                  procstack->cRingHdl=h;
1453                }
1454                else
1455                {
1456                  Werror("%s is no identifier",n);
1457                  $2.CleanUp();
1458                  YYERROR;
1459                }
1460              }
1461              if (h!=NULL) rSetHdl(h);
1462              else
1463              {
1464                Werror("cannot find the name of the basering %s",n);
1465                $2.CleanUp();
1466                YYERROR;
1467              }
1468              $2.CleanUp();
1469            }
1470            else
1471            {
1472              Werror("%s is no name of a ring/qring",n);
1473              $2.CleanUp();
1474              YYERROR;
1475            }
1476          }
1477        ;
1478
1479typecmd:
1480        TYPE_CMD expr
1481          {
1482            if ($2.rtyp!=IDHDL) MYYERROR("identifier expected");
1483            idhdl h = (idhdl)$2.data;
1484            type_cmd(h);
1485          }
1486        | exprlist
1487          {
1488            //Print("typ is %d, rtyp:%d\n",$1.Typ(),$1.rtyp);
1489            #ifdef SIQ
1490            if ($1.rtyp!=COMMAND)
1491            {
1492            #endif
1493              if ($1.Typ()==UNKNOWN)
1494              {
1495                if ($1.name!=NULL)
1496                {
1497                  Werror("`%s` is undefined",$1.name);
1498                  omFree((ADDRESS)$1.name);
1499                }
1500                YYERROR;
1501              }
1502            #ifdef SIQ
1503            }
1504            #endif
1505            $1.Print(&sLastPrinted);
1506            $1.CleanUp(currRing);
1507            if (errorreported) YYERROR;
1508          }
1509        ;
1510
1511/* --------------------------------------------------------------------*/
1512/* section of flow control                                             */
1513/* --------------------------------------------------------------------*/
1514
1515ifcmd: IF_CMD '(' expr ')' BLOCKTOK
1516          {
1517            int i; TESTSETINT($3,i);
1518            if (i!=0)
1519            {
1520              newBuffer( $5, BT_if);
1521            }
1522            else
1523            {
1524              omFree((ADDRESS)$5);
1525              currentVoice->ifsw=1;
1526            }
1527          }
1528        | ELSE_CMD BLOCKTOK
1529          {
1530            if (currentVoice->ifsw==1)
1531            {
1532              currentVoice->ifsw=0;
1533              newBuffer( $2, BT_else);
1534            }
1535            else
1536            {
1537              if (currentVoice->ifsw!=2)
1538              {
1539                Warn("`else` without `if` in level %d",myynest);
1540              }
1541              omFree((ADDRESS)$2);
1542            }
1543            currentVoice->ifsw=0;
1544          }
1545        | IF_CMD '(' expr ')' BREAK_CMD
1546          {
1547            int i; TESTSETINT($3,i);
1548            if (i)
1549            {
1550              if (exitBuffer(BT_break)) YYERROR;
1551            }
1552            currentVoice->ifsw=0;
1553          }
1554        | BREAK_CMD
1555          {
1556            if (exitBuffer(BT_break)) YYERROR;
1557            currentVoice->ifsw=0;
1558          }
1559        | CONTINUE_CMD
1560          {
1561            if (contBuffer(BT_break)) YYERROR;
1562            currentVoice->ifsw=0;
1563          }
1564      ;
1565
1566whilecmd:
1567        WHILE_CMD STRINGTOK BLOCKTOK
1568          {
1569            /* -> if(!$2) break; $3; continue;*/
1570            char * s = (char *)omAlloc( strlen($2) + strlen($3) + 36);
1571            sprintf(s,"whileif (!(%s)) break;\n%scontinue;\n " ,$2,$3);
1572            newBuffer(s,BT_break);
1573            omFree((ADDRESS)$2);
1574            omFree((ADDRESS)$3);
1575          }
1576        ;
1577
1578forcmd:
1579        FOR_CMD STRINGTOK STRINGTOK STRINGTOK BLOCKTOK
1580          {
1581            /* $2 */
1582            /* if (!$3) break; $5; $4; continue; */
1583            char * s = (char *)omAlloc( strlen($3)+strlen($4)+strlen($5)+36);
1584            sprintf(s,"forif (!(%s)) break;\n%s%s;\ncontinue;\n "
1585                   ,$3,$5,$4);
1586            omFree((ADDRESS)$3);
1587            omFree((ADDRESS)$4);
1588            omFree((ADDRESS)$5);
1589            newBuffer(s,BT_break);
1590            s = (char *)omAlloc( strlen($2) + 3);
1591            sprintf(s,"%s;\n",$2);
1592            omFree((ADDRESS)$2);
1593            newBuffer(s,BT_if);
1594          }
1595        ;
1596
1597proccmd:
1598        PROC_CMD extendedid BLOCKTOK
1599          {
1600            procinfov pi;
1601            idhdl h = enterid($2,myynest,PROC_CMD,&IDROOT,TRUE);
1602            if (h==NULL) {omFree((ADDRESS)$2);omFree((ADDRESS)$3); YYERROR;}
1603            iiInitSingularProcinfo(IDPROC(h),"", $2, 0, 0);
1604            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+31);;
1605            sprintf(IDPROC(h)->data.s.body,"parameter list #;\n%s;return();\n\n",$3);
1606            omFree((ADDRESS)$3);
1607            omFree((ADDRESS)$2);
1608          }
1609        | PROC_DEF STRINGTOK BLOCKTOK
1610          {
1611            idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE);
1612            if (h==NULL)
1613            {
1614              omFree((ADDRESS)$1);
1615              omFree((ADDRESS)$2);
1616              omFree((ADDRESS)$3);
1617              YYERROR;
1618            }
1619            char *args=iiProcArgs($2,FALSE);
1620            omFree((ADDRESS)$2);
1621            procinfov pi;
1622            iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0);
1623            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+strlen(args)+14);;
1624            sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$3);
1625            omFree((ADDRESS)args);
1626            omFree((ADDRESS)$3);
1627            omFree((ADDRESS)$1);
1628          }
1629        | PROC_DEF STRINGTOK STRINGTOK BLOCKTOK
1630          {
1631            omFree((ADDRESS)$3);
1632            idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE);
1633            if (h==NULL)
1634            {
1635              omFree((ADDRESS)$1);
1636              omFree((ADDRESS)$2);
1637              omFree((ADDRESS)$4);
1638              YYERROR;
1639            }
1640            char *args=iiProcArgs($2,FALSE);
1641            omFree((ADDRESS)$2);
1642            procinfov pi;
1643            iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0);
1644            omFree((ADDRESS)$1);
1645            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($4)+strlen(args)+14);;
1646            sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$4);
1647            omFree((ADDRESS)args);
1648            omFree((ADDRESS)$4);
1649          }
1650        ;
1651
1652parametercmd:
1653        PARAMETER declare_ip_variable
1654          {
1655            //Print("par:%s, %d\n",$2.Name(),$2.Typ());
1656            //yylineno--;
1657            if (iiParameter(&$2)) YYERROR;
1658          }
1659        | PARAMETER expr
1660          {
1661            //Print("par:%s, %d\n",$2.Name(),$2.Typ());
1662            sleftv tmp_expr;
1663            //yylineno--;
1664            if ((iiDeclCommand(&tmp_expr,&$2,myynest,DEF_CMD,&IDROOT))
1665            || (iiParameter(&tmp_expr)))
1666              YYERROR;
1667          }
1668        ;
1669
1670returncmd:
1671        RETURN '(' exprlist ')'
1672          {
1673            if(iiRETURNEXPR==NULL) YYERROR;
1674            iiRETURNEXPR[myynest].Copy(&$3);
1675            $3.CleanUp();
1676            if (exitBuffer(BT_proc)) YYERROR;
1677          }
1678        | RETURN '(' ')'
1679          {
1680            if ($1==RETURN)
1681            {
1682              if(iiRETURNEXPR==NULL) YYERROR;
1683              iiRETURNEXPR[myynest].Init();
1684              iiRETURNEXPR[myynest].rtyp=NONE;
1685              if (exitBuffer(BT_proc)) YYERROR;
1686            }
1687          }
1688        ;
Note: See TracBrowser for help on using the repository browser.