version 1.2, 2000/01/16 07:55:40 |
version 1.5, 2013/11/06 06:23:24 |
|
|
/* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/kan96xx/Kan/parserpass0.c,v 1.4 2005/07/03 11:08:54 ohara 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; |
|
|
*/ |
*/ |
/* 1992/03/05 */ |
/* 1992/03/05 */ |
#include <stdio.h> |
#include <stdio.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
#include "datatype.h" |
#include "datatype.h" |
#include "extern2.h" |
#include "extern2.h" |
|
|
Line 36 static struct tokens flush(); |
|
Line 38 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 48 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 88 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 135 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 174 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; |
int k; char *newbuf; |
int k; char *newbuf; |
if (kind == INIT) { |
if (kind == INIT) { |
ptr = 0; |
ptr = 0; |
return; |
return 0; |
} |
} |
|
|
i=0; |
i=0; |
Line 192 actionType kind; /* kind is INIT or PUT */ |
|
Line 194 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; |
} |
} |
} |
} |
|
return 0; |
} |
} |
|
|
|
|
|
|
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 252 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 290 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 303 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)); |
} |
} |
*/ |
*/ |