version 1.2, 2000/01/16 07:55:40 |
version 1.3, 2001/05/04 01:06:24 |
|
|
/* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/kan96xx/Kan/parserpass0.c,v 1.2 2000/01/16 07:55:40 takayama Exp $ */ |
/* parserpass0.c */ |
/* parserpass0.c */ |
/* In this preprocessor, for example, the expression |
/* In this preprocessor, for example, the expression |
x^2+y^2-4+x y; |
x^2+y^2-4+x y; |
Line 36 static struct tokens flush(); |
|
Line 36 static struct tokens flush(); |
|
|
|
|
|
static int get0() |
static int get0() |
/* get a letter from String0 */ |
/* get a letter from String0 */ |
{ |
{ |
int c; |
int c; |
c = String0[Strp0++]; |
c = String0[Strp0++]; |
Line 46 static int get0() |
|
Line 46 static int get0() |
|
} |
} |
|
|
static put0(c) |
static put0(c) |
int c; |
int c; |
/* put a letter on Buf0 */ |
/* put a letter on Buf0 */ |
{ |
{ |
char *new; int i; |
char *new; int i; |
Buf0[Exist0++] = c; |
Buf0[Exist0++] = c; |
Line 86 static struct tokens flush() |
|
Line 86 static struct tokens flush() |
|
} |
} |
|
|
static isSpace0(c) |
static isSpace0(c) |
int c; |
int c; |
{ |
{ |
if (c <= ' ') return(1); |
if (c <= ' ') return(1); |
else return(0); |
else return(0); |
} |
} |
|
|
static int isSymbol0(c) |
static int isSymbol0(c) |
int c; |
int c; |
{ |
{ |
if ((c == '+') || |
if ((c == '+') || |
(c == '-') || |
(c == '-') || |
|
|
} |
} |
|
|
static int isNumber0(c) |
static int isNumber0(c) |
int c; |
int c; |
{ |
{ |
if ((c>='0') && (c<='9')) return(1); |
if ((c>='0') && (c<='9')) return(1); |
else return(0); |
else return(0); |
} |
} |
|
|
static struct tokens getoken_pass0(kind) |
static struct tokens getoken_pass0(kind) |
actionType kind; |
actionType kind; |
{ |
{ |
static int c; |
static int c; |
static struct tokens rnull; |
static struct tokens rnull; |
Line 133 actionType kind; |
|
Line 133 actionType kind; |
|
else return(rnull); |
else return(rnull); |
} else if (isSpace0(c)) { |
} else if (isSpace0(c)) { |
if (Exist0) { |
if (Exist0) { |
c = get0(); return(flush()); |
c = get0(); return(flush()); |
}else { |
}else { |
while (isSpace0(c=get0())) ; |
while (isSpace0(c=get0())) ; |
} |
} |
} else if (isSymbol0(c)) { |
} else if (isSymbol0(c)) { |
if (Exist0) return(flush()); |
if (Exist0) return(flush()); |
else { |
else { |
put0(c); |
put0(c); |
c = get0(); |
c = get0(); |
return(flush()); |
return(flush()); |
} |
} |
} else if (isNumber0(c)) { |
} else if (isNumber0(c)) { |
put0(c); |
put0(c); |
c = get0(); |
c = get0(); |
while (isNumber0(c)) { |
while (isNumber0(c)) { |
put0(c); |
put0(c); |
c = get0(); |
c = get0(); |
} |
} |
return(flush()); |
return(flush()); |
} else { /* identifier */ |
} else { /* identifier */ |
put0(c); |
put0(c); |
c =get0(); |
c =get0(); |
while ((!isSymbol0(c)) && |
while ((!isSymbol0(c)) && |
(!isSpace0(c)) && |
(!isSpace0(c)) && |
(c != EOF)) { |
(c != EOF)) { |
put0(c); |
put0(c); |
c = get0(); |
c = get0(); |
} |
} |
return(flush()); |
return(flush()); |
} |
} |
Line 172 static char *Buf = Buftmp; |
|
Line 172 static char *Buf = Buftmp; |
|
static int Buflimit = STRBUFMAX; |
static int Buflimit = STRBUFMAX; |
|
|
static putstr(str,kind) |
static putstr(str,kind) |
char str[]; /* string to be outputted */ |
char str[]; /* string to be outputted */ |
actionType kind; /* kind is INIT or PUT */ |
actionType kind; /* kind is INIT or PUT */ |
{ |
{ |
static int ptr; |
static int ptr; |
int i; |
int i; |
Line 192 actionType kind; /* kind is INIT or PUT */ |
|
Line 192 actionType kind; /* kind is INIT or PUT */ |
|
fprintf(stderr,"Increasing Buf to %d.\n",2*Buflimit); |
fprintf(stderr,"Increasing Buf to %d.\n",2*Buflimit); |
newbuf = (char *) sGC_malloc(2*Buflimit); |
newbuf = (char *) sGC_malloc(2*Buflimit); |
if (newbuf == (char *)NULL) { |
if (newbuf == (char *)NULL) { |
fprintf(stderr,"\nNo memory in putstr() in parserpass0.c\n"); |
fprintf(stderr,"\nNo memory in putstr() in parserpass0.c\n"); |
exit(20); |
exit(20); |
} |
} |
for (k=0; k<Buflimit; k++) { |
for (k=0; k<Buflimit; k++) { |
newbuf[k] = Buf[k]; |
newbuf[k] = Buf[k]; |
} |
} |
Buf = newbuf; |
Buf = newbuf; |
Buflimit *= 2; |
Buflimit *= 2; |
Line 207 actionType kind; /* kind is INIT or PUT */ |
|
Line 207 actionType kind; /* kind is INIT or PUT */ |
|
|
|
|
|
char *str2strPass0(string,ringp) |
char *str2strPass0(string,ringp) |
char *string; |
char *string; |
struct ring *ringp; |
struct ring *ringp; |
{ |
{ |
|
|
struct tokens ptoken; /* previous token */ |
struct tokens ptoken; /* previous token */ |
Line 249 struct ring *ringp; |
|
Line 249 struct ring *ringp; |
|
if (inputTranslation && (ptoken.kind == ID)) { |
if (inputTranslation && (ptoken.kind == ID)) { |
/* Do the input translation for identifier*/ |
/* Do the input translation for identifier*/ |
for (i=0; i<n; i++) { |
for (i=0; i<n; i++) { |
if (strcmp(ptoken.token,ringp->x[i]) == 0) { |
if (strcmp(ptoken.token,ringp->x[i]) == 0) { |
sprintf(work,"x%d",i); |
sprintf(work,"x%d",i); |
putstr(work,PUT); |
putstr(work,PUT); |
i = -1; |
i = -1; |
break; /* break for */ |
break; /* break for */ |
} |
} |
if (strcmp(ptoken.token,ringp->D[i]) == 0) { |
if (strcmp(ptoken.token,ringp->D[i]) == 0) { |
sprintf(work,"d%d",i); |
sprintf(work,"d%d",i); |
putstr(work,PUT); |
putstr(work,PUT); |
i = -1; |
i = -1; |
break; /* break for */ |
break; /* break for */ |
} |
} |
} |
} |
if (strlen(ptoken.token)>0 && (ptoken.token)[0] == '@') { |
if (strlen(ptoken.token)>0 && (ptoken.token)[0] == '@') { |
putstr(ptoken.token,PUT); |
putstr(ptoken.token,PUT); |
i = -1; |
i = -1; |
} |
} |
if (i != -1) { /* very dirty code */ |
if (i != -1) { /* very dirty code */ |
fprintf(stderr,"\n Undefined identifier %s. \n",ptoken.token); |
fprintf(stderr,"\n Undefined identifier %s. \n",ptoken.token); |
putstr(ptoken.token,PUT); |
putstr(ptoken.token,PUT); |
} |
} |
/* end of input translations */ |
/* end of input translations */ |
}else { |
}else { |
if (ptoken.token != (char *)NULL) { |
if (ptoken.token != (char *)NULL) { |
putstr(ptoken.token,PUT); |
putstr(ptoken.token,PUT); |
} |
} |
} |
} |
/* if ctoken.token is ";" then end */ |
/* if ctoken.token is ";" then end */ |
Line 287 struct ring *ringp; |
|
Line 287 struct ring *ringp; |
|
} |
} |
|
|
if (((ptoken.kind == ID) || (ptoken.kind == KAZU) || (ptoken.kind == ')')) |
if (((ptoken.kind == ID) || (ptoken.kind == KAZU) || (ptoken.kind == ')')) |
&& |
&& |
((ctoken.kind == ID) || (ctoken.kind == KAZU) || (ctoken.kind == '('))) |
((ctoken.kind == ID) || (ctoken.kind == KAZU) || (ctoken.kind == '('))) |
{ |
{ |
putstr(" * ",PUT); |
putstr(" * ",PUT); |
} |
} |
if (ptoken.token != (char *)NULL) sGC_free(ptoken.token); |
if (ptoken.token != (char *)NULL) sGC_free(ptoken.token); |
ptoken = ctoken; |
ptoken = ctoken; |
Line 300 struct ring *ringp; |
|
Line 300 struct ring *ringp; |
|
|
|
|
|
/* |
/* |
main() { |
main() { |
char str[200]; |
char str[200]; |
struct ring r; |
struct ring r; |
static char *x[]={"x","y","z"}; |
static char *x[]={"x","y","z"}; |
static char *D[]={"Dx","Dy","Dz"}; |
static char *D[]={"Dx","Dy","Dz"}; |
r.n = 3; |
r.n = 3; |
r.x = x; r.D = D; |
r.x = x; r.D = D; |
gets(str); |
gets(str); |
printf("%s\n",str2strPass0(str,&r)); |
printf("%s\n",str2strPass0(str,&r)); |
} |
} |
*/ |
*/ |