=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/Kan/scanner.c,v retrieving revision 1.3 retrieving revision 1.7 diff -u -p -r1.3 -r1.7 --- OpenXM/src/kan96xx/Kan/scanner.c 2000/03/20 01:53:46 1.3 +++ OpenXM/src/kan96xx/Kan/scanner.c 2004/09/12 00:26:21 1.7 @@ -1,4 +1,4 @@ -/*$OpenXM: OpenXM/src/kan96xx/Kan/scanner.c,v 1.2 1999/11/18 08:08:24 takayama Exp $*/ +/*$OpenXM: OpenXM/src/kan96xx/Kan/scanner.c,v 1.6 2004/09/10 22:21:27 takayama Exp $*/ /* scanner.c (SM StackMachine) */ /* export: struct tokens getokenSM(actionType kind,char *str); scanner.c is used to get tokens from streams. @@ -80,31 +80,40 @@ static mygetchar() static mygetchar() { int c; - if (EchoInScanner) { - c = getc(Cfp); - if (c==EOF) { - printf("\n%% EOF of file %x\n",(int) Cfp); - }else{ - printf("%c",c); - } - return( c ); - }else{ - return( getc(Cfp) ); - } + if (EchoInScanner) { + c = getc(Cfp); + if (c==EOF) { + printf("\n%% EOF of file %x\n",(int) Cfp); + }else{ + printf("%c",c); + } + return( c ); + }else{ + return( getc(Cfp) ); + } } static myungetchar(c) -int c; + int c; { return( ungetc(c,Cfp) ); } /**************** code part of lexical analizer ********************/ static int getSM() -/* get a letter from StringSM */ + /* get a letter from StringSM */ { int c; + + if ((StrpSM > 0) && (StringSM[StrpSM] == ',') && (StringSM[StrpSM-1] == ',')) { int i; + fprintf(stderr,"Warning: ,, is found."); + for (i=(StrpSM-30>0?StrpSM-30:0); i<=StrpSM; i++) { + fprintf(stderr,"%c",StringSM[i]); + } + fprintf(stderr,"\n"); + } + c = StringSM[StrpSM++]; if (c == '\0') { StrpSM--;return(EOF); @@ -112,8 +121,8 @@ static int getSM() } static putSM(c) -int c; -/* put a letter on BufSM */ + int c; + /* put a letter on BufSM */ { char *new; int i; BufSM[ExistSM++] = ((c=='\n')? ' ' : c); @@ -146,6 +155,7 @@ static struct tokens flushSM() strcpy(token,BufSM); r.token = token; r.kind = TypeSM; + r.tflag = 0; if (r.kind == ID) { if (isLiteral(r.token)) { r.object = lookupLiteralString(r.token); @@ -157,35 +167,35 @@ static struct tokens flushSM() } static isSpaceSM(c) -int c; + int c; { - if ((c <= ' ') && (c!= EOF)) return(1); + if (((c <= ' ') || c == ',') && (c!= EOF)) return(1); else return(0); } static isDollarSM(c) -int c; + int c; { if (c == '$') return(1); else return(0); } static isBraceSM(c) -int c; + int c; { if (c == '{') return(1); else return(0); } static isKakkoSM(c) -int c; + int c; { if (c == '(') return(1); else return(0); } static isSymbolSM(c) -int c; + int c; { if ((c == '{') || (c == '}') || @@ -198,8 +208,8 @@ int c; } struct tokens getokenSM(kind,str) -actionType kind; -char *str; + actionType kind; + char *str; { static int c; static struct tokens rnull; @@ -215,7 +225,7 @@ char *str; myungetchar('\n'); /* dummy */ c = mygetchar(); /* Notice that you need at least on input to return - from the getokenSM(INIT); ^^^^^^^^*/ + from the getokenSM(INIT); ^^^^^^^^*/ rnull.token = (char *)NULL; rnull.kind = -1; return(rnull); } @@ -234,35 +244,35 @@ char *str; }else { Cfp = fopen(str,"r"); if (EchoInScanner) - printf("\n%% I open the file %s.\n",str); + printf("\n%% I open the file %s.\n",str); if (Cfp == (FILE *)NULL) { - strcpy(fname,getLOAD_SM1_PATH()); - strcat(fname,str); - Cfp = fopen(fname,"r"); - if (Cfp == (FILE *)NULL) { - strcpy(fname,LOAD_SM1_PATH); - strcat(fname,str); - Cfp = fopen(fname,"r"); - if (Cfp == (FILE *)NULL) { - fprintf(stderr,"Warning: Cannot open the file <<%s>> for loading in the current directory nor the library directories %s and %s.\n",str,getLOAD_SM1_PATH(),LOAD_SM1_PATH); + strcpy(fname,getLOAD_SM1_PATH()); + strcat(fname,str); + Cfp = fopen(fname,"r"); + if (Cfp == (FILE *)NULL) { + strcpy(fname,LOAD_SM1_PATH); + strcat(fname,str); + Cfp = fopen(fname,"r"); + if (Cfp == (FILE *)NULL) { + fprintf(stderr,"Warning: Cannot open the file <<%s>> for loading in the current directory nor the library directories %s and %s.\n",str,getLOAD_SM1_PATH(),LOAD_SM1_PATH); - Cfp = FileStack[--FileStackP]; - fprintf(stderr,"\nWarning: I could not open the file %s\n",str); - c = mygetchar(); - rnull.kind = -3; - return(rnull); /* error */ - }else{ - c = mygetchar(); /* input from the new file */ - return(rnull); - } - }else{ - c = mygetchar(); /* input from the new file */ - return(rnull); - } + Cfp = FileStack[--FileStackP]; + fprintf(stderr,"\nWarning: I could not open the file %s\n",str); + c = mygetchar(); + rnull.kind = -3; + return(rnull); /* error */ + }else{ + c = mygetchar(); /* input from the new file */ + return(rnull); + } + }else{ + c = mygetchar(); /* input from the new file */ + return(rnull); + } }else{ - c = mygetchar(); /* input from the new file */ - return(rnull); + c = mygetchar(); /* input from the new file */ + return(rnull); } } } @@ -271,74 +281,74 @@ char *str; TypeSM = ID; if (c == EOF) { if (FileStackP <= 0) { - if (ExistSM) return(flushSM()); - else return(rnull); + if (ExistSM) return(flushSM()); + else return(rnull); }else { /* return to the previous file */ - fclose(Cfp); /* close the file */ - Cfp = FileStack[--FileStackP]; - c = mygetchar(Cfp); + fclose(Cfp); /* close the file */ + Cfp = FileStack[--FileStackP]; + c = mygetchar(Cfp); } } else if (isSpaceSM(c)) { if (ExistSM) { - c = mygetchar(); return(flushSM()); + c = mygetchar(); return(flushSM()); }else { - while (isSpaceSM(c=mygetchar())) ; + while (isSpaceSM(c=mygetchar())) ; } } else if (isDollarSM(c)) { /* output contents in dollar signs. */ if (ExistSM) return(flushSM()); else { - c = mygetchar(); - while ((c != EOF) && (c != '$')) { - putSM(c); - c = mygetchar(); - } - if (c=='$') c=mygetchar(); - TypeSM = DOLLAR; - return(flushSM()); + c = mygetchar(); + while ((c != EOF) && (c != '$')) { + putSM(c); + c = mygetchar(); + } + if (c=='$') c=mygetchar(); + TypeSM = DOLLAR; + return(flushSM()); } } else if (isBraceSM(c)) { /* output contents in { } */ /* { { } } */ level = 0; if (ExistSM) return(flushSM()); else { - c = mygetchar(); - while (1) { - if (c == '%') { /* skip the comment in the brace. */ - while (((c=mygetchar()) != '\n') && (c != EOF)) ; - } - if (c == EOF) break; - if ((c == '}') && (level <= 0)) break; - if ( c == '{') ++level; - if ( c == '}') --level; - putSM(c); - c = mygetchar(); - } - if (c=='}') c=mygetchar(); - TypeSM = EXECUTABLE_STRING; - return(flushSM()); + c = mygetchar(); + while (1) { + if (c == '%') { /* skip the comment in the brace. */ + while (((c=mygetchar()) != '\n') && (c != EOF)) ; + } + if (c == EOF) break; + if ((c == '}') && (level <= 0)) break; + if ( c == '{') ++level; + if ( c == '}') --level; + putSM(c); + c = mygetchar(); + } + if (c=='}') c=mygetchar(); + TypeSM = EXECUTABLE_STRING; + return(flushSM()); } } else if (isKakkoSM(c)) { /* output contents in ( ) */ level = 0; if (ExistSM) return(flushSM()); else { - c = mygetchar(); - while (1) { - if (c == EOF) break; - if (c == '\\') { /* e.g. \( */ - putSM(c); - c = mygetchar(); - if (c == EOF) break; - }else{ - if ((c == ')') && (level <= 0)) break; - if ( c == '(') ++level; - if ( c == ')') --level; - } - putSM(c); - c = mygetchar(); - } - if (c==')') c=mygetchar(); - TypeSM = DOLLAR; - return(flushSM()); + c = mygetchar(); + while (1) { + if (c == EOF) break; + if (c == '\\') { /* e.g. \( */ + putSM(c); + c = mygetchar(); + if (c == EOF) break; + }else{ + if ((c == ')') && (level <= 0)) break; + if ( c == '(') ++level; + if ( c == ')') --level; + } + putSM(c); + c = mygetchar(); + } + if (c==')') c=mygetchar(); + TypeSM = DOLLAR; + return(flushSM()); } } else if (c=='%') { /* comment */ while (((c=mygetchar()) != '\n') && (c != EOF)) ; @@ -346,19 +356,19 @@ char *str; } else if (isSymbolSM(c)) { /* symbols. {,} etc */ if(ExistSM) return(flushSM()); else { - putSM(c); - c = mygetchar(); - return(flushSM()); + putSM(c); + c = mygetchar(); + return(flushSM()); } } else { /* identifier */ putSM(c); c =mygetchar(); while ((!isDollarSM(c)) && - (!isSpaceSM(c)) && - (!isSymbolSM(c)) && - (c != EOF)) { - putSM(c); - c = mygetchar(); + (!isSpaceSM(c)) && + (!isSymbolSM(c)) && + (c != EOF)) { + putSM(c); + c = mygetchar(); } return(flushSM()); } @@ -403,9 +413,9 @@ char *getLOAD_SM1_PATH() { p2 = (char *) sGC_malloc(sizeof(char)*(strlen(p)+strlen("/lib/sm1/")+3)); if (p2 == NULL) { fprintf(stderr,"No more memory.\n"); exit(10); } if (p[strlen(p)-1] != '/') { - strcpy(p2,p); strcat(p2,"/lib/sm1/"); + strcpy(p2,p); strcat(p2,"/lib/sm1/"); }else{ - strcpy(p2,p); strcat(p2,"lib/sm1/"); + strcpy(p2,p); strcat(p2,"lib/sm1/"); } return(p2); }