source: git/Singular/grammar.y @ 745c46

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