source: git/Singular/grammar.y @ 82716e

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