/**************************************** * Computer Algebra System SINGULAR * ****************************************/ /* $Id$ */ /* * ABSTRACT: SINGULAR shell grammatik */ %{ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if 0 void debug_list(leftv v) { idhdl r=basePackHdl; idhdl h; BOOLEAN found=FALSE; const char *nn=v->name; h=IDROOT->get(nn,myynest); if (h!=NULL) { Print("Curr::%s, (%s)\n",nn,Tok2Cmdname((int)IDTYP(h))); found=TRUE; } else Print("`%s` not found in IDROOT\n",nn); while (r!=NULL) { if ((IDTYP(r)==PACKAGE_CMD) || (IDTYP(r)==RING_CMD) || (IDTYP(r)==QRING_CMD)) { h=IDPACKAGE(r)->idroot->get(nn,myynest); if (h!=NULL) { Print("%s::%s, (%s)\n",r->id,nn,Tok2Cmdname((int)IDTYP(h))); found=TRUE; } else Print("%s::%s not found\n",r->id,nn); } if (r==basePackHdl) r=IDPACKAGE(r)->idroot; r=r->next; if (r==basePackHdl) break; } if (!found) { listall(TRUE); } } #endif /* From the bison docu: By defining the macro `YYMAXDEPTH', you can control how deep the parser stack can become before a stack overflow occurs. Define the macro with a value that is an integer. This value is the maximum number of tokens that can be shifted (and not reduced) before overflow. It must be a constant expression whose value is known at compile time. The stack space allowed is not necessarily allocated. If you specify a large value for `YYMAXDEPTH', the parser actually allocates a small stack at first, and then makes it bigger by stages as needed. This increasing allocation happens automatically and silently. Therefore, you do not need to make `YYMAXDEPTH' painfully small merely to save space for ordinary inputs that do not need much stack. The default value of `YYMAXDEPTH', if you do not define it, is 10000. */ #define YYMAXDEPTH INT_MAX extern int yylineno; extern FILE* yyin; char my_yylinebuf[80]; const char * currid; BOOLEAN yyInRingConstruction=FALSE; BOOLEAN expected_parms; int cmdtok; int inerror = 0; #define TESTSETINT(a,i) \ if ((a).Typ() != INT_CMD) \ { \ WerrorS("no int expression"); \ YYERROR; \ } \ (i) = (int)((long)(a).Data()); #define MYYERROR(a) { WerrorS(a); YYERROR; } void yyerror(const char * fmt) { BOOLEAN old_errorreported=errorreported; errorreported = TRUE; if (currid!=NULL) { killid(currid,&IDROOT); currid = NULL; } if(inerror==0) { { if ((strlen(fmt)>1) && (strncmp(fmt,"parse",5)!=0) && (strncmp(fmt,"syntax",6)!=0)) WerrorS(fmt); Werror( "error occurred in or before %s line %d: `%s`" ,VoiceName(), yylineno, my_yylinebuf); } if (cmdtok!=0) { const char *s=Tok2Cmdname(cmdtok); if (expected_parms) { Werror("expected %s-expression. type \'help %s;\'",s,s); } else { Werror("wrong type declaration. type \'help %s;\'",s); } } if (!old_errorreported && (lastreserved!=NULL)) { Werror("last reserved name was `%s`",lastreserved); } inerror=1; } if ((currentVoice!=NULL) && (currentVoice->prev!=NULL) && (myynest>0) #ifdef HAVE_SDB && ((sdb_flags &1)==0) #endif ) { Werror("leaving %s",VoiceName()); } #ifdef HAVE_FACTORY // libfac: extern int libfac_interruptflag; libfac_interruptflag=0; #endif } %} /* %expect 22 */ %pure_parser /* special symbols */ %token DOTDOT %token EQUAL_EQUAL %token GE %token LE %token MINUSMINUS %token NOT %token NOTEQUAL %token PLUSPLUS %token COLONCOLON /* types, part 1 (ring indep.)*/ %token GRING_CMD %token INTMAT_CMD %token PROC_CMD %token RING_CMD /* valid when ring defined ! */ %token BEGIN_RING /* types, part 2 */ %token IDEAL_CMD %token MAP_CMD %token MATRIX_CMD %token MODUL_CMD %token NUMBER_CMD %token POLY_CMD %token RESOLUTION_CMD %token VECTOR_CMD /* end types */ /* ring dependent cmd:*/ %token BETTI_CMD %token CHINREM_CMD %token COEFFS_CMD %token COEF_CMD %token CONTRACT_CMD %token DEGREE_CMD %token DEG_CMD %token DIFF_CMD %token DIM_CMD %token DIVISION_CMD %token ELIMINATION_CMD %token E_CMD %token FAREY_CMD %token FETCH_CMD %token FREEMODULE_CMD %token KEEPRING_CMD %token HILBERT_CMD %token HOMOG_CMD %token IMAP_CMD %token INDEPSET_CMD %token INTERRED_CMD %token INTERSECT_CMD %token JACOB_CMD %token JET_CMD %token KBASE_CMD %token KOSZUL_CMD %token LEADCOEF_CMD %token LEADEXP_CMD %token LEAD_CMD %token LEADMONOM_CMD %token LIFTSTD_CMD %token LIFT_CMD %token MAXID_CMD %token MINBASE_CMD %token MINOR_CMD %token MINRES_CMD %token MODULO_CMD %token MONOM_CMD %token MRES_CMD %token MULTIPLICITY_CMD %token ORD_CMD %token PAR_CMD %token PARDEG_CMD %token PREIMAGE_CMD %token QUOTIENT_CMD %token QHWEIGHT_CMD %token REDUCE_CMD %token REGULARITY_CMD %token RES_CMD %token SIMPLIFY_CMD %token SORTVEC_CMD %token SRES_CMD %token STD_CMD %token SUBST_CMD %token SYZYGY_CMD %token VAR_CMD %token VDIM_CMD %token WEDGE_CMD %token WEIGHT_CMD /*system variables in ring block*/ %token VALTVARS %token VMAXDEG %token VMAXMULT %token VNOETHER %token VMINPOLY %token END_RING /* end of ring definitions */ %token CMD_1 %token CMD_2 %token CMD_3 %token CMD_12 %token CMD_13 %token CMD_23 %token CMD_123 %token CMD_M %token ROOT_DECL /* put variables of this type into the idroot list */ %token ROOT_DECL_LIST /* put variables of this type into the idroot list */ %token RING_DECL /* put variables of this type into the currRing list */ %token EXAMPLE_CMD %token EXPORT_CMD %token HELP_CMD %token KILL_CMD %token LIB_CMD %token LISTVAR_CMD %token SETRING_CMD %token TYPE_CMD %token STRINGTOK BLOCKTOK INT_CONST %token UNKNOWN_IDENT RINGVAR PROC_DEF /* control */ %token BREAK_CMD %token CONTINUE_CMD %token ELSE_CMD %token EVAL %token QUOTE %token FOR_CMD %token IF_CMD %token SYS_BREAK %token WHILE_CMD %token RETURN %token PARAMETER /* system variables */ %token SYSVAR %type extendedid %type rlist ordering OrderingList orderelem %type stringexpr %type expr elemexpr exprlist expr_arithmetic %type declare_ip_variable left_value %type ordername %type cmdeq %type currring_lists %type setrings %type ringcmd1 %type '=' '<' '>' '+' '-' COLONCOLON %type '/' '[' ']' '^' ',' ';' /*%nonassoc '=' PLUSEQUAL DOTDOT*/ /*%nonassoc '=' DOTDOT COLONCOLON*/ %nonassoc '=' DOTDOT %left ',' %left '&' %left EQUAL_EQUAL NOTEQUAL %left '<' %left '+' '-' ':' %left '/' '*' %left UMINUS NOT %left '^' %left '[' ']' %left '(' ')' %left PLUSPLUS MINUSMINUS %left COLONCOLON %% lines: /**/ | lines pprompt { if (timerv) { writeTime("used time:"); startTimer(); } if (rtimerv) { writeRTime("used real time:"); startRTimer(); } prompt_char = '>'; #ifdef HAVE_SDB if (sdb_flags & 2) { sdb_flags=1; YYERROR; } #endif if(siCntrlc) { WerrorS("abort..."); while((currentVoice!=NULL) && (currentVoice->prev!=NULL)) exitVoice(); if (currentVoice!=NULL) currentVoice->ifsw=0; } if (errorreported) /* also catches abort... */ { yyerror(""); } if (inerror==2) PrintLn(); errorreported = inerror = cmdtok = 0; lastreserved = currid = NULL; expected_parms = siCntrlc = FALSE; } ; pprompt: flowctrl /* if, while, for, proc */ | command ';' /* commands returning no value */ {currentVoice->ifsw=0;} | declare_ip_variable ';' /* default initialization */ { $1.CleanUp(); currentVoice->ifsw=0;} | returncmd { YYACCEPT; } | SYS_BREAK { currentVoice->ifsw=0; iiDebug(); } | ';' /* ignore empty statements */ {currentVoice->ifsw=0;} | error ';' { #ifdef SIQ siq=0; #endif yyInRingConstruction = FALSE; currentVoice->ifsw=0; if (inerror) { /* bison failed here if ((inerror!=3) && ($1.i' ')) { // 1: yyerror called // 2: scanner put actual string // 3: error rule put token+\n inerror=3; Print(" error at token `%s`\n",iiTwoOps($1.i)); } */ } if (!errorreported) WerrorS("...parse error"); yyerror(""); yyerrok; #ifdef HAVE_SDB if ((sdb_flags & 1) && currentVoice->pi!=NULL) { currentVoice->pi->trace_flag |=1; } else #endif if (myynest>0) { feBufferTypes t=currentVoice->Typ(); //PrintS("leaving yyparse\n"); exitBuffer(BT_proc); if (t==BT_example) YYACCEPT; else YYABORT; } else if (currentVoice->prev!=NULL) { exitVoice(); } #ifdef HAVE_SDB if (sdb_flags &2) sdb_flags=1; #endif } ; flowctrl: ifcmd | whilecmd | example_dummy | forcmd | proccmd | filecmd | helpcmd | examplecmd {if (currentVoice!=NULL) currentVoice->ifsw=0;} ; example_dummy : EXAMPLE_CMD BLOCKTOK { omFree((ADDRESS)$2); } ; command: assign | exportcmd | killcmd | listcmd | parametercmd | ringcmd | scriptcmd | setringcmd | typecmd ; assign: left_value exprlist { if(iiAssign(&$1,&$2)) YYERROR; } ; elemexpr: RINGVAR { if (currRing==NULL) MYYERROR("no ring active"); syMake(&$$,omStrDup($1)); } | extendedid { syMake(&$$,$1); } | elemexpr COLONCOLON elemexpr { if(iiExprArith2(&$$, &$1, COLONCOLON, &$3)) YYERROR; } | elemexpr '(' ')' { if(iiExprArith1(&$$,&$1,'(')) YYERROR; } | elemexpr '(' exprlist ')' { if ($1.rtyp==LIB_CMD) { if(iiExprArith1(&$$,&$3,LIB_CMD)) YYERROR; } else { if ($1.Typ()==UNKNOWN) { if(iiExprArith2(&$$,&$1,'(',&$3)) YYERROR; } else { $1.next=(leftv)omAllocBin(sleftv_bin); memcpy($1.next,&$3,sizeof(sleftv)); if(iiExprArithM(&$$,&$1,'(')) YYERROR; } } } | '[' exprlist ']' { if (currRingHdl==NULL) MYYERROR("no ring active"); int j = 0; memset(&$$,0,sizeof(sleftv)); $$.rtyp=VECTOR_CMD; leftv v = &$2; while (v!=NULL) { int i,t; sleftv tmp; memset(&tmp,0,sizeof(tmp)); i=iiTestConvert((t=v->Typ()),POLY_CMD); if((i==0) || (iiConvert(t /*v->Typ()*/,POLY_CMD,i,v,&tmp))) { pDelete((poly *)&$$.data); $2.CleanUp(); MYYERROR("expected '[poly,...'"); } poly p = (poly)tmp.CopyD(POLY_CMD); pSetCompP(p,++j); $$.data = (void *)pAdd((poly)$$.data,p); v->next=tmp.next;tmp.next=NULL; tmp.CleanUp(); v=v->next; } $2.CleanUp(); } | INT_CONST { memset(&$$,0,sizeof($$)); int i = atoi($1); /*remember not to omFree($1) *because it is a part of the scanner buffer*/ $$.rtyp = INT_CMD; $$.data = (void *)(long)i; /* check: out of range input */ int l = strlen($1)+2; number n; if (l >= MAX_INT_LEN) { char tmp[MAX_INT_LEN+5]; sprintf(tmp,"%d",i); if (strcmp(tmp,$1)!=0) { nlRead($1,&n); $$.rtyp=BIGINT_CMD; $$.data = n; } } } | SYSVAR { memset(&$$,0,sizeof($$)); $$.rtyp = $1; $$.data = $$.Data(); } | stringexpr { memset(&$$,0,sizeof($$)); $$.rtyp = STRING_CMD; $$.data = $1; } ; exprlist: exprlist ',' expr { leftv v = &$1; while (v->next!=NULL) { v=v->next; } v->next = (leftv)omAllocBin(sleftv_bin); memcpy(v->next,&($3),sizeof(sleftv)); $$ = $1; } | expr { $$ = $1; } ; expr: expr_arithmetic { /*if ($1.typ == eunknown) YYERROR;*/ $$ = $1; } | elemexpr { $$ = $1; } | '(' exprlist ')' { $$ = $2; } | expr '[' expr ',' expr ']' { if(iiExprArith3(&$$,'[',&$1,&$3,&$5)) YYERROR; } | expr '[' expr ']' { if(iiExprArith2(&$$,&$1,'[',&$3)) YYERROR; } | ROOT_DECL '(' expr ')' { if(iiExprArith1(&$$,&$3,$1)) YYERROR; } | ROOT_DECL_LIST '(' exprlist ')' { if(iiExprArithM(&$$,&$3,$1)) YYERROR; } | ROOT_DECL_LIST '(' ')' { if(iiExprArithM(&$$,NULL,$1)) YYERROR; } | RING_DECL '(' expr ')' { if(iiExprArith1(&$$,&$3,$1)) YYERROR; } | currring_lists '(' exprlist ')' { if(iiExprArithM(&$$,&$3,$1)) YYERROR; } | currring_lists '(' ')' { if(iiExprArithM(&$$,NULL,$1)) YYERROR; } | CMD_1 '(' expr ')' { if(iiExprArith1(&$$,&$3,$1)) YYERROR; } | CMD_2 '(' expr ',' expr ')' { if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR; } | CMD_3 '(' expr ',' expr ',' expr ')' { if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR; } | CMD_23 '(' expr ',' expr ')' { if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR; } | CMD_23 '(' expr ',' expr ',' expr ')' { if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR; } | CMD_12 '(' expr ')' { if(iiExprArith1(&$$,&$3,$1)) YYERROR; } | CMD_13 '(' expr ')' { if(iiExprArith1(&$$,&$3,$1)) YYERROR; } | CMD_12 '(' expr ',' expr ')' { if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR; } | CMD_123 '(' expr ')' { if(iiExprArith1(&$$,&$3,$1)) YYERROR; } | CMD_123 '(' expr ',' expr ')' { if(iiExprArith2(&$$,&$3,$1,&$5,TRUE)) YYERROR; } | CMD_13 '(' expr ',' expr ',' expr ')' { if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR; } | CMD_123 '(' expr ',' expr ',' expr ')' { if(iiExprArith3(&$$,$1,&$3,&$5,&$7)) YYERROR; } | CMD_M '(' ')' { if(iiExprArithM(&$$,NULL,$1)) YYERROR; } | CMD_M '(' exprlist ')' { if(iiExprArithM(&$$,&$3,$1)) YYERROR; } | MATRIX_CMD '(' expr ',' expr ',' expr ')' { if(iiExprArith3(&$$,MATRIX_CMD,&$3,&$5,&$7)) YYERROR; } | MATRIX_CMD '(' expr ')' { if(iiExprArith1(&$$,&$3,MATRIX_CMD)) YYERROR; } | INTMAT_CMD '(' expr ',' expr ',' expr ')' { if(iiExprArith3(&$$,INTMAT_CMD,&$3,&$5,&$7)) YYERROR; } | INTMAT_CMD '(' expr ')' { if(iiExprArith1(&$$,&$3,INTMAT_CMD)) YYERROR; } | RING_CMD '(' rlist ',' rlist ',' ordering ')' { if(iiExprArith3(&$$,RING_CMD,&$3,&$5,&$7)) YYERROR; } | RING_CMD '(' expr ')' { if(iiExprArith1(&$$,&$3,RING_CMD)) YYERROR; } | quote_start expr quote_end { $$=$2; } | quote_start expr '=' expr quote_end { #ifdef SIQ siq++; if (siq>0) { if (iiExprArith2(&$$,&$2,'=',&$4)) YYERROR; } else #endif { memset(&$$,0,sizeof($$)); $$.rtyp=NONE; if (iiAssign(&$2,&$4)) YYERROR; } #ifdef SIQ siq--; #endif } | EVAL '(' { #ifdef SIQ siq--; #endif } expr ')' { #ifdef SIQ if (siq<=0) $4.Eval(); #endif $$=$4; #ifdef SIQ siq++; #endif } ; quote_start: QUOTE '(' { #ifdef SIQ siq++; #endif } ; quote_end: ')' { #ifdef SIQ siq--; #endif } ; expr_arithmetic: expr PLUSPLUS %prec PLUSPLUS { if(iiExprArith1(&$$,&$1,PLUSPLUS)) YYERROR; } | expr MINUSMINUS %prec MINUSMINUS { if(iiExprArith1(&$$,&$1,MINUSMINUS)) YYERROR; } | expr '+' expr { if(iiExprArith2(&$$,&$1,'+',&$3)) YYERROR; } | expr '-' expr { if(iiExprArith2(&$$,&$1,'-',&$3)) YYERROR; } | expr '/' expr { if(iiExprArith2(&$$,&$1,$2,&$3)) YYERROR; } | expr '^' expr { if(iiExprArith2(&$$,&$1,'^',&$3)) YYERROR; } | expr '<' expr { if(iiExprArith2(&$$,&$1,$2,&$3)) YYERROR; } | expr '&' expr { if(iiExprArith2(&$$,&$1,$2,&$3)) YYERROR; } | expr NOTEQUAL expr { if(iiExprArith2(&$$,&$1,NOTEQUAL,&$3)) YYERROR; } | expr EQUAL_EQUAL expr { if(iiExprArith2(&$$,&$1,EQUAL_EQUAL,&$3)) YYERROR; } | expr DOTDOT expr { if(iiExprArith2(&$$,&$1,DOTDOT,&$3)) YYERROR; } | expr ':' expr { if(iiExprArith2(&$$,&$1,':',&$3)) YYERROR; } | NOT expr { memset(&$$,0,sizeof($$)); int i; TESTSETINT($2,i); $$.rtyp = INT_CMD; $$.data = (void *)(long)(i == 0 ? 1 : 0); } | '-' expr %prec UMINUS { if(iiExprArith1(&$$,&$2,'-')) YYERROR; } ; left_value: declare_ip_variable cmdeq { $$ = $1; } | exprlist '=' { if ($1.rtyp==0) { Werror("`%s` is undefined",$1.Fullname()); YYERROR; } else if (($1.rtyp==MODUL_CMD) // matrix m; m[2]=... && ($1.e!=NULL) && ($1.e->next==NULL)) { MYYERROR("matrix must have 2 indices"); } $$ = $1; } ; extendedid: UNKNOWN_IDENT | '`' expr '`' { if ($2.Typ()!=STRING_CMD) { MYYERROR("string expression expected"); } $$ = (char *)$2.CopyD(STRING_CMD); $2.CleanUp(); } ; currring_lists: IDEAL_CMD | MODUL_CMD /* put variables into the current ring */ ; declare_ip_variable: ROOT_DECL elemexpr { if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot))) YYERROR; } | ROOT_DECL_LIST elemexpr { if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot))) YYERROR; } | RING_DECL elemexpr { if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR; } | currring_lists elemexpr { if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR; } | MATRIX_CMD elemexpr '[' expr ']' '[' expr ']' { if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR; int r; TESTSETINT($4,r); int c; TESTSETINT($7,c); if (r < 1) MYYERROR("rows must be greater than 0"); if (c < 0) MYYERROR("cols must be greater than -1"); leftv v=&$$; //while (v->next!=NULL) { v=v->next; } idhdl h=(idhdl)v->data; idDelete(&IDIDEAL(h)); IDMATRIX(h) = mpNew(r,c); if (IDMATRIX(h)==NULL) YYERROR; } | MATRIX_CMD elemexpr { if (iiDeclCommand(&$$,&$2,myynest,$1,&(currRing->idroot), TRUE)) YYERROR; } | INTMAT_CMD elemexpr '[' expr ']' '[' expr ']' { int r; TESTSETINT($4,r); int c; TESTSETINT($7,c); if (r < 1) MYYERROR("rows must be greater than 0"); if (c < 0) MYYERROR("cols must be greater than -1"); if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot))) YYERROR; leftv v=&$$; idhdl h=(idhdl)v->data; delete IDINTVEC(h); IDINTVEC(h) = new intvec(r,c,0); if (IDINTVEC(h)==NULL) YYERROR; } | INTMAT_CMD elemexpr { if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot))) YYERROR; leftv v=&$$; idhdl h; do { h=(idhdl)v->data; delete IDINTVEC(h); IDINTVEC(h) = new intvec(1,1,0); v=v->next; } while (v!=NULL); } | declare_ip_variable ',' elemexpr { int t=$1.Typ(); sleftv r; memset(&r,0,sizeof(sleftv)); if ((BEGIN_RINGidroot), TRUE)) YYERROR; } else { if (iiDeclCommand(&r,&$3,myynest,t,&($3.req_packhdl->idroot))) YYERROR; } leftv v=&$1; while (v->next!=NULL) v=v->next; v->next=(leftv)omAllocBin(sleftv_bin); memcpy(v->next,&r,sizeof(sleftv)); $$=$1; } | PROC_CMD elemexpr { if (iiDeclCommand(&$$,&$2,myynest,$1,&($2.req_packhdl->idroot))) YYERROR; } ; stringexpr: STRINGTOK ; rlist: expr | '(' expr ',' exprlist ')' { leftv v = &$2; while (v->next!=NULL) { v=v->next; } v->next = (leftv)omAllocBin(sleftv_bin); memcpy(v->next,&($4),sizeof(sleftv)); $$ = $2; } ; ordername: UNKNOWN_IDENT { // let rInit take care of any errors $$=rOrderName($1); } ; orderelem: ordername { memset(&$$,0,sizeof($$)); intvec *iv = new intvec(2); (*iv)[0] = 1; (*iv)[1] = $1; $$.rtyp = INTVEC_CMD; $$.data = (void *)iv; } | ordername '(' exprlist ')' { memset(&$$,0,sizeof($$)); leftv sl = &$3; int slLength; { slLength = exprlist_length(sl); int l = 2 + slLength; intvec *iv = new intvec(l); (*iv)[0] = slLength; (*iv)[1] = $1; int i = 2; while ((iTyp() == INT_CMD) { (*iv)[i++] = (int)((long)(sl->Data())); } else if ((sl->Typ() == INTVEC_CMD) ||(sl->Typ() == INTMAT_CMD)) { intvec *ivv = (intvec *)(sl->Data()); int ll = 0,l = ivv->length(); for (; l>0; l--) { (*iv)[i++] = (*ivv)[ll++]; } } else { delete iv; $3.CleanUp(); MYYERROR("wrong type in ordering"); } sl = sl->next; } $$.rtyp = INTVEC_CMD; $$.data = (void *)iv; } $3.CleanUp(); } ; OrderingList: orderelem | orderelem ',' OrderingList { $$ = $1; $$.next = (sleftv *)omAllocBin(sleftv_bin); memcpy($$.next,&$3,sizeof(sleftv)); } ; ordering: orderelem | '(' OrderingList ')' { $$ = $2; } ; cmdeq: '=' { expected_parms = TRUE; } ; /* --------------------------------------------------------------------*/ /* section of pure commands */ /* --------------------------------------------------------------------*/ filecmd: '<' stringexpr { if ($1 != '<') YYERROR; if((feFilePending=feFopen($2,"r",NULL,TRUE))==NULL) YYERROR; } ';' { newFile($2,feFilePending); } ; helpcmd: HELP_CMD STRINGTOK ';' { feHelp($2); omFree((ADDRESS)$2); } | HELP_CMD ';' { feHelp(NULL); } ; examplecmd: EXAMPLE_CMD STRINGTOK ';' { singular_example($2); omFree((ADDRESS)$2); } ; exportcmd: EXPORT_CMD exprlist { if (basePack!=$2.req_packhdl) { if(iiExport(&$2,0,currPackHdl)) YYERROR; } else if (iiExport(&$2,0)) YYERROR; } ; killcmd: KILL_CMD elemexpr { leftv v=&$2; if (v->rtyp!=IDHDL) { if (v->name!=NULL) { Werror("`%s` is undefined in kill",v->name); } else WerrorS("kill what ?"); } else { killhdl((idhdl)v->data,v->req_packhdl); } } | killcmd ',' elemexpr { leftv v=&$3; if (v->rtyp!=IDHDL) { if (v->name!=NULL) { Werror("`%s` is undefined in kill",v->name); } else WerrorS("kill what ?"); } else { killhdl((idhdl)v->data,v->req_packhdl); } } ; listcmd: LISTVAR_CMD '(' ROOT_DECL ')' { list_cmd($3,NULL,"// ",TRUE); } | LISTVAR_CMD '(' ROOT_DECL_LIST ')' { list_cmd($3,NULL,"// ",TRUE); } | LISTVAR_CMD '(' RING_DECL ')' { if ($3==QRING_CMD) $3=RING_CMD; list_cmd($3,NULL,"// ",TRUE); } | LISTVAR_CMD '(' currring_lists ')' { list_cmd($3,NULL,"// ",TRUE); } | LISTVAR_CMD '(' RING_CMD ')' { list_cmd(RING_CMD,NULL,"// ",TRUE); } | LISTVAR_CMD '(' MATRIX_CMD ')' { list_cmd(MATRIX_CMD,NULL,"// ",TRUE); } | LISTVAR_CMD '(' INTMAT_CMD ')' { list_cmd(INTMAT_CMD,NULL,"// ",TRUE); } | LISTVAR_CMD '(' PROC_CMD ')' { list_cmd(PROC_CMD,NULL,"// ",TRUE); } | LISTVAR_CMD '(' elemexpr ')' { list_cmd(0,$3.Fullname(),"// ",TRUE); $3.CleanUp(); } | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL ')' { if($3.Typ() == PACKAGE_CMD) list_cmd($5,NULL,"// ",TRUE); $3.CleanUp(); } | LISTVAR_CMD '(' elemexpr ',' ROOT_DECL_LIST ')' { if($3.Typ() == PACKAGE_CMD) list_cmd($5,NULL,"// ",TRUE); $3.CleanUp(); } | LISTVAR_CMD '(' elemexpr ',' RING_DECL ')' { if($3.Typ() == PACKAGE_CMD) list_cmd($5,NULL,"// ",TRUE); $3.CleanUp(); } | LISTVAR_CMD '(' elemexpr ',' currring_lists ')' { if($3.Typ() == PACKAGE_CMD) list_cmd($5,NULL,"// ",TRUE); $3.CleanUp(); } | LISTVAR_CMD '(' elemexpr ',' RING_CMD ')' { if($3.Typ() == PACKAGE_CMD) list_cmd($5,NULL,"// ",TRUE); $3.CleanUp(); } | LISTVAR_CMD '(' elemexpr ',' MATRIX_CMD ')' { if($3.Typ() == PACKAGE_CMD) list_cmd($5,NULL,"// ",TRUE); $3.CleanUp(); } | LISTVAR_CMD '(' elemexpr ',' INTMAT_CMD ')' { if($3.Typ() == PACKAGE_CMD) list_cmd($5,NULL,"// ",TRUE); $3.CleanUp(); } | LISTVAR_CMD '(' elemexpr ',' PROC_CMD ')' { if($3.Typ() == PACKAGE_CMD) list_cmd($5,NULL,"// ",TRUE); $3.CleanUp(); } //| LISTVAR_CMD '(' elemexpr ',' elemexpr ')' // { // //if($3.Typ() == PACKAGE_CMD) // // list_cmd($5,NULL,"// ",TRUE); // $3.CleanUp(); // } | LISTVAR_CMD '(' ')' { list_cmd(-1,NULL,"// ",TRUE); } ; ringcmd1: RING_CMD { yyInRingConstruction = TRUE; } ; ringcmd: ringcmd1 elemexpr cmdeq rlist ',' /* description of coeffs */ rlist ',' /* var names */ ordering /* list of (multiplier ordering (weight(s))) */ { const char *ring_name = $2.name; ring b= rInit(&$4, /* characteristik and list of parameters*/ &$6, /* names of ringvariables */ &$8); /* ordering */ idhdl newRingHdl=NULL; if (b!=NULL) { newRingHdl=enterid(ring_name, myynest, RING_CMD, &($2.req_packhdl->idroot)); $2.CleanUp(); if (newRingHdl!=NULL) { omFreeSize(IDRING(newRingHdl),sizeof(ip_sring)); IDRING(newRingHdl)=b; } else { rKill(b); } } yyInRingConstruction = FALSE; if (newRingHdl==NULL) { MYYERROR("cannot make ring"); } else { rSetHdl(newRingHdl); } } | ringcmd1 elemexpr { const char *ring_name = $2.name; if (!inerror) rDefault(ring_name); yyInRingConstruction = FALSE; $2.CleanUp(); } ; scriptcmd: SYSVAR stringexpr { if (($1!=LIB_CMD)||(iiLibCmd($2,TRUE,TRUE,TRUE))) //if ($1==LIB_CMD) //{ // sleftv tmp; // if(iiExprArith1(&tmp,&$2,LIB_CMD)) YYERROR; //} //else YYERROR; } ; setrings: SETRING_CMD | KEEPRING_CMD ; setringcmd: setrings expr { if (($1==KEEPRING_CMD) && (myynest==0)) MYYERROR("only inside a proc allowed"); const char * n=$2.Name(); if ((($2.Typ()==RING_CMD)||($2.Typ()==QRING_CMD)) && ($2.rtyp==IDHDL)) { idhdl h=(idhdl)$2.data; if ($2.e!=NULL) h=rFindHdl((ring)$2.Data(),NULL, NULL); //Print("setring %s lev %d (ptr:%x)\n",IDID(h),IDLEV(h),IDRING(h)); if ($1==KEEPRING_CMD) { if (h!=NULL) { if (IDLEV(h)!=0) { if (iiExport(&$2,myynest-1)) YYERROR; #if 1 idhdl p=IDRING(h)->idroot; idhdl root=p; int prevlev=myynest-1; while (p!=NULL) { if (IDLEV(p)==myynest) { idhdl old=root->get(IDID(p),prevlev); if (old!=NULL) { if (BVERBOSE(V_REDEFINE)) Warn("redefining %s",IDID(p)); killhdl2(old,&root,IDRING(h)); IDRING(h)->idroot=root; } IDLEV(p)=prevlev; } p=IDNEXT(p); } #endif } #ifdef USE_IILOCALRING iiLocalRing[myynest-1]=IDRING(h); #endif procstack->cRing=IDRING(h); procstack->cRingHdl=h; } else { Werror("%s is no identifier",n); $2.CleanUp(); YYERROR; } } if (h!=NULL) rSetHdl(h); else { Werror("cannot find the name of the basering %s",n); $2.CleanUp(); YYERROR; } $2.CleanUp(); } else { Werror("%s is no name of a ring/qring",n); $2.CleanUp(); YYERROR; } } ; typecmd: TYPE_CMD expr { if ($2.rtyp!=IDHDL) MYYERROR("identifier expected"); idhdl h = (idhdl)$2.data; type_cmd(h); } | exprlist { //Print("typ is %d, rtyp:%d\n",$1.Typ(),$1.rtyp); #ifdef SIQ if ($1.rtyp!=COMMAND) { #endif if ($1.Typ()==UNKNOWN) { if ($1.name!=NULL) { Werror("`%s` is undefined",$1.name); omFree((ADDRESS)$1.name); } YYERROR; } #ifdef SIQ } #endif $1.Print(&sLastPrinted); $1.CleanUp(currRing); if (errorreported) YYERROR; } ; /* --------------------------------------------------------------------*/ /* section of flow control */ /* --------------------------------------------------------------------*/ ifcmd: IF_CMD '(' expr ')' BLOCKTOK { int i; TESTSETINT($3,i); if (i!=0) { newBuffer( $5, BT_if); } else { omFree((ADDRESS)$5); currentVoice->ifsw=1; } } | ELSE_CMD BLOCKTOK { if (currentVoice->ifsw==1) { currentVoice->ifsw=0; newBuffer( $2, BT_else); } else { if (currentVoice->ifsw!=2) { Warn("`else` without `if` in level %d",myynest); } omFree((ADDRESS)$2); } currentVoice->ifsw=0; } | IF_CMD '(' expr ')' BREAK_CMD { int i; TESTSETINT($3,i); if (i) { if (exitBuffer(BT_break)) YYERROR; } currentVoice->ifsw=0; } | BREAK_CMD { if (exitBuffer(BT_break)) YYERROR; currentVoice->ifsw=0; } | CONTINUE_CMD { if (contBuffer(BT_break)) YYERROR; currentVoice->ifsw=0; } ; whilecmd: WHILE_CMD STRINGTOK BLOCKTOK { /* -> if(!$2) break; $3; continue;*/ char * s = (char *)omAlloc( strlen($2) + strlen($3) + 36); sprintf(s,"whileif (!(%s)) break;\n%scontinue;\n " ,$2,$3); newBuffer(s,BT_break); omFree((ADDRESS)$2); omFree((ADDRESS)$3); } ; forcmd: FOR_CMD STRINGTOK STRINGTOK STRINGTOK BLOCKTOK { /* $2 */ /* if (!$3) break; $5; $4; continue; */ char * s = (char *)omAlloc( strlen($3)+strlen($4)+strlen($5)+36); sprintf(s,"forif (!(%s)) break;\n%s%s;\ncontinue;\n " ,$3,$5,$4); omFree((ADDRESS)$3); omFree((ADDRESS)$4); omFree((ADDRESS)$5); newBuffer(s,BT_break); s = (char *)omAlloc( strlen($2) + 3); sprintf(s,"%s;\n",$2); omFree((ADDRESS)$2); newBuffer(s,BT_if); } ; proccmd: PROC_CMD extendedid BLOCKTOK { procinfov pi; idhdl h = enterid($2,myynest,PROC_CMD,&IDROOT,TRUE); if (h==NULL) {omFree((ADDRESS)$2);omFree((ADDRESS)$3); YYERROR;} iiInitSingularProcinfo(IDPROC(h),"", $2, 0, 0); IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+31);; sprintf(IDPROC(h)->data.s.body,"parameter list #;\n%s;return();\n\n",$3); omFree((ADDRESS)$3); omFree((ADDRESS)$2); } | PROC_DEF STRINGTOK BLOCKTOK { idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE); if (h==NULL) { omFree((ADDRESS)$1); omFree((ADDRESS)$2); omFree((ADDRESS)$3); YYERROR; } char *args=iiProcArgs($2,FALSE); omFree((ADDRESS)$2); procinfov pi; iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0); IDPROC(h)->data.s.body = (char *)omAlloc(strlen($3)+strlen(args)+14);; sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$3); omFree((ADDRESS)args); omFree((ADDRESS)$3); omFree((ADDRESS)$1); } | PROC_DEF STRINGTOK STRINGTOK BLOCKTOK { omFree((ADDRESS)$3); idhdl h = enterid($1,myynest,PROC_CMD,&IDROOT,TRUE); if (h==NULL) { omFree((ADDRESS)$1); omFree((ADDRESS)$2); omFree((ADDRESS)$4); YYERROR; } char *args=iiProcArgs($2,FALSE); omFree((ADDRESS)$2); procinfov pi; iiInitSingularProcinfo(IDPROC(h),"", $1, 0, 0); omFree((ADDRESS)$1); IDPROC(h)->data.s.body = (char *)omAlloc(strlen($4)+strlen(args)+14);; sprintf(IDPROC(h)->data.s.body,"%s\n%s;return();\n\n",args,$4); omFree((ADDRESS)args); omFree((ADDRESS)$4); } ; parametercmd: PARAMETER declare_ip_variable { // decl. of type proc p(int i) if ($1==PARAMETER) { if (iiParameter(&$2)) YYERROR; } else { if (iiAlias(&$2)) YYERROR; } } | PARAMETER expr { // decl. of type proc p(i) sleftv tmp_expr; if ($1==ALIAS_CMD) MYYERROR("alias requires a type"); if ((iiDeclCommand(&tmp_expr,&$2,myynest,DEF_CMD,&IDROOT)) || (iiParameter(&tmp_expr))) YYERROR; } ; returncmd: RETURN '(' exprlist ')' { if(iiRETURNEXPR==NULL) YYERROR; iiRETURNEXPR[myynest].Copy(&$3); $3.CleanUp(); if (exitBuffer(BT_proc)) YYERROR; } | RETURN '(' ')' { if ($1==RETURN) { if(iiRETURNEXPR==NULL) YYERROR; iiRETURNEXPR[myynest].Init(); iiRETURNEXPR[myynest].rtyp=NONE; if (exitBuffer(BT_proc)) YYERROR; } } ;