[BACK]Return to parser.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / kan96xx / Kan

Diff for /OpenXM/src/kan96xx/Kan/parser.c between version 1.2 and 1.3

version 1.2, 2000/01/16 07:55:40 version 1.3, 2001/05/04 01:06:24
Line 1 
Line 1 
 /* $OpenXM$ */  /* $OpenXM: OpenXM/src/kan96xx/Kan/parser.c,v 1.2 2000/01/16 07:55:40 takayama Exp $ */
 /*  /*
    parser.c   parser for poly.c    parser.c   parser for poly.c
 */  */
   
 #include <stdio.h>  #include <stdio.h>
Line 101  static union valObject vpop() {
Line 101  static union valObject vpop() {
   
   
 POLY stringToPOLY(s,ringp)  POLY stringToPOLY(s,ringp)
 char *s;       char *s;
 struct ring *ringp;       struct ring *ringp;
 {  {
   /* call init() [ poly.c ] before you use strToPoly(). */    /* call init() [ poly.c ] before you use strToPoly(). */
   POLY ppp;    POLY ppp;
Line 127  struct ring *ringp;
Line 127  struct ring *ringp;
   } else { }    } else { }
   
   ss = (char *)sGC_malloc( strlen(s)+6 );  /* This parser think that an expression    ss = (char *)sGC_malloc( strlen(s)+6 );  /* This parser think that an expression
                                           -1+.. is error. ---->                        -1+.. is error. ---->
                                           Improved at 1992/03/04.*/                        Improved at 1992/03/04.*/
   if (ss == (char *)NULL)    if (ss == (char *)NULL)
     errorParser("No more space.");      errorParser("No more space.");
   k=0; while (s[k] == ' ') k++;    k=0; while (s[k] == ' ') k++;
   /* This method is quite adhoc. */    /* This method is quite adhoc. */
   /*    /*
   if (s[k] == '+' || s[k] == '-') {      if (s[k] == '+' || s[k] == '-') {
     strcpy(ss,"0"); strcat(ss,&(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 - */    strcpy(ss,&(s[k])); /* we introduce new parser which recognize unary - */
   k = strlen(ss);    k = strlen(ss);
Line 169  struct ring *ringp;
Line 169  struct ring *ringp;
   
 static int mytolower(c) int c; {  static int mytolower(c) int c; {
   /*if (c>='A' && c<= 'Z') return( c + 0x20 );    /*if (c>='A' && c<= 'Z') return( c + 0x20 );
   else return( c ); */      else return( c ); */
   return(c);   /* 1992/06/27  : do nothing now. ***/    return(c);   /* 1992/06/27  : do nothing now. ***/
 }  }
   
Line 185  static int getoken() {
Line 185  static int getoken() {
   int i;    int i;
   if (Ch == '\0') return( -1 );    if (Ch == '\0') return( -1 );
   while (isSpace(Ch)) Ch = getcharFromStr();    while (isSpace(Ch)) Ch = getcharFromStr();
  if (isDigit(Ch)) {    if (isDigit(Ch)) {
     Symbol = NUM; Bp = 0;      Symbol = NUM; Bp = 0;
     do {      do {
       Bwork[Bp] = Ch; Bwork[Bp+1] = '\0';        Bwork[Bp] = Ch; Bwork[Bp+1] = '\0';
       Ch = getcharFromStr();        Ch = getcharFromStr();
       Bp++;        Bp++;
       if (Bp >= BIGNUM_ILIMIT-1) {        if (Bp >= BIGNUM_ILIMIT-1) {
         errorParser(" Too big big-num. ");          errorParser(" Too big big-num. ");
       }        }
     } while (isDigit(Ch));      } while (isDigit(Ch));
     BigValue = newMP_INT();      BigValue = newMP_INT();
Line 205  static int getoken() {
Line 205  static int getoken() {
       /* Symbol = NUM; Don't do that. */        /* Symbol = NUM; Don't do that. */
       Value = 0;        Value = 0;
       do {        do {
         Value = Value*10+(Ch-'0');          Value = Value*10+(Ch-'0');
         Ch = getcharFromStr();          Ch = getcharFromStr();
       } while (isDigit(Ch));        } while (isDigit(Ch));
     }else errorParser(" Number is expected after x or d. ");      }else errorParser(" Number is expected after x or d. ");
   } else if (Ch == '@') {    } else if (Ch == '@') {
Line 215  static int getoken() {
Line 215  static int getoken() {
     do {      do {
       Name[i] = Ch; Name[i+1] = '\0'; i++;        Name[i] = Ch; Name[i+1] = '\0'; i++;
       if (i+2 >= NAME_MAX) {        if (i+2 >= NAME_MAX) {
         errorParser("Too long name begining with @.");          errorParser("Too long name begining with @.");
       }        }
       Ch = getcharFromStr();        Ch = getcharFromStr();
     } while (isAlphabetNum(Ch));      } while (isAlphabetNum(Ch));
Line 225  static int getoken() {
Line 225  static int getoken() {
   }    }
   
   /***/ /*    /***/ /*
   if (Symbol == NUM) {        if (Symbol == NUM) {
     fprintf(stderr,"\nToken type = number");        fprintf(stderr,"\nToken type = number");
   } else {        } else {
     fprintf(stderr,"\nToken type = %c",Symbol);        fprintf(stderr,"\nToken type = %c",Symbol);
   }        }
   fprintf(stderr,"  value is %d ",Value);        fprintf(stderr,"  value is %d ",Value);
   */          */
   
 }  }
   
Line 248  static  void expr() {
Line 248  static  void expr() {
   
   int gtype, ftype;   /* data type.  NUM or POL */    int gtype, ftype;   /* data type.  NUM or POL */
   POLY gp; POLY fp; POLY rp; /* g -> gp, f->fp, r -> rp , if they are    POLY gp; POLY fp; POLY rp; /* g -> gp, f->fp, r -> rp , if they are
                                 polynomials */                                  polynomials */
   POLY tmpp;    POLY tmpp;
   
   term();    term();
Line 274  static  void expr() {
Line 274  static  void expr() {
       fp= (ValTmp).p;        fp= (ValTmp).p;
     }else ;      }else ;
   
    /* debug */      /* debug */
    /* pWritef(gp,3); printf("\n\n"); sleep(5); */      /* pWritef(gp,3); printf("\n\n"); sleep(5); */
   
     if (op == '+') {      if (op == '+') {
       if (ftype == NUM && gtype == NUM) {        if (ftype == NUM && gtype == NUM) {
         mpz_add(f,f,g);          mpz_add(f,f,g);
         utmp.ival = f;          utmp.ival = f;
         push(NUM,utmp);          push(NUM,utmp);
       }else if (ftype== POL && gtype == NUM) {        }else if (ftype== POL && gtype == NUM) {
         rp = ppAdd(fp,bxx(g,0,0,&Ring0));          rp = ppAdd(fp,bxx(g,0,0,&Ring0));
         utmp.p = rp;          utmp.p = rp;
         push(POL, utmp);          push(POL, utmp);
       }else if (ftype==NUM && gtype == POL) {        }else if (ftype==NUM && gtype == POL) {
         rp = ppAdd(bxx(f,0,0,&Ring0),gp);          rp = ppAdd(bxx(f,0,0,&Ring0),gp);
         utmp.p = rp;          utmp.p = rp;
         push(POL,utmp);          push(POL,utmp);
       }else if (ftype==POL && gtype== POL) {        }else if (ftype==POL && gtype== POL) {
         rp = ppAdd(fp,gp);          rp = ppAdd(fp,gp);
         utmp.p = rp;          utmp.p = rp;
         push(POL,utmp);          push(POL,utmp);
       }else ;        }else ;
   
     }else {      }else {
       if (ftype == NUM && gtype == NUM) {        if (ftype == NUM && gtype == NUM) {
         mpz_sub(f,f,g);          mpz_sub(f,f,g);
         utmp.ival = f;          utmp.ival = f;
         push(NUM,utmp);          push(NUM,utmp);
       }else if (ftype== POL && gtype == NUM) {        }else if (ftype== POL && gtype == NUM) {
         rp = ppSub(fp,bxx(g,0,0,&Ring0));          rp = ppSub(fp,bxx(g,0,0,&Ring0));
         utmp.p = rp;          utmp.p = rp;
         push(POL, utmp);          push(POL, utmp);
       }else if (ftype==NUM && gtype == POL) {        }else if (ftype==NUM && gtype == POL) {
         rp = ppSub(bxx(f,0,0,&Ring0),gp);          rp = ppSub(bxx(f,0,0,&Ring0),gp);
         utmp.p = rp;          utmp.p = rp;
         push(POL,utmp);          push(POL,utmp);
       }else if (ftype==POL && gtype== POL) {        }else if (ftype==POL && gtype== POL) {
         rp = ppSub(fp,gp);          rp = ppSub(fp,gp);
         utmp.p = rp;          utmp.p = rp;
         push(POL,utmp);          push(POL,utmp);
       }else ;        }else ;
   
     }      }
Line 328  static void term() {
Line 328  static void term() {
   
   int gtype, ftype;   /* data type.  NUM or POL */    int gtype, ftype;   /* data type.  NUM or POL */
   POLY gp; POLY fp; POLY rp; /* g -> gp, f->fp, r -> rp , if they are    POLY gp; POLY fp; POLY rp; /* g -> gp, f->fp, r -> rp , if they are
                                 polynomials */                                  polynomials */
   POLY tmpp;    POLY tmpp;
   
   
   /* Unary + and -.  For example -(1+6), -5*3, so on and so forth.    /* Unary + and -.  For example -(1+6), -5*3, so on and so forth.
    term :          factor |       term :          factor |
           ( + | - )factor |       ( + | - )factor |
                    factor ( * | / ) factor ...  |       factor ( * | / ) factor ...  |
           ( + | - )factor ( * | / ) factor ...       ( + | - )factor ( * | / ) factor ...
   */    */
   if (Symbol == '+') {    if (Symbol == '+') {
     getoken();      getoken();
Line 385  static void term() {
Line 385  static void term() {
   
     if (op == '*') {      if (op == '*') {
       if (ftype == NUM && gtype == NUM) {        if (ftype == NUM && gtype == NUM) {
         mpz_mul(f,f,g);          mpz_mul(f,f,g);
         utmp.ival = f;          utmp.ival = f;
         push(NUM,utmp);          push(NUM,utmp);
       }else if (ftype== POL && gtype == NUM) {        }else if (ftype== POL && gtype == NUM) {
         fp = ppMult(bxx(g,0,0,&Ring0),fp);          fp = ppMult(bxx(g,0,0,&Ring0),fp);
         utmp.p = fp;          utmp.p = fp;
         push(POL, utmp);          push(POL, utmp);
       }else if (ftype==NUM && gtype == POL) {        }else if (ftype==NUM && gtype == POL) {
         gp = ppMult(bxx(f,0,0,&Ring0),gp);          gp = ppMult(bxx(f,0,0,&Ring0),gp);
         utmp.p = gp;          utmp.p = gp;
         push(POL,utmp);          push(POL,utmp);
       }else if (ftype==POL && gtype== POL) {        }else if (ftype==POL && gtype== POL) {
         rp = ppMult(fp,gp);          rp = ppMult(fp,gp);
         utmp.p = rp;          utmp.p = rp;
         push(POL,utmp);          push(POL,utmp);
       }else ;        }else ;
   
     }else {      }else {
       if (ftype == NUM && gtype == NUM) {        if (ftype == NUM && gtype == NUM) {
         mpz_div(f,f,g);          mpz_div(f,f,g);
         utmp.ival = f;          utmp.ival = f;
         push(NUM,utmp);          push(NUM,utmp);
       }else if (ftype== POL && gtype == NUM) {        }else if (ftype== POL && gtype == NUM) {
         errorParser("POLY / num is not supported yet.\n");          errorParser("POLY / num is not supported yet.\n");
         /*pvCoeffDiv(BbToCoeff(g),fp);          /*pvCoeffDiv(BbToCoeff(g),fp);
         utmp.p = fp;            utmp.p = fp;
         push(POL, utmp);*/            push(POL, utmp);*/
       }else if (ftype==NUM && gtype == POL) {        }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) {        }else if (ftype==POL && gtype== POL) {
         errorParser(" / POLY is not supported yet.\n");          errorParser(" / POLY is not supported yet.\n");
       }else ;        }else ;
   
     }      }
Line 429  static void factor() {
Line 429  static void factor() {
   
   int gtype, ftype;   /* data type.  NUM or POL */    int gtype, ftype;   /* data type.  NUM or POL */
   POLY gp; POLY fp; POLY rp; /* g -> gp, f->fp, r -> rp , if they are    POLY gp; POLY fp; POLY rp; /* g -> gp, f->fp, r -> rp , if they are
                                 polynomials */                                  polynomials */
   POLY tmpp;    POLY tmpp;
   union valObject utmp;    union valObject utmp;
   
Line 456  static void factor() {
Line 456  static void factor() {
   
     if (1) {      if (1) {
       if (ftype == NUM && gtype == NUM) {        if (ftype == NUM && gtype == NUM) {
         /* printf("\nf=");mpz_out_str(stdout,10,f);          /* printf("\nf=");mpz_out_str(stdout,10,f);
         printf("\ng=");mpz_out_str(stdout,10,g); */             printf("\ng=");mpz_out_str(stdout,10,g); */
         mpz_pow_ui(f,f,(unsigned long int) mpz_get_si(g));          mpz_pow_ui(f,f,(unsigned long int) mpz_get_si(g));
         utmp.ival = f;          utmp.ival = f;
         push(NUM,utmp);          push(NUM,utmp);
       }else if (ftype== POL && gtype == NUM) {        }else if (ftype== POL && gtype == NUM) {
         rp = pPower(fp,(int)mpz_get_si(g));          rp = pPower(fp,(int)mpz_get_si(g));
         utmp.p = rp;          utmp.p = rp;
         push(POL,utmp);          push(POL,utmp);
       }else if (ftype==NUM && gtype == POL) {        }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) {        }else if (ftype==POL && gtype== POL) {
         errorParser("(   ) ^ Polynomial is not supported yet.\n");          errorParser("(   ) ^ Polynomial is not supported yet.\n");
       }else ;        }else ;
   
     }      }
Line 495  static void monom() {
Line 495  static void monom() {
   
   }else if (Symbol == '@') {    }else if (Symbol == '@') {
     obj = findUserDictionary(&(Name[1]),hash0(&(Name[1])),hash1(&(Name[1])),      obj = findUserDictionary(&(Name[1]),hash0(&(Name[1])),hash1(&(Name[1])),
                              CurrentContextp);                               CurrentContextp);
     if (isNullObject(obj)) {      if (isNullObject(obj)) {
       fprintf(stderr,"%s",Name);        fprintf(stderr,"%s",Name);
       errorParser(" cannot be found in the user dictionary.");        errorParser(" cannot be found in the user dictionary.");
Line 510  static void monom() {
Line 510  static void monom() {
       push(POL,utmp);        push(POL,utmp);
     }else{      }else{
       if (f->m->ringp->n != Ring0.n) {        if (f->m->ringp->n != Ring0.n) {
         fprintf(stderr,"%s ",Name);          fprintf(stderr,"%s ",Name);
         errorParser("should be a polynomial in the current ring.\n");          errorParser("should be a polynomial in the current ring.\n");
       }        }
       utmp.p = modulo0(f,&Ring0);        utmp.p = modulo0(f,&Ring0);
       push(POL,utmp);        push(POL,utmp);
Line 570  static void errorParser(s) char s[]; {
Line 570  static void errorParser(s) char s[]; {
     strcat(tmpc," The error occured around: ");      strcat(tmpc," The error occured around: ");
     j = strlen(tmpc);      j = strlen(tmpc);
     for (i=(((StrPtr-5) >= 0)?StrPtr-5:0)  ;      for (i=(((StrPtr-5) >= 0)?StrPtr-5:0)  ;
          (i<StrPtr+10) && (String[i] != '\0'); i++) {           (i<StrPtr+10) && (String[i] != '\0'); i++) {
       tmpc[j] = String[i]; j++;        tmpc[j] = String[i]; j++;
       tmpc[j] = '\0';        tmpc[j] = '\0';
       if (j >= 1023) break;        if (j >= 1023) break;
Line 581  static void errorParser(s) char s[]; {
Line 581  static void errorParser(s) char s[]; {
     fprintf(stderr,"%s\n",s);      fprintf(stderr,"%s\n",s);
     fprintf(stderr,"The error occured around:  ");      fprintf(stderr,"The error occured around:  ");
     for (i=(((StrPtr-5) >= 0)?StrPtr-5:0)  ;      for (i=(((StrPtr-5) >= 0)?StrPtr-5:0)  ;
          (i<StrPtr+10) && (String[i] != '\0'); i++)           (i<StrPtr+10) && (String[i] != '\0'); i++)
       fprintf(stderr,"%c",String[i]);        fprintf(stderr,"%c",String[i]);
     fprintf(stderr,"  ..... \n");      fprintf(stderr,"  ..... \n");
   }    }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>