source: git/Singular/grammar.y @ 7df2ef

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