source: git/Singular/grammar.y @ 94466fd

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