source: git/Singular/grammar.y @ 5480da

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