=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Kan/parser.c,v retrieving revision 1.1.1.1 retrieving revision 1.12 diff -u -p -r1.1.1.1 -r1.12 --- OpenXM/src/kan96xx/Kan/parser.c 1999/10/08 02:12:02 1.1.1.1 +++ OpenXM/src/kan96xx/Kan/parser.c 2015/10/08 11:49:37 1.12 @@ -1,14 +1,17 @@ +/* $OpenXM: OpenXM/src/kan96xx/Kan/parser.c,v 1.11 2015/09/29 01:52:14 takayama Exp $ */ /* - parser.c parser for poly.c + parser.c parser for poly.c */ #include +#include #include "datatype.h" #include "setjmp.h" #include "stackm.h" #include "extern.h" #include "extern2.h" + #define NUM 1 /* NUM means struct Bignum */ #define POL 0 @@ -21,8 +24,11 @@ union valObject { POLY p; }; - +#if defined(__CYGWIN__) +static sigjmp_buf EnvOfParser; +#else static jmp_buf EnvOfParser; +#endif static char *String; static int StrPtr = 0; /* String and StrPtr are used in getcharFromStr() */ @@ -100,8 +106,8 @@ static union valObject vpop() { POLY stringToPOLY(s,ringp) -char *s; -struct ring *ringp; + char *s; + struct ring *ringp; { /* call init() [ poly.c ] before you use strToPoly(). */ POLY ppp; @@ -118,24 +124,27 @@ struct ring *ringp; Ring0 = *ringp; Ring0.p = 0; Ring0.next = (struct ring *)NULL; - - if (setjmp(EnvOfParser)) { +#if defined(__CYGWIN__) + if (MYSIGSETJMP(EnvOfParser,1)) { +#else + if (MYSETJMP(EnvOfParser)) { +#endif fprintf(stderr,"\nERROR: You have syntax errors in the expression: %s\n",s); errorKan1("%s\n"," parser.c : Syntax error in the input polynomial."); return( POLYNULL ); /* error */ } else { } ss = (char *)sGC_malloc( strlen(s)+6 ); /* This parser think that an expression - -1+.. is error. ----> - Improved at 1992/03/04.*/ + -1+.. is error. ----> + Improved at 1992/03/04.*/ if (ss == (char *)NULL) errorParser("No more space."); k=0; while (s[k] == ' ') k++; /* This method is quite adhoc. */ /* - if (s[k] == '+' || s[k] == '-') { + if (s[k] == '+' || s[k] == '-') { strcpy(ss,"0"); strcat(ss,&(s[k])); - }else strcpy(ss,&(s[k])); + }else strcpy(ss,&(s[k])); */ strcpy(ss,&(s[k])); /* we introduce new parser which recognize unary - */ k = strlen(ss); @@ -168,7 +177,7 @@ struct ring *ringp; static int mytolower(c) int c; { /*if (c>='A' && c<= 'Z') return( c + 0x20 ); - else return( c ); */ + else return( c ); */ return(c); /* 1992/06/27 : do nothing now. ***/ } @@ -184,14 +193,14 @@ static int getoken() { int i; if (Ch == '\0') return( -1 ); while (isSpace(Ch)) Ch = getcharFromStr(); - if (isDigit(Ch)) { + if (isDigit(Ch)) { Symbol = NUM; Bp = 0; do { Bwork[Bp] = Ch; Bwork[Bp+1] = '\0'; Ch = getcharFromStr(); Bp++; if (Bp >= BIGNUM_ILIMIT-1) { - errorParser(" Too big big-num. "); + errorParser(" Too big big-num. "); } } while (isDigit(Ch)); BigValue = newMP_INT(); @@ -204,8 +213,8 @@ static int getoken() { /* Symbol = NUM; Don't do that. */ Value = 0; do { - Value = Value*10+(Ch-'0'); - Ch = getcharFromStr(); + Value = Value*10+(Ch-'0'); + Ch = getcharFromStr(); } while (isDigit(Ch)); }else errorParser(" Number is expected after x or d. "); } else if (Ch == '@') { @@ -214,7 +223,7 @@ static int getoken() { do { Name[i] = Ch; Name[i+1] = '\0'; i++; if (i+2 >= NAME_MAX) { - errorParser("Too long name begining with @."); + errorParser("Too long name begining with @."); } Ch = getcharFromStr(); } while (isAlphabetNum(Ch)); @@ -224,13 +233,13 @@ static int getoken() { } /***/ /* - if (Symbol == NUM) { - fprintf(stderr,"\nToken type = number"); - } else { - fprintf(stderr,"\nToken type = %c",Symbol); - } - fprintf(stderr," value is %d ",Value); - */ + if (Symbol == NUM) { + fprintf(stderr,"\nToken type = number"); + } else { + fprintf(stderr,"\nToken type = %c",Symbol); + } + fprintf(stderr," value is %d ",Value); + */ } @@ -247,7 +256,7 @@ static void expr() { int gtype, ftype; /* data type. NUM or POL */ POLY gp; POLY fp; POLY rp; /* g -> gp, f->fp, r -> rp , if they are - polynomials */ + polynomials */ POLY tmpp; term(); @@ -273,45 +282,45 @@ static void expr() { fp= (ValTmp).p; }else ; - /* debug */ - /* pWritef(gp,3); printf("\n\n"); sleep(5); */ + /* debug */ + /* pWritef(gp,3); printf("\n\n"); sleep(5); */ if (op == '+') { if (ftype == NUM && gtype == NUM) { - mpz_add(f,f,g); - utmp.ival = f; - push(NUM,utmp); + mpz_add(f,f,g); + utmp.ival = f; + push(NUM,utmp); }else if (ftype== POL && gtype == NUM) { - rp = ppAdd(fp,bxx(g,0,0,&Ring0)); - utmp.p = rp; - push(POL, utmp); + rp = ppAdd(fp,bxx(g,0,0,&Ring0)); + utmp.p = rp; + push(POL, utmp); }else if (ftype==NUM && gtype == POL) { - rp = ppAdd(bxx(f,0,0,&Ring0),gp); - utmp.p = rp; - push(POL,utmp); + rp = ppAdd(bxx(f,0,0,&Ring0),gp); + utmp.p = rp; + push(POL,utmp); }else if (ftype==POL && gtype== POL) { - rp = ppAdd(fp,gp); - utmp.p = rp; - push(POL,utmp); + rp = ppAdd(fp,gp); + utmp.p = rp; + push(POL,utmp); }else ; - + }else { if (ftype == NUM && gtype == NUM) { - mpz_sub(f,f,g); - utmp.ival = f; - push(NUM,utmp); + mpz_sub(f,f,g); + utmp.ival = f; + push(NUM,utmp); }else if (ftype== POL && gtype == NUM) { - rp = ppSub(fp,bxx(g,0,0,&Ring0)); - utmp.p = rp; - push(POL, utmp); + rp = ppSub(fp,bxx(g,0,0,&Ring0)); + utmp.p = rp; + push(POL, utmp); }else if (ftype==NUM && gtype == POL) { - rp = ppSub(bxx(f,0,0,&Ring0),gp); - utmp.p = rp; - push(POL,utmp); + rp = ppSub(bxx(f,0,0,&Ring0),gp); + utmp.p = rp; + push(POL,utmp); }else if (ftype==POL && gtype== POL) { - rp = ppSub(fp,gp); - utmp.p = rp; - push(POL,utmp); + rp = ppSub(fp,gp); + utmp.p = rp; + push(POL,utmp); }else ; } @@ -327,15 +336,15 @@ static void term() { int gtype, ftype; /* data type. NUM or POL */ POLY gp; POLY fp; POLY rp; /* g -> gp, f->fp, r -> rp , if they are - polynomials */ + polynomials */ POLY tmpp; /* Unary + and -. For example -(1+6), -5*3, so on and so forth. - term : factor | - ( + | - )factor | - factor ( * | / ) factor ... | - ( + | - )factor ( * | / ) factor ... + term : factor | + ( + | - )factor | + factor ( * | / ) factor ... | + ( + | - )factor ( * | / ) factor ... */ if (Symbol == '+') { getoken(); @@ -384,37 +393,38 @@ static void term() { if (op == '*') { if (ftype == NUM && gtype == NUM) { - mpz_mul(f,f,g); - utmp.ival = f; - push(NUM,utmp); + mpz_mul(f,f,g); + utmp.ival = f; + push(NUM,utmp); }else if (ftype== POL && gtype == NUM) { - fp = ppMult(bxx(g,0,0,&Ring0),fp); - utmp.p = fp; - push(POL, utmp); + fp = ppMult(bxx(g,0,0,&Ring0),fp); + utmp.p = fp; + push(POL, utmp); }else if (ftype==NUM && gtype == POL) { - gp = ppMult(bxx(f,0,0,&Ring0),gp); - utmp.p = gp; - push(POL,utmp); + gp = ppMult(bxx(f,0,0,&Ring0),gp); + utmp.p = gp; + push(POL,utmp); }else if (ftype==POL && gtype== POL) { - rp = ppMult(fp,gp); - utmp.p = rp; - push(POL,utmp); + rp = ppMult(fp,gp); + utmp.p = rp; + push(POL,utmp); }else ; - + }else { if (ftype == NUM && gtype == NUM) { - mpz_div(f,f,g); - utmp.ival = f; - push(NUM,utmp); + errorParser("num/num is not supported yet.\n"); + mpz_div(f,f,g); + utmp.ival = f; + push(NUM,utmp); }else if (ftype== POL && gtype == NUM) { - errorParser("POLY / num is not supported yet.\n"); - /*pvCoeffDiv(BbToCoeff(g),fp); - utmp.p = fp; - push(POL, utmp);*/ + errorParser("POLY / num is not supported yet.\n"); + /*pvCoeffDiv(BbToCoeff(g),fp); + utmp.p = fp; + push(POL, utmp);*/ }else if (ftype==NUM && gtype == POL) { - errorParser(" / POLY is not supported yet.\n"); + errorParser(" / POLY is not supported yet.\n"); }else if (ftype==POL && gtype== POL) { - errorParser(" / POLY is not supported yet.\n"); + errorParser(" / POLY is not supported yet.\n"); }else ; } @@ -428,7 +438,7 @@ static void factor() { int gtype, ftype; /* data type. NUM or POL */ POLY gp; POLY fp; POLY rp; /* g -> gp, f->fp, r -> rp , if they are - polynomials */ + polynomials */ POLY tmpp; union valObject utmp; @@ -455,19 +465,19 @@ static void factor() { if (1) { if (ftype == NUM && gtype == NUM) { - /* printf("\nf=");mpz_out_str(stdout,10,f); - printf("\ng=");mpz_out_str(stdout,10,g); */ - mpz_pow_ui(f,f,(unsigned long int) mpz_get_si(g)); - utmp.ival = f; - push(NUM,utmp); + /* printf("\nf=");mpz_out_str(stdout,10,f); + printf("\ng=");mpz_out_str(stdout,10,g); */ + mpz_pow_ui(f,f,(unsigned long int) mpz_get_si(g)); + utmp.ival = f; + push(NUM,utmp); }else if (ftype== POL && gtype == NUM) { - rp = pPower(fp,(int)mpz_get_si(g)); - utmp.p = rp; - push(POL,utmp); + rp = pPower(fp,(int)mpz_get_si(g)); + utmp.p = rp; + push(POL,utmp); }else if (ftype==NUM && gtype == POL) { - errorParser("( ) ^ Polynomial is not supported yet.\n"); + errorParser("( ) ^ Polynomial is not supported yet.\n"); }else if (ftype==POL && gtype== POL) { - errorParser("( ) ^ Polynomial is not supported yet.\n"); + errorParser("( ) ^ Polynomial is not supported yet.\n"); }else ; } @@ -478,7 +488,7 @@ static void factor() { static void monom() { union valObject utmp; - struct object obj; + struct object obj = OINIT; POLY f; extern struct context *CurrentContextp; if (Symbol == 'x' || Symbol == 'd') { @@ -494,7 +504,7 @@ static void monom() { }else if (Symbol == '@') { obj = findUserDictionary(&(Name[1]),hash0(&(Name[1])),hash1(&(Name[1])), - CurrentContextp); + CurrentContextp); if (isNullObject(obj)) { fprintf(stderr,"%s",Name); errorParser(" cannot be found in the user dictionary."); @@ -509,8 +519,8 @@ static void monom() { push(POL,utmp); }else{ if (f->m->ringp->n != Ring0.n) { - fprintf(stderr,"%s ",Name); - errorParser("should be a polynomial in the current ring.\n"); + fprintf(stderr,"%s ",Name); + errorParser("should be a polynomial in the current ring.\n"); } utmp.p = modulo0(f,&Ring0); push(POL,utmp); @@ -559,8 +569,11 @@ static void errorParser(s) char s[]; { extern char *GotoLabel; extern int GotoP; extern int ErrorMessageMode; + extern int RestrictedMode, RestrictedMode_saved; int j; char tmpc[1024]; + RestrictedMode = RestrictedMode_saved; + cancelAlarm(); if (ErrorMessageMode == 1 || ErrorMessageMode == 2) { sprintf(tmpc,"\nError(parser.c): "); if (strlen(s) < 1000-strlen(tmpc)) { @@ -569,7 +582,7 @@ static void errorParser(s) char s[]; { strcat(tmpc," The error occured around: "); j = strlen(tmpc); for (i=(((StrPtr-5) >= 0)?StrPtr-5:0) ; - (i= 1023) break; @@ -580,7 +593,7 @@ static void errorParser(s) char s[]; { fprintf(stderr,"%s\n",s); fprintf(stderr,"The error occured around: "); for (i=(((StrPtr-5) >= 0)?StrPtr-5:0) ; - (i>. It is also aborted.\n",GotoLabel); GotoP = 0; } - longjmp(EnvOfParser,1); +#if defined(__CYGWIN__) + MYSIGLONGJMP(EnvOfParser,1); +#else + MYLONGJMP(EnvOfParser,1); +#endif }