source: git/Singular/grammar.y @ 3149a5

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