source: git/Singular/grammar.y @ 42a7cb4

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