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

spielwiese
Last change on this file since 9eefa5 was 9eefa5, checked in by Hans Schönemann <hannes@…>, 19 years ago
*hannes: kill r,i; git-svn-id: file:///usr/local/Singular/svn/trunk@8127 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 42.6 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: grammar.y,v 1.110 2005-05-10 14:35:09 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)
159      && (strncmp(fmt,"parse",5)!=0)
160      && (strncmp(fmt,"syntax",6)!=0))
161        WerrorS(fmt);
162      Werror( "error occurred in %s line %d: `%s`"
163             ,VoiceName(), yylineno, my_yylinebuf);
164    }
165    if (cmdtok!=0)
166    {
167      char *s=Tok2Cmdname(cmdtok);
168      if (expected_parms)
169      {
170        Werror("expected %s-expression. type \'help %s;\'",s,s);
171      }
172      else
173      {
174        Werror("wrong type declaration. type \'help %s;\'",s);
175      }
176    }
177    if (!old_errorreported && (lastreserved!=NULL))
178    {
179      Werror("last reserved name was `%s`",lastreserved);
180    }
181    inerror=1;
182  }
183  if ((currentVoice!=NULL)
184  && (currentVoice->prev!=NULL)
185  && (myynest>0)
186#ifdef HAVE_SDB
187  && ((sdb_flags &1)==0)
188#endif
189  )
190  {
191    Werror("leaving %s",VoiceName());
192  }
193}
194
195%}
196
197/* %expect 22 */
198%pure_parser
199
200/* special symbols */
201%token DOTDOT
202%token EQUAL_EQUAL
203%token GE
204%token LE
205%token MINUSMINUS
206%token NOT
207%token NOTEQUAL
208%token PLUSPLUS
209%token COLONCOLON
210
211/* types, part 1 (ring indep.)*/
212%token <i> GRING_CMD
213%token <i> INTMAT_CMD
214%token <i> PROC_CMD
215%token <i> RING_CMD
216
217/* valid when ring defined ! */
218%token <i> BEGIN_RING
219/* types, part 2 */
220%token <i> IDEAL_CMD
221%token <i> MAP_CMD
222%token <i> MATRIX_CMD
223%token <i> MODUL_CMD
224%token <i> NUMBER_CMD
225%token <i> POLY_CMD
226%token <i> RESOLUTION_CMD
227%token <i> VECTOR_CMD
228/* end types */
229
230/* ring dependent cmd:*/
231%token <i> BETTI_CMD
232%token <i> COEFFS_CMD
233%token <i> COEF_CMD
234%token <i> CONTRACT_CMD
235%token <i> DEGREE_CMD
236%token <i> DEG_CMD
237%token <i> DIFF_CMD
238%token <i> DIM_CMD
239%token <i> DIVISION_CMD
240%token <i> ELIMINATION_CMD
241%token <i> E_CMD
242%token <i> FETCH_CMD
243%token <i> FREEMODULE_CMD
244%token <i> KEEPRING_CMD
245%token <i> HILBERT_CMD
246%token <i> HOMOG_CMD
247%token <i> IMAP_CMD
248%token <i> INDEPSET_CMD
249%token <i> INTERRED_CMD
250%token <i> INTERSECT_CMD
251%token <i> JACOB_CMD
252%token <i> JET_CMD
253%token <i> KBASE_CMD
254%token <i> KOSZUL_CMD
255%token <i> LEADCOEF_CMD
256%token <i> LEADEXP_CMD
257%token <i> LEAD_CMD
258%token <i> LEADMONOM_CMD
259%token <i> LIFTSTD_CMD
260%token <i> LIFT_CMD
261%token <i> MAXID_CMD
262%token <i> MINBASE_CMD
263%token <i> MINOR_CMD
264%token <i> MINRES_CMD
265%token <i> MODULO_CMD
266%token <i> MRES_CMD
267%token <i> MULTIPLICITY_CMD
268%token <i> ORD_CMD
269%token <i> PAR_CMD
270%token <i> PARDEG_CMD
271%token <i> PREIMAGE_CMD
272%token <i> QUOTIENT_CMD
273%token <i> QHWEIGHT_CMD
274%token <i> REDUCE_CMD
275%token <i> REGULARITY_CMD
276%token <i> RES_CMD
277%token <i> SIMPLIFY_CMD
278%token <i> SORTVEC_CMD
279%token <i> SRES_CMD
280%token <i> STD_CMD
281%token <i> SUBST_CMD
282%token <i> SYZYGY_CMD
283%token <i> VAR_CMD
284%token <i> VDIM_CMD
285%token <i> WEDGE_CMD
286%token <i> WEIGHT_CMD
287
288/*system variables in ring block*/
289%token <i> VALTVARS
290%token <i> VMAXDEG
291%token <i> VMAXMULT
292%token <i> VNOETHER
293%token <i> VMINPOLY
294
295%token <i> END_RING
296/* end of ring definitions */
297
298%token <i> CMD_1
299%token <i> CMD_2
300%token <i> CMD_3
301%token <i> CMD_12
302%token <i> CMD_13
303%token <i> CMD_23
304%token <i> CMD_123
305%token <i> CMD_M
306%token <i> ROOT_DECL
307        /* put variables of this type into the idroot list */
308%token <i> ROOT_DECL_LIST
309        /* put variables of this type into the idroot list */
310%token <i> RING_DECL
311        /* put variables of this type into the currRing list */
312%token <i> EXAMPLE_CMD
313%token <i> EXPORT_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        ;
1158
1159killcmd:
1160        KILL_CMD extendedid
1161        {
1162          killid($2,&IDROOT);
1163        }
1164        | killcmd ',' extendedid
1165        {
1166          killid($3,&IDROOT);
1167        }
1168        ;
1169
1170listcmd:
1171        LISTVAR_CMD '(' ROOT_DECL ')'
1172          {
1173            list_cmd($3,NULL,"// ",TRUE);
1174          }
1175        | LISTVAR_CMD '(' ROOT_DECL_LIST ')'
1176          {
1177            list_cmd($3,NULL,"// ",TRUE);
1178          }
1179        | LISTVAR_CMD '(' RING_DECL ')'
1180          {
1181            if ($3==QRING_CMD) $3=RING_CMD;
1182            list_cmd($3,NULL,"// ",TRUE);
1183          }
1184        | LISTVAR_CMD '(' currring_lists ')'
1185          {
1186            list_cmd($3,NULL,"// ",TRUE);
1187          }
1188        | LISTVAR_CMD '(' RING_CMD ')'
1189          {
1190            list_cmd(RING_CMD,NULL,"// ",TRUE);
1191          }
1192        | LISTVAR_CMD '(' MATRIX_CMD ')'
1193          {
1194            list_cmd(MATRIX_CMD,NULL,"// ",TRUE);
1195           }
1196        | LISTVAR_CMD '(' INTMAT_CMD ')'
1197          {
1198            list_cmd(INTMAT_CMD,NULL,"// ",TRUE);
1199          }
1200        | LISTVAR_CMD '(' PROC_CMD ')'
1201          {
1202            list_cmd(PROC_CMD,NULL,"// ",TRUE);
1203          }
1204        | LISTVAR_CMD '(' elemexpr ')'
1205          {
1206            list_cmd(0,$3.Fullname(),"// ",TRUE);
1207            $3.CleanUp();
1208          }
1209        | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL ')'
1210          {
1211#ifdef HAVE_NS
1212            PrintS("?????\n");
1213            if($3.Typ() == PACKAGE_CMD)
1214              list_cmd($5,NULL,"// ",TRUE);
1215#endif /* HAVE_NS */
1216            $3.CleanUp();
1217          }
1218        | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL_LIST ')'
1219          {
1220#ifdef HAVE_NS
1221            PrintS("?????\n");
1222            if($3.Typ() == PACKAGE_CMD)
1223              list_cmd($5,NULL,"// ",TRUE);
1224#endif /* HAVE_NS */
1225            $3.CleanUp();
1226          }
1227        | LISTVAR_CMD '(' elemexpr ',' RING_DECL ')'
1228          {
1229#ifdef HAVE_NS
1230            PrintS("?????\n");
1231            if($3.Typ() == PACKAGE_CMD)
1232              list_cmd($5,NULL,"// ",TRUE);
1233#endif /* HAVE_NS */
1234            $3.CleanUp();
1235          }
1236        | LISTVAR_CMD '(' elemexpr ',' currring_lists ')'
1237          {
1238#ifdef HAVE_NS
1239            PrintS("?????\n");
1240            if($3.Typ() == PACKAGE_CMD)
1241              list_cmd($5,NULL,"// ",TRUE);
1242#endif /* HAVE_NS */
1243            $3.CleanUp();
1244          }
1245        | LISTVAR_CMD '(' elemexpr ',' RING_CMD ')'
1246          {
1247#ifdef HAVE_NS
1248            PrintS("?????\n");
1249            if($3.Typ() == PACKAGE_CMD)
1250              list_cmd($5,NULL,"// ",TRUE);
1251#endif /* HAVE_NS */
1252            $3.CleanUp();
1253          }
1254        | LISTVAR_CMD '(' elemexpr ',' MATRIX_CMD ')'
1255          {
1256#ifdef HAVE_NS
1257            PrintS("?????\n");
1258            if($3.Typ() == PACKAGE_CMD)
1259              list_cmd($5,NULL,"// ",TRUE);
1260#endif /* HAVE_NS */
1261            $3.CleanUp();
1262          }
1263        | LISTVAR_CMD '(' elemexpr ',' INTMAT_CMD ')'
1264          {
1265#ifdef HAVE_NS
1266            PrintS("?????\n");
1267            if($3.Typ() == PACKAGE_CMD)
1268              list_cmd($5,NULL,"// ",TRUE);
1269#endif /* HAVE_NS */
1270            $3.CleanUp();
1271          }
1272        | LISTVAR_CMD '(' elemexpr ',' PROC_CMD ')'
1273          {
1274#ifdef HAVE_NS
1275            PrintS("?????\n");
1276            if($3.Typ() == PACKAGE_CMD)
1277              list_cmd($5,NULL,"// ",TRUE);
1278#endif /* HAVE_NS */
1279            $3.CleanUp();
1280          }
1281        | LISTVAR_CMD '(' elemexpr ',' elemexpr ')'
1282          {
1283#ifdef HAVE_NS
1284            PrintS("?????\n");
1285            //if($3.Typ() == PACKAGE_CMD)
1286            //  list_cmd($5,NULL,"// ",TRUE);
1287#endif /* HAVE_NS */
1288            $3.CleanUp();
1289          }
1290        | LISTVAR_CMD '(' ')'
1291          {
1292            list_cmd(-1,NULL,"// ",TRUE);
1293          }
1294        ;
1295
1296ringcmd1:
1297       RING_CMD { yyInRingConstruction = TRUE; }
1298       ;
1299
1300ringcmd:
1301        ringcmd1
1302          elemexpr cmdeq
1303          rlist     ','      /* description of coeffs */
1304          rlist     ','      /* var names */
1305          ordering           /* list of (multiplier ordering (weight(s))) */
1306          {
1307            BOOLEAN do_pop = FALSE;
1308            char *ring_name = $2.name;
1309            ring b=
1310            rInit(&$4,            /* characteristik and list of parameters*/
1311                  &$6,            /* names of ringvariables */
1312                  &$8);            /* ordering */
1313            idhdl newRingHdl=NULL;
1314            if (b!=NULL)
1315            {
1316              newRingHdl=enterid(ring_name, myynest, RING_CMD, &IDROOT);
1317              $2.CleanUp();
1318              if (newRingHdl!=NULL)
1319              {
1320                omFreeSize(IDRING(newRingHdl),sizeof(ip_sring));
1321                IDRING(newRingHdl)=b;
1322              }
1323              else
1324              {
1325                rKill(b);
1326              }
1327            }
1328            yyInRingConstruction = FALSE;
1329            if (newRingHdl==NULL)
1330            {
1331              MYYERROR("cannot make ring");
1332            }
1333            else
1334            {
1335              rSetHdl(newRingHdl);
1336            }
1337          }
1338        | ringcmd1 elemexpr
1339          {
1340            BOOLEAN do_pop = FALSE;
1341            char *ring_name = $2.name;
1342            if (!inerror) rDefault(ring_name);
1343            yyInRingConstruction = FALSE;
1344            $2.CleanUp();
1345          }
1346        ;
1347
1348scriptcmd:
1349         SYSVAR stringexpr
1350          {
1351            if (($1!=LIB_CMD)||(iiLibCmd($2)))
1352            //if ($1==LIB_CMD)
1353            //{
1354            //  sleftv tmp;
1355            //  if(iiExprArith1(&tmp,&$2,LIB_CMD)) YYERROR;
1356            //}
1357            //else
1358                YYERROR;
1359          }
1360        ;
1361
1362setrings:  SETRING_CMD | KEEPRING_CMD ;
1363
1364setringcmd:
1365        setrings expr
1366          {
1367            if (($1==KEEPRING_CMD) && (myynest==0))
1368               MYYERROR("only inside a proc allowed");
1369            const char * n=$2.Name();
1370            if ((($2.Typ()==RING_CMD)||($2.Typ()==QRING_CMD))
1371            && ($2.rtyp==IDHDL))
1372            {
1373              idhdl h=(idhdl)$2.data;
1374              if ($2.e!=NULL) h=rFindHdl((ring)$2.Data(),NULL, NULL);
1375              //Print("setring %s lev %d (ptr:%x)\n",IDID(h),IDLEV(h),IDRING(h));
1376              if ($1==KEEPRING_CMD)
1377              {
1378                if (h!=NULL)
1379                {
1380                  if (IDLEV(h)!=0)
1381                  {
1382                    if (iiExport(&$2,myynest-1)) YYERROR;
1383#if 1
1384                    //if (TEST_OPT_KEEPVARS)
1385                    //{
1386                      idhdl p=IDRING(h)->idroot;
1387                      idhdl root=p;
1388                      int prevlev=myynest-1;
1389                      while (p!=NULL)
1390                      {
1391                        if (IDLEV(p)==myynest)
1392                        {
1393                          idhdl old=root->get(IDID(p),prevlev);
1394                          if (old!=NULL)
1395                          {
1396                            if (BVERBOSE(V_REDEFINE))
1397                              Warn("redefining %s",IDID(p));
1398                            killhdl2(old,&root,IDRING(h));
1399                            IDRING(h)->idroot=root;
1400                          }
1401                          IDLEV(p)=prevlev;
1402                        }
1403                        p=IDNEXT(p);
1404                      }
1405                      //IDRING(h)->idroot=root;
1406#endif
1407                    //}
1408                  }
1409#ifdef USE_IILOCALRING
1410                  iiLocalRing[myynest-1]=IDRING(h);
1411#endif
1412                  procstack->cRing=IDRING(h);
1413                  procstack->cRingHdl=h;
1414                }
1415                else
1416                {
1417                  Werror("%s is no identifier",n);
1418                  $2.CleanUp();
1419                  YYERROR;
1420                }
1421              }
1422              if (h!=NULL) rSetHdl(h);
1423              else
1424              {
1425                Werror("cannot find the name of the basering %s",n);
1426                $2.CleanUp();
1427                YYERROR;
1428              }
1429              $2.CleanUp();
1430            }
1431            else
1432            {
1433              Werror("%s is no name of a ring/qring",n);
1434              $2.CleanUp();
1435              YYERROR;
1436            }
1437          }
1438        ;
1439
1440typecmd:
1441        TYPE_CMD expr
1442          {
1443            if ($2.rtyp!=IDHDL) MYYERROR("identifier expected");
1444            idhdl h = (idhdl)$2.data;
1445            type_cmd(h);
1446          }
1447        | exprlist
1448          {
1449            //Print("typ is %d, rtyp:%d\n",$1.Typ(),$1.rtyp);
1450            #ifdef SIQ
1451            if ($1.rtyp!=COMMAND)
1452            {
1453            #endif
1454              if ($1.Typ()==UNKNOWN)
1455              {
1456                if ($1.name!=NULL)
1457                {
1458                  Werror("`%s` is undefined",$1.name);
1459                  omFree((ADDRESS)$1.name);
1460                }
1461                YYERROR;
1462              }
1463            #ifdef SIQ
1464            }
1465            #endif
1466            $1.Print(&sLastPrinted);
1467            $1.CleanUp(currRing);
1468            if (errorreported) YYERROR;
1469          }
1470        ;
1471
1472/* --------------------------------------------------------------------*/
1473/* section of flow control                                             */
1474/* --------------------------------------------------------------------*/
1475
1476ifcmd: IF_CMD '(' expr ')' BLOCKTOK
1477          {
1478            int i; TESTSETINT($3,i);
1479            if (i!=0)
1480            {
1481              newBuffer( $5, BT_if);
1482            }
1483            else
1484            {
1485              omFree((ADDRESS)$5);
1486              currentVoice->ifsw=1;
1487            }
1488          }
1489        | ELSE_CMD BLOCKTOK
1490          {
1491            if (currentVoice->ifsw==1)
1492            {
1493              currentVoice->ifsw=0;
1494              newBuffer( $2, BT_else);
1495            }
1496            else
1497            {
1498              if (currentVoice->ifsw!=2)
1499              {
1500                Warn("`else` without `if` in level %d",myynest);
1501              }
1502              omFree((ADDRESS)$2);
1503            }
1504            currentVoice->ifsw=0;
1505          }
1506        | IF_CMD '(' expr ')' BREAK_CMD
1507          {
1508            int i; TESTSETINT($3,i);
1509            if (i)
1510            {
1511              if (exitBuffer(BT_break)) YYERROR;
1512            }
1513            currentVoice->ifsw=0;
1514          }
1515        | BREAK_CMD
1516          {
1517            if (exitBuffer(BT_break)) YYERROR;
1518            currentVoice->ifsw=0;
1519          }
1520        | CONTINUE_CMD
1521          {
1522            if (contBuffer(BT_break)) YYERROR;
1523            currentVoice->ifsw=0;
1524          }
1525      ;
1526
1527whilecmd:
1528        WHILE_CMD STRINGTOK BLOCKTOK
1529          {
1530            /* -> if(!$2) break; $3; continue;*/
1531            char * s = (char *)omAlloc( strlen($2) + strlen($3) + 36);
1532            sprintf(s,"whileif (!(%s)) break;\n%scontinue;\n " ,$2,$3);
1533            newBuffer(s,BT_break);
1534            omFree((ADDRESS)$2);
1535            omFree((ADDRESS)$3);
1536          }
1537        ;
1538
1539forcmd:
1540        FOR_CMD STRINGTOK STRINGTOK STRINGTOK BLOCKTOK
1541          {
1542            /* $2 */
1543            /* if (!$3) break; $5; $4; continue; */
1544            char * s = (char *)omAlloc( strlen($3)+strlen($4)+strlen($5)+36);
1545            sprintf(s,"forif (!(%s)) break;\n%s%s;\ncontinue;\n "
1546                   ,$3,$5,$4);
1547            omFree((ADDRESS)$3);
1548            omFree((ADDRESS)$4);
1549            omFree((ADDRESS)$5);
1550            newBuffer(s,BT_break);
1551            s = (char *)omAlloc( strlen($2) + 3);
1552            sprintf(s,"%s;\n",$2);
1553            omFree((ADDRESS)$2);
1554            newBuffer(s,BT_if);
1555          }
1556        ;
1557
1558proccmd:
1559        PROC_CMD extendedid BLOCKTOK
1560          {
1561            procinfov pi;
1562            idhdl h = enterid($2,myynest,PROC_CMD,&IDROOT,TRUE);
1563            if (h==NULL) {omFree((ADDRESS)$2);omFree((ADDRESS)$3); YYERROR;}
1564            iiInitSingularProcinfo(IDPROC(h),"", $2, 0, 0);
1565            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+31);;
1566            sprintf(IDPROC(h)->data.s.body,"parameter list #;\n%s;return();\n\n",$3);
1567            omFree((ADDRESS)$3);
1568            omFree((ADDRESS)$2);
1569          }
1570        | PROC_DEF STRINGTOK BLOCKTOK
1571          {
1572            idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE);
1573            if (h==NULL)
1574            {
1575              omFree((ADDRESS)$1);
1576              omFree((ADDRESS)$2);
1577              omFree((ADDRESS)$3);
1578              YYERROR;
1579            }
1580            char *args=iiProcArgs($2,FALSE);
1581            omFree((ADDRESS)$2);
1582            procinfov pi;
1583            iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0);
1584            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+strlen(args)+14);;
1585            sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$3);
1586            omFree((ADDRESS)args);
1587            omFree((ADDRESS)$3);
1588            omFree((ADDRESS)$1);
1589          }
1590        | PROC_DEF STRINGTOK STRINGTOK BLOCKTOK
1591          {
1592            omFree((ADDRESS)$3);
1593            idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE);
1594            if (h==NULL)
1595            {
1596              omFree((ADDRESS)$1);
1597              omFree((ADDRESS)$2);
1598              omFree((ADDRESS)$4);
1599              YYERROR;
1600            }
1601            char *args=iiProcArgs($2,FALSE);
1602            omFree((ADDRESS)$2);
1603            procinfov pi;
1604            iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0);
1605            omFree((ADDRESS)$1);
1606            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($4)+strlen(args)+14);;
1607            sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$4);
1608            omFree((ADDRESS)args);
1609            omFree((ADDRESS)$4);
1610          }
1611        ;
1612
1613parametercmd:
1614        PARAMETER declare_ip_variable
1615          {
1616            //Print("par:%s, %d\n",$2.Name(),$2.Typ());
1617            //yylineno--;
1618            if (iiParameter(&$2)) YYERROR;
1619          }
1620        | PARAMETER expr
1621          {
1622            //Print("par:%s, %d\n",$2.Name(),$2.Typ());
1623            sleftv tmp_expr;
1624            //yylineno--;
1625            if ((iiDeclCommand(&tmp_expr,&$2,myynest,DEF_CMD,&IDROOT))
1626            || (iiParameter(&tmp_expr)))
1627              YYERROR;
1628          }
1629        ;
1630
1631returncmd:
1632        RETURN '(' exprlist ')'
1633          {
1634            if(iiRETURNEXPR==NULL) YYERROR;
1635            iiRETURNEXPR[myynest].Copy(&$3);
1636            $3.CleanUp();
1637            if (exitBuffer(BT_proc)) YYERROR;
1638          }
1639        | RETURN '(' ')'
1640          {
1641            if ($1==RETURN)
1642            {
1643              if(iiRETURNEXPR==NULL) YYERROR;
1644              iiRETURNEXPR[myynest].Init();
1645              iiRETURNEXPR[myynest].rtyp=NONE;
1646              if (exitBuffer(BT_proc)) YYERROR;
1647            }
1648          }
1649        ;
Note: See TracBrowser for help on using the repository browser.