source: git/Singular/grammar.y @ d3e630

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