source: git/Singular/grammar.y @ fb1675

spielwiese
Last change on this file since fb1675 was fb1675, checked in by Hans Schoenemann <hannes@…>, 7 years ago
use include ".." for singular related .h, p8
  • Property mode set to 100644
File size: 42.3 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.next==NULL)
475            {
476              $1.next=(leftv)omAllocBin(sleftv_bin);
477              memcpy($1.next,&$3,sizeof(sleftv));
478              if(iiExprArithM(&$$,&$1,'(')) YYERROR;
479            }
480            else if ($1.rtyp==UNKNOWN)
481            { // for x(i)(j)
482              if(iiExprArith2(&$$,&$1,'(',&$3)) YYERROR;
483            }
484            else YYERROR;
485          }
486        | '[' exprlist ']'
487          {
488            if (currRingHdl==NULL) MYYERROR("no ring active");
489            int j = 0;
490            memset(&$$,0,sizeof(sleftv));
491            $$.rtyp=VECTOR_CMD;
492            leftv v = &$2;
493            while (v!=NULL)
494            {
495              int i,t;
496              sleftv tmp;
497              memset(&tmp,0,sizeof(tmp));
498              i=iiTestConvert((t=v->Typ()),POLY_CMD);
499              if((i==0) || (iiConvert(t /*v->Typ()*/,POLY_CMD,i,v,&tmp)))
500              {
501                pDelete((poly *)&$$.data);
502                $2.CleanUp();
503                MYYERROR("expected '[poly,...'");
504              }
505              poly p = (poly)tmp.CopyD(POLY_CMD);
506              pSetCompP(p,++j);
507              $$.data = (void *)pAdd((poly)$$.data,p);
508              v->next=tmp.next;tmp.next=NULL;
509              tmp.CleanUp();
510              v=v->next;
511            }
512            $2.CleanUp();
513          }
514        | INT_CONST
515          {
516            memset(&$$,0,sizeof($$));
517            int i = atoi($1);
518            /*remember not to omFree($1)
519            *because it is a part of the scanner buffer*/
520            $$.rtyp  = INT_CMD;
521            $$.data = (void *)(long)i;
522
523            /* check: out of range input */
524            int l = strlen($1)+2;
525            number n;
526            if (l >= MAX_INT_LEN)
527            {
528              char tmp[MAX_INT_LEN+5];
529              sprintf(tmp,"%d",i);
530              if (strcmp(tmp,$1)!=0)
531              {
532                n_Read($1,&n,coeffs_BIGINT);
533                $$.rtyp=BIGINT_CMD;
534                $$.data = n;
535              }
536            }
537          }
538        | SYSVAR
539          {
540            memset(&$$,0,sizeof($$));
541            $$.rtyp = $1;
542            $$.data = $$.Data();
543          }
544        | stringexpr
545          {
546            memset(&$$,0,sizeof($$));
547            $$.rtyp  = STRING_CMD;
548            $$.data = $1;
549          }
550        | PROC_CMD '(' expr ')'
551          {
552            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
553          }
554        | ROOT_DECL '(' expr ')'
555          {
556            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
557          }
558        | ROOT_DECL_LIST '(' exprlist ')'
559          {
560            if(iiExprArithM(&$$,&$3,$1)) YYERROR;
561          }
562        | ROOT_DECL_LIST '(' ')'
563          {
564            if(iiExprArithM(&$$,NULL,$1)) YYERROR;
565          }
566        | RING_DECL '(' expr ')'
567          {
568            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
569          }
570        | RING_DECL_LIST '(' exprlist ')'
571          {
572            if(iiExprArithM(&$$,&$3,$1)) YYERROR;
573          }
574        | RING_DECL_LIST '(' ')'
575          {
576            if(iiExprArithM(&$$,NULL,$1)) YYERROR;
577          }
578        | CMD_1 '(' expr ')'
579          {
580            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
581          }
582        | CMD_12 '(' expr ')'
583          {
584            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
585          }
586        | CMD_13 '(' expr ')'
587          {
588            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
589          }
590        | CMD_123 '(' expr ')'
591          {
592            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
593          }
594        | CMD_2 '(' expr ',' expr ')'
595          {
596            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
597          }
598        | CMD_12 '(' expr ',' expr ')'
599          {
600            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
601          }
602        | CMD_23 '(' expr ',' expr ')'
603          {
604            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
605          }
606        | CMD_123 '(' expr ',' expr ')'
607          {
608            if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR;
609          }
610        | CMD_3 '(' expr ',' expr ',' expr ')'
611          {
612            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
613          }
614        | CMD_13 '(' expr ',' expr ',' expr ')'
615          {
616            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
617          }
618        | CMD_23 '(' expr ',' expr ',' expr ')'
619          {
620            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
621          }
622        | CMD_123 '(' expr ',' expr ',' expr ')'
623          {
624            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
625          }
626        | CMD_M '(' ')'
627          {
628            if(iiExprArithM(&$$,NULL,$1)) YYERROR;
629          }
630        | CMD_M '(' exprlist ')'
631          {
632            int b=iiExprArithM(&$$,&$3,$1); // handle branchTo
633            if (b==TRUE) YYERROR;
634            if (b==2) YYACCEPT;
635          }
636        | mat_cmd '(' expr ',' expr ',' expr ')'
637          {
638            if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR;
639          }
640        | mat_cmd '(' expr ')'
641          {
642            if(iiExprArith1(&$$,&$3,$1)) YYERROR;
643          }
644        | RING_CMD '(' rlist ',' rlist ',' ordering ')'
645          {
646            if(iiExprArith3(&$$,RING_CMD,&$3,&$5,&$7)) YYERROR;
647          }
648        | RING_CMD '(' expr ')'
649          {
650            if(iiExprArith1(&$$,&$3,RING_CMD)) YYERROR;
651          }
652        | extendedid  ARROW BLOCKTOK
653          {
654            if (iiARROW(&$$,$1,$3)) YYERROR;
655          }
656        | '(' exprlist ')'    { $$ = $2; }
657        ;
658
659exprlist:
660        exprlist ',' expr
661          {
662            leftv v = &$1;
663            while (v->next!=NULL)
664            {
665              v=v->next;
666            }
667            v->next = (leftv)omAllocBin(sleftv_bin);
668            memcpy(v->next,&($3),sizeof(sleftv));
669            $$ = $1;
670          }
671        | expr
672          {
673            $$ = $1;
674          }
675        ;
676
677expr:   expr_arithmetic
678          {
679            /*if ($1.typ == eunknown) YYERROR;*/
680            $$ = $1;
681          }
682        | elemexpr       { $$ = $1; }
683        | expr '[' expr ',' expr ']'
684          {
685            if(iiExprArith3(&$$,'[',&$1,&$3,&$5)) YYERROR;
686          }
687        | expr '[' expr ']'
688          {
689            if(iiExprArith2(&$$,&$1,'[',&$3)) YYERROR;
690          }
691        | APPLY '('  expr ',' CMD_1 ')'
692          {
693            if (iiApply(&$$, &$3, $5, NULL)) YYERROR;
694          }
695        | APPLY '('  expr ',' CMD_12 ')'
696          {
697            if (iiApply(&$$, &$3, $5, NULL)) YYERROR;
698          }
699        | APPLY '('  expr ',' CMD_13 ')'
700          {
701            if (iiApply(&$$, &$3, $5, NULL)) YYERROR;
702          }
703        | APPLY '('  expr ',' CMD_123 ')'
704          {
705            if (iiApply(&$$, &$3, $5, NULL)) YYERROR;
706          }
707        | APPLY '('  expr ',' CMD_M ')'
708          {
709            if (iiApply(&$$, &$3, $5, NULL)) YYERROR;
710          }
711        | APPLY '('  expr ',' expr ')'
712          {
713            if (iiApply(&$$, &$3, 0, &$5)) YYERROR;
714          }
715        | quote_start expr quote_end
716          {
717            $$=$2;
718          }
719        | quote_start expr '=' expr quote_end
720          {
721            #ifdef SIQ
722            siq++;
723            if (siq>0)
724            { if (iiExprArith2(&$$,&$2,'=',&$4)) YYERROR; }
725            else
726            #endif
727            {
728              memset(&$$,0,sizeof($$));
729              $$.rtyp=NONE;
730              if (iiAssign(&$2,&$4)) YYERROR;
731            }
732            #ifdef SIQ
733            siq--;
734            #endif
735          }
736        | assume_start expr ',' expr quote_end
737          {
738            iiTestAssume(&$2,&$4);
739            memset(&$$,0,sizeof($$));
740            $$.rtyp=NONE;
741          }
742        | EVAL  '('
743          {
744            #ifdef SIQ
745            siq--;
746            #endif
747          }
748          expr ')'
749          {
750            #ifdef SIQ
751            if (siq<=0) $4.Eval();
752            #endif
753            $$=$4;
754            #ifdef SIQ
755            siq++;
756            #endif
757          }
758          ;
759
760quote_start:    QUOTE  '('
761          {
762            #ifdef SIQ
763            siq++;
764            #endif
765          }
766          ;
767
768assume_start:    ASSUME_CMD '('
769          {
770            #ifdef SIQ
771            siq++;
772            #endif
773          }
774          ;
775
776quote_end: ')'
777          {
778            #ifdef SIQ
779            siq--;
780            #endif
781          }
782          ;
783
784expr_arithmetic:
785          expr PLUSPLUS     %prec PLUSPLUS
786          {
787            if(iiExprArith1(&$$,&$1,PLUSPLUS)) YYERROR;
788          }
789        | expr MINUSMINUS   %prec MINUSMINUS
790          {
791            if(iiExprArith1(&$$,&$1,MINUSMINUS)) YYERROR;
792          }
793        | expr '+' expr
794          {
795            if(iiExprArith2(&$$,&$1,'+',&$3)) YYERROR;
796          }
797        | expr '-' expr
798          {
799            if(iiExprArith2(&$$,&$1,'-',&$3)) YYERROR;
800          }
801        | expr '/' expr
802          {
803            if(iiExprArith2(&$$,&$1,$<i>2,&$3)) YYERROR;
804          }
805        | expr '^' expr
806          {
807            if(iiExprArith2(&$$,&$1,'^',&$3)) YYERROR;
808          }
809        | expr '<' expr
810          {
811            if(iiExprArith2(&$$,&$1,$<i>2,&$3)) YYERROR;
812          }
813        | expr '&' expr
814          {
815            if(iiExprArith2(&$$,&$1,$<i>2,&$3)) YYERROR;
816          }
817        | expr NOTEQUAL expr
818          {
819            if(iiExprArith2(&$$,&$1,NOTEQUAL,&$3)) YYERROR;
820          }
821        | expr EQUAL_EQUAL expr
822          {
823            if(iiExprArith2(&$$,&$1,EQUAL_EQUAL,&$3)) YYERROR;
824          }
825        | expr DOTDOT expr
826          {
827            if(iiExprArith2(&$$,&$1,DOTDOT,&$3)) YYERROR;
828          }
829        | expr ':' expr
830          {
831            if(iiExprArith2(&$$,&$1,':',&$3)) YYERROR;
832          }
833        | NOT expr
834          {
835            if (siq>0)
836            { if (iiExprArith1(&$$,&$2,NOT)) YYERROR; }
837            else
838            {
839              memset(&$$,0,sizeof($$));
840              int i; TESTSETINT($2,i);
841              $$.rtyp  = INT_CMD;
842              $$.data = (void *)(long)(i == 0 ? 1 : 0);
843            }
844          }
845        | '-' expr %prec UMINUS
846          {
847            if(iiExprArith1(&$$,&$2,'-')) YYERROR;
848          }
849        ;
850
851left_value:
852        declare_ip_variable cmdeq  { $$ = $1; }
853        | exprlist '='
854          {
855            if ($1.rtyp==0)
856            {
857              Werror("`%s` is undefined",$1.Fullname());
858              YYERROR;
859            }
860            else if (($1.rtyp==MODUL_CMD)
861            // matrix m; m[2]=...
862            && ($1.e!=NULL) && ($1.e->next==NULL))
863            {
864              MYYERROR("matrix must have 2 indices");
865            }
866            $$ = $1;
867          }
868        ;
869
870
871extendedid:
872        UNKNOWN_IDENT
873        | '`' expr '`'
874          {
875            if ($2.Typ()!=STRING_CMD)
876            {
877              MYYERROR("string expression expected");
878            }
879            $$ = (char *)$2.CopyD(STRING_CMD);
880            $2.CleanUp();
881          }
882        ;
883
884declare_ip_variable:
885        ROOT_DECL elemexpr
886          {
887            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
888              YYERROR;
889          }
890        | ROOT_DECL_LIST elemexpr
891          {
892            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
893              YYERROR;
894          }
895        | RING_DECL elemexpr
896          {
897            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
898          }
899        | RING_DECL_LIST elemexpr
900          {
901            if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
902          }
903        | mat_cmd elemexpr '[' expr ']' '[' expr ']'
904          {
905            int r; TESTSETINT($4,r);
906            int c; TESTSETINT($7,c);
907            leftv v;
908            idhdl h;
909            if ($1 == MATRIX_CMD)
910            {
911              if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
912              v=&$$;
913              h=(idhdl)v->data;
914              idDelete(&IDIDEAL(h));
915              IDMATRIX(h) = mpNew(r,c);
916              if (IDMATRIX(h)==NULL) YYERROR;
917            }
918            else if ($1 == INTMAT_CMD)
919            {
920              if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
921                YYERROR;
922              v=&$$;
923              h=(idhdl)v->data;
924              delete IDINTVEC(h);
925              IDINTVEC(h) = new intvec(r,c,0);
926              if (IDINTVEC(h)==NULL) YYERROR;
927            }
928            else /* BIGINTMAT_CMD */
929            {
930              if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
931                YYERROR;
932              v=&$$;
933              h=(idhdl)v->data;
934              delete IDBIMAT(h);
935              IDBIMAT(h) = new bigintmat(r, c, coeffs_BIGINT);
936              if (IDBIMAT(h)==NULL) YYERROR;
937            }
938          }
939        | mat_cmd elemexpr
940          {
941            if ($1 == MATRIX_CMD)
942            {
943              if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR;
944            }
945            else if ($1 == INTMAT_CMD)
946            {
947              if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
948                YYERROR;
949              leftv v=&$$;
950              idhdl h;
951              do
952              {
953                 h=(idhdl)v->data;
954                 delete IDINTVEC(h);
955                 IDINTVEC(h) = new intvec(1,1,0);
956                 v=v->next;
957              } while (v!=NULL);
958            }
959            else /* BIGINTMAT_CMD */
960            {
961              if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
962                YYERROR;
963            }
964          }
965        | declare_ip_variable ',' elemexpr
966          {
967            int t=$1.Typ();
968            sleftv r;
969            memset(&r,0,sizeof(sleftv));
970            if ((BEGIN_RING<t) && (t<END_RING))
971            {
972              if (iiDeclCommand(&r,&$3,myynest,t,&(currRing->idroot), TRUE))
973                YYERROR;
974            }
975            else
976            {
977              if (iiDeclCommand(&r,&$3,myynest,t,&($3.req_packhdl->idroot)))
978                YYERROR;
979            }
980            leftv v=&$1;
981            while (v->next!=NULL) v=v->next;
982            v->next=(leftv)omAllocBin(sleftv_bin);
983            memcpy(v->next,&r,sizeof(sleftv));
984            $$=$1;
985          }
986        | PROC_CMD elemexpr
987          {
988            if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot)))
989              YYERROR;
990          }
991        ;
992
993stringexpr:
994        STRINGTOK
995        ;
996
997rlist:
998        expr
999        | '(' expr ',' exprlist ')'
1000          {
1001            leftv v = &$2;
1002            while (v->next!=NULL)
1003            {
1004              v=v->next;
1005            }
1006            v->next = (leftv)omAllocBin(sleftv_bin);
1007            memcpy(v->next,&($4),sizeof(sleftv));
1008            $$ = $2;
1009          }
1010        ;
1011
1012ordername:
1013        UNKNOWN_IDENT
1014        {
1015          // let rInit take care of any errors
1016          $$=rOrderName($1);
1017        }
1018        ;
1019
1020orderelem:
1021        ordername
1022          {
1023            memset(&$$,0,sizeof($$));
1024            intvec *iv = new intvec(2);
1025            (*iv)[0] = 1;
1026            (*iv)[1] = $1;
1027            $$.rtyp = INTVEC_CMD;
1028            $$.data = (void *)iv;
1029          }
1030        | ordername '(' exprlist ')'
1031          {
1032            memset(&$$,0,sizeof($$));
1033            leftv sl = &$3;
1034            int slLength;
1035            {
1036              slLength =  exprlist_length(sl);
1037              int l = 2 +  slLength;
1038              intvec *iv = new intvec(l);
1039              (*iv)[0] = slLength;
1040              (*iv)[1] = $1;
1041
1042              int i = 2;
1043              while ((i<l) && (sl!=NULL))
1044              {
1045                if (sl->Typ() == INT_CMD)
1046                {
1047                  (*iv)[i++] = (int)((long)(sl->Data()));
1048                }
1049                else if ((sl->Typ() == INTVEC_CMD)
1050                ||(sl->Typ() == INTMAT_CMD))
1051                {
1052                  intvec *ivv = (intvec *)(sl->Data());
1053                  int ll = 0,l = ivv->length();
1054                  for (; l>0; l--)
1055                  {
1056                    (*iv)[i++] = (*ivv)[ll++];
1057                  }
1058                }
1059                else
1060                {
1061                  delete iv;
1062                  $3.CleanUp();
1063                  MYYERROR("wrong type in ordering");
1064                }
1065                sl = sl->next;
1066              }
1067              $$.rtyp = INTVEC_CMD;
1068              $$.data = (void *)iv;
1069            }
1070            $3.CleanUp();
1071          }
1072        ;
1073
1074OrderingList:
1075        orderelem
1076        |  orderelem ',' OrderingList
1077          {
1078            $$ = $1;
1079            $$.next = (sleftv *)omAllocBin(sleftv_bin);
1080            memcpy($$.next,&$3,sizeof(sleftv));
1081          }
1082        ;
1083
1084ordering:
1085        orderelem
1086        | '(' OrderingList ')'
1087          {
1088            $$ = $2;
1089          }
1090        ;
1091
1092cmdeq:  '='
1093          {
1094            expected_parms = TRUE;
1095          }
1096        ;
1097
1098
1099mat_cmd: MATRIX_CMD
1100            { $$ = $1; }
1101        | INTMAT_CMD
1102            { $$ = $1; }
1103        | BIGINTMAT_CMD
1104            { $$ = $1; }
1105          ;
1106
1107/* --------------------------------------------------------------------*/
1108/* section of pure commands                                            */
1109/* --------------------------------------------------------------------*/
1110
1111filecmd:
1112        '<' stringexpr
1113          { if ($<i>1 != '<') YYERROR;
1114            if((feFilePending=feFopen($2,"r",NULL,TRUE))==NULL) YYERROR; }
1115        ';'
1116          { newFile($2,feFilePending); }
1117        ;
1118
1119helpcmd:
1120        HELP_CMD STRINGTOK ';'
1121          {
1122            feHelp($2);
1123            omFree((ADDRESS)$2);
1124          }
1125        | HELP_CMD ';'
1126          {
1127            feHelp(NULL);
1128          }
1129        ;
1130
1131examplecmd:
1132        EXAMPLE_CMD STRINGTOK ';'
1133          {
1134            singular_example($2);
1135            omFree((ADDRESS)$2);
1136          }
1137       ;
1138
1139exportcmd:
1140        EXPORT_CMD exprlist
1141        {
1142          if (basePack!=$2.req_packhdl)
1143          {
1144            if(iiExport(&$2,0,currPack)) YYERROR;
1145          }
1146          else
1147            if (iiExport(&$2,0)) YYERROR;
1148        }
1149        ;
1150
1151killcmd:
1152        KILL_CMD elemexpr
1153        {
1154          leftv v=&$2;
1155          if (v->rtyp!=IDHDL)
1156          {
1157            if (v->name!=NULL)
1158            {
1159               Werror("`%s` is undefined in kill",v->name);
1160               omFree((ADDRESS)v->name); v->name=NULL;
1161            }
1162            else               WerrorS("kill what ?");
1163          }
1164          else
1165          {
1166            killhdl((idhdl)v->data,v->req_packhdl);
1167          }
1168        }
1169        | killcmd ',' elemexpr
1170        {
1171          leftv v=&$3;
1172          if (v->rtyp!=IDHDL)
1173          {
1174            if (v->name!=NULL)
1175            {
1176               Werror("`%s` is undefined in kill",v->name);
1177               omFree((ADDRESS)v->name); v->name=NULL;
1178            }
1179            else               WerrorS("kill what ?");
1180          }
1181          else
1182          {
1183            killhdl((idhdl)v->data,v->req_packhdl);
1184          }
1185        }
1186        ;
1187
1188listcmd:
1189        LISTVAR_CMD '(' ROOT_DECL ')'
1190          {
1191            list_cmd($3,NULL,"// ",TRUE);
1192          }
1193        | LISTVAR_CMD '(' ROOT_DECL_LIST ')'
1194          {
1195            list_cmd($3,NULL,"// ",TRUE);
1196          }
1197        | LISTVAR_CMD '(' RING_DECL ')'
1198          {
1199            if ($3==QRING_CMD) $3=RING_CMD;
1200            list_cmd($3,NULL,"// ",TRUE);
1201          }
1202        | LISTVAR_CMD '(' RING_DECL_LIST ')'
1203          {
1204            list_cmd($3,NULL,"// ",TRUE);
1205          }
1206        | LISTVAR_CMD '(' RING_CMD ')'
1207          {
1208            list_cmd(RING_CMD,NULL,"// ",TRUE);
1209          }
1210        | LISTVAR_CMD '(' mat_cmd ')'
1211          {
1212            list_cmd($3,NULL,"// ",TRUE);
1213           }
1214        | LISTVAR_CMD '(' PROC_CMD ')'
1215          {
1216            list_cmd(PROC_CMD,NULL,"// ",TRUE);
1217          }
1218        | LISTVAR_CMD '(' elemexpr ')'
1219          {
1220            list_cmd(0,$3.Fullname(),"// ",TRUE);
1221            $3.CleanUp();
1222          }
1223        | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL ')'
1224          {
1225            if($3.Typ() == PACKAGE_CMD)
1226              list_cmd($5,NULL,"// ",TRUE);
1227            $3.CleanUp();
1228          }
1229        | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL_LIST ')'
1230          {
1231            if($3.Typ() == PACKAGE_CMD)
1232              list_cmd($5,NULL,"// ",TRUE);
1233            $3.CleanUp();
1234          }
1235        | LISTVAR_CMD '(' elemexpr ',' RING_DECL ')'
1236          {
1237            if($3.Typ() == PACKAGE_CMD)
1238              list_cmd($5,NULL,"// ",TRUE);
1239            $3.CleanUp();
1240          }
1241        | LISTVAR_CMD '(' elemexpr ',' RING_DECL_LIST ')'
1242          {
1243            if($3.Typ() == PACKAGE_CMD)
1244              list_cmd($5,NULL,"// ",TRUE);
1245            $3.CleanUp();
1246          }
1247        | LISTVAR_CMD '(' elemexpr ',' RING_CMD ')'
1248          {
1249            if($3.Typ() == PACKAGE_CMD)
1250              list_cmd($5,NULL,"// ",TRUE);
1251            $3.CleanUp();
1252          }
1253        | LISTVAR_CMD '(' elemexpr ',' mat_cmd ')'
1254          {
1255            if($3.Typ() == PACKAGE_CMD)
1256              list_cmd($5,NULL,"// ",TRUE);
1257            $3.CleanUp();
1258          }
1259        | LISTVAR_CMD '(' elemexpr ',' PROC_CMD ')'
1260          {
1261            if($3.Typ() == PACKAGE_CMD)
1262              list_cmd($5,NULL,"// ",TRUE);
1263            $3.CleanUp();
1264          }
1265        //| LISTVAR_CMD '(' elemexpr ',' elemexpr ')'
1266        //  {
1267        //    //if($3.Typ() == PACKAGE_CMD)
1268        //    //  list_cmd($5,NULL,"// ",TRUE);
1269        //    $3.CleanUp();
1270        //  }
1271        | LISTVAR_CMD '(' ')'
1272          {
1273            list_cmd(-1,NULL,"// ",TRUE);
1274          }
1275        ;
1276
1277ringcmd1:
1278       RING_CMD { yyInRingConstruction = TRUE; }
1279       ;
1280
1281ringcmd:
1282        ringcmd1
1283          elemexpr cmdeq
1284          rlist     ','      /* description of coeffs */
1285          rlist     ','      /* var names */
1286          ordering           /* list of (multiplier ordering (weight(s))) */
1287          {
1288            const char *ring_name = $2.name;
1289            ring b=
1290            rInit(&$4,            /* characteristik and list of parameters*/
1291                  &$6,            /* names of ringvariables */
1292                  &$8);            /* ordering */
1293            idhdl newRingHdl=NULL;
1294
1295            if (b!=NULL)
1296            {
1297              newRingHdl=enterid(ring_name, myynest, RING_CMD,
1298                                   &($2.req_packhdl->idroot),FALSE);
1299              $2.CleanUp();
1300              if (newRingHdl!=NULL)
1301              {
1302                IDRING(newRingHdl)=b;
1303              }
1304              else
1305              {
1306                rKill(b);
1307              }
1308            }
1309            yyInRingConstruction = FALSE;
1310            if (newRingHdl==NULL)
1311            {
1312              MYYERROR("cannot make ring");
1313            }
1314            else
1315            {
1316              rSetHdl(newRingHdl);
1317            }
1318          }
1319        | ringcmd1 elemexpr
1320          {
1321            const char *ring_name = $2.name;
1322            if (!inerror) rDefault(ring_name);
1323            yyInRingConstruction = FALSE;
1324            $2.CleanUp();
1325          }
1326        | ringcmd1 elemexpr cmdeq elemexpr
1327          {
1328            yyInRingConstruction = FALSE;
1329            if (iiAssignCR(&$2,&$4)) YYERROR;
1330          }
1331        | ringcmd1 elemexpr cmdeq elemexpr '[' exprlist ']'
1332        {
1333          yyInRingConstruction = FALSE;
1334          sleftv tmp;
1335          $4.next=(leftv)omAlloc(sizeof(sleftv));
1336          memcpy($4.next,&$6,sizeof(sleftv));
1337          memset(&$6,0,sizeof(sleftv));
1338          if (iiExprArithM(&tmp,&$4,'[')) YYERROR;
1339          if (iiAssignCR(&$2,&tmp)) YYERROR;
1340        }
1341        ;
1342
1343scriptcmd:
1344         SYSVAR stringexpr
1345          {
1346            if (($1!=LIB_CMD)||(jjLOAD($2,TRUE))) YYERROR;
1347          }
1348        ;
1349
1350setrings:  SETRING_CMD | KEEPRING_CMD ;
1351
1352setringcmd:
1353        setrings expr
1354          {
1355            if (($1==KEEPRING_CMD) && (myynest==0))
1356               MYYERROR("only inside a proc allowed");
1357            const char * n=$2.Name();
1358            if (($2.Typ()==RING_CMD)
1359            && ($2.rtyp==IDHDL))
1360            {
1361              idhdl h=(idhdl)$2.data;
1362              if ($2.e!=NULL) h=rFindHdl((ring)$2.Data(),NULL);
1363              //Print("setring %s lev %d (ptr:%x)\n",IDID(h),IDLEV(h),IDRING(h));
1364              if ($1==KEEPRING_CMD)
1365              {
1366                if (h!=NULL)
1367                {
1368                  if (IDLEV(h)!=0)
1369                  {
1370                    if (iiExport(&$2,myynest-1)) YYERROR;
1371#if 1
1372                    idhdl p=IDRING(h)->idroot;
1373                    idhdl root=p;
1374                    int prevlev=myynest-1;
1375                    while (p!=NULL)
1376                    {
1377                      if (IDLEV(p)==myynest)
1378                      {
1379                        idhdl old=root->get(IDID(p),prevlev);
1380                        if (old!=NULL)
1381                        {
1382                          if (BVERBOSE(V_REDEFINE))
1383                            Warn("redefining %s",IDID(p));
1384                          killhdl2(old,&root,IDRING(h));
1385                          IDRING(h)->idroot=root;
1386                        }
1387                        IDLEV(p)=prevlev;
1388                      }
1389                      p=IDNEXT(p);
1390                    }
1391#endif
1392                  }
1393                  iiLocalRing[myynest-1]=IDRING(h);
1394                }
1395                else
1396                {
1397                  Werror("%s is no identifier",n);
1398                  $2.CleanUp();
1399                  YYERROR;
1400                }
1401              }
1402              if (h!=NULL) rSetHdl(h);
1403              else
1404              {
1405                Werror("cannot find the name of the basering %s",n);
1406                $2.CleanUp();
1407                YYERROR;
1408              }
1409              $2.CleanUp();
1410            }
1411            else
1412            {
1413              Werror("%s is no name of a ring/qring",n);
1414              $2.CleanUp();
1415              YYERROR;
1416            }
1417          }
1418        ;
1419
1420typecmd:
1421        TYPE_CMD expr
1422          {
1423            type_cmd(&($2));
1424          }
1425        | exprlist
1426          {
1427            //Print("typ is %d, rtyp:%d\n",$1.Typ(),$1.rtyp);
1428            #ifdef SIQ
1429            if ($1.rtyp!=COMMAND)
1430            {
1431            #endif
1432              if ($1.Typ()==UNKNOWN)
1433              {
1434                if ($1.name!=NULL)
1435                {
1436                  Werror("`%s` is undefined",$1.name);
1437                  omFree((ADDRESS)$1.name);
1438                }
1439                YYERROR;
1440              }
1441            #ifdef SIQ
1442            }
1443            #endif
1444            $1.Print(&sLastPrinted);
1445            $1.CleanUp(currRing);
1446            if (errorreported) YYERROR;
1447          }
1448        ;
1449
1450/* --------------------------------------------------------------------*/
1451/* section of flow control                                             */
1452/* --------------------------------------------------------------------*/
1453
1454ifcmd: IF_CMD '(' expr ')' BLOCKTOK
1455          {
1456            int i; TESTSETINT($3,i);
1457            if (i!=0)
1458            {
1459              newBuffer( $5, BT_if);
1460            }
1461            else
1462            {
1463              omFree((ADDRESS)$5);
1464              currentVoice->ifsw=1;
1465            }
1466          }
1467        | ELSE_CMD BLOCKTOK
1468          {
1469            if (currentVoice->ifsw==1)
1470            {
1471              currentVoice->ifsw=0;
1472              newBuffer( $2, BT_else);
1473            }
1474            else
1475            {
1476              if (currentVoice->ifsw!=2)
1477              {
1478                Warn("`else` without `if` in level %d",myynest);
1479              }
1480              omFree((ADDRESS)$2);
1481            }
1482            currentVoice->ifsw=0;
1483          }
1484        | IF_CMD '(' expr ')' BREAK_CMD
1485          {
1486            int i; TESTSETINT($3,i);
1487            if (i)
1488            {
1489              if (exitBuffer(BT_break)) YYERROR;
1490            }
1491            currentVoice->ifsw=0;
1492          }
1493        | BREAK_CMD
1494          {
1495            if (exitBuffer(BT_break)) YYERROR;
1496            currentVoice->ifsw=0;
1497          }
1498        | CONTINUE_CMD
1499          {
1500            if (contBuffer(BT_break)) YYERROR;
1501            currentVoice->ifsw=0;
1502          }
1503      ;
1504
1505whilecmd:
1506        WHILE_CMD STRINGTOK BLOCKTOK
1507          {
1508            /* -> if(!$2) break; $3; continue;*/
1509            char * s = (char *)omAlloc( strlen($2) + strlen($3) + 36);
1510            sprintf(s,"whileif (!(%s)) break;\n%scontinue;\n " ,$2,$3);
1511            newBuffer(s,BT_break);
1512            omFree((ADDRESS)$2);
1513            omFree((ADDRESS)$3);
1514          }
1515        ;
1516
1517forcmd:
1518        FOR_CMD STRINGTOK STRINGTOK STRINGTOK BLOCKTOK
1519          {
1520            /* $2 */
1521            /* if (!$3) break; $5; $4; continue; */
1522            char * s = (char *)omAlloc( strlen($3)+strlen($4)+strlen($5)+36);
1523            sprintf(s,"forif (!(%s)) break;\n%s%s;\ncontinue;\n "
1524                   ,$3,$5,$4);
1525            omFree((ADDRESS)$3);
1526            omFree((ADDRESS)$4);
1527            omFree((ADDRESS)$5);
1528            newBuffer(s,BT_break);
1529            s = (char *)omAlloc( strlen($2) + 3);
1530            sprintf(s,"%s;\n",$2);
1531            omFree((ADDRESS)$2);
1532            newBuffer(s,BT_if);
1533          }
1534        ;
1535
1536proccmd:
1537        PROC_CMD extendedid BLOCKTOK
1538          {
1539            idhdl h = enterid($2,myynest,PROC_CMD,&IDROOT,TRUE);
1540            if (h==NULL) {omFree((ADDRESS)$2);omFree((ADDRESS)$3); YYERROR;}
1541            iiInitSingularProcinfo(IDPROC(h),"", $2, 0, 0);
1542            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+31);;
1543            sprintf(IDPROC(h)->data.s.body,"parameter list #;\n%s;return();\n\n",$3);
1544            omFree((ADDRESS)$3);
1545            omFree((ADDRESS)$2);
1546          }
1547        | PROC_DEF STRINGTOK BLOCKTOK
1548          {
1549            idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE);
1550            if (h==NULL)
1551            {
1552              omFree((ADDRESS)$1);
1553              omFree((ADDRESS)$2);
1554              omFree((ADDRESS)$3);
1555              YYERROR;
1556            }
1557            char *args=iiProcArgs($2,FALSE);
1558            omFree((ADDRESS)$2);
1559            iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0);
1560            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+strlen(args)+14);;
1561            sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$3);
1562            omFree((ADDRESS)args);
1563            omFree((ADDRESS)$3);
1564            omFree((ADDRESS)$1);
1565          }
1566        | PROC_DEF STRINGTOK STRINGTOK BLOCKTOK
1567          {
1568            omFree((ADDRESS)$3);
1569            idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE);
1570            if (h==NULL)
1571            {
1572              omFree((ADDRESS)$1);
1573              omFree((ADDRESS)$2);
1574              omFree((ADDRESS)$4);
1575              YYERROR;
1576            }
1577            char *args=iiProcArgs($2,FALSE);
1578            omFree((ADDRESS)$2);
1579            iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0);
1580            omFree((ADDRESS)$1);
1581            IDPROC(h)->data.s.body = (char *)omAlloc(strlen($4)+strlen(args)+14);;
1582            sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$4);
1583            omFree((ADDRESS)args);
1584            omFree((ADDRESS)$4);
1585          }
1586        ;
1587
1588parametercmd:
1589        PARAMETER declare_ip_variable
1590          {
1591            // decl. of type proc p(int i)
1592            if ($1==PARAMETER)  { if (iiParameter(&$2)) YYERROR; }
1593            else                { if (iiAlias(&$2)) YYERROR; }
1594          }
1595        | PARAMETER expr
1596          {
1597            // decl. of type proc p(i)
1598            sleftv tmp_expr;
1599            if ($1==ALIAS_CMD) MYYERROR("alias requires a type");
1600            if ((iiDeclCommand(&tmp_expr,&$2,myynest,DEF_CMD,&IDROOT))
1601            || (iiParameter(&tmp_expr)))
1602              YYERROR;
1603          }
1604        ;
1605
1606returncmd:
1607        RETURN '(' exprlist ')'
1608          {
1609            iiRETURNEXPR.Copy(&$3);
1610            $3.CleanUp();
1611            if (exitBuffer(BT_proc)) YYERROR;
1612          }
1613        | RETURN '(' ')'
1614          {
1615            if ($1==RETURN)
1616            {
1617              iiRETURNEXPR.Init();
1618              iiRETURNEXPR.rtyp=NONE;
1619              if (exitBuffer(BT_proc)) YYERROR;
1620            }
1621          }
1622        ;
Note: See TracBrowser for help on using the repository browser.