source: git/Singular/grammar.y @ 9bc0b8

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