version 1.2, 2003/11/20 03:25:08 |
version 1.4, 2003/11/20 07:56:00 |
|
|
/* $OpenXM: OpenXM/src/kan96xx/Kan/yylex_polymake.c,v 1.1 2003/11/20 00:06:07 takayama Exp $ */ |
/* $OpenXM: OpenXM/src/kan96xx/Kan/yylex_polymake.c,v 1.3 2003/11/20 06:04:04 takayama Exp $ */ |
/* parser for polymake output */ |
/* parser for polymake output */ |
/* This program requires |
/* This program requires |
|
|
|
|
#include "yylex_polymake.h" |
#include "yylex_polymake.h" |
#include "yy_polymake.tab.h" |
#include "yy_polymake.tab.h" |
|
|
/* #define mymalloc(n) sGC_malloc(n) */ |
#define mymalloc(n) sGC_malloc(n) |
|
/* |
#define mymalloc(n) malloc(n) |
#define mymalloc(n) malloc(n) |
|
*/ |
/* pm = PolyMake */ |
/* pm = PolyMake */ |
#define PM_emptyLineCode 1 |
#define PM_emptyLineCode 1 |
|
|
Line 23 static int PMdebug = 0; |
|
Line 25 static int PMdebug = 0; |
|
|
|
/* char *PMlval; */ |
/* char *PMlval; */ |
|
|
|
/* The function putstr() uses static variables inside, |
|
so if it is under use, it must not be initialized. |
|
The function putstr2() is for the second use and is identical |
|
function with putstr(). |
|
*/ |
static char *putstr(int c); |
static char *putstr(int c); |
|
static char *putstr2(int c); |
|
static char *putstr2s(char *s); |
|
|
|
char *pmPutstr(int c) { |
|
return putstr(c); |
|
} |
|
|
|
pmSetS(char *s) { |
|
S = s; |
|
return 0; |
|
} |
|
|
int PMlex() { |
int PMlex() { |
int type; |
int type; |
type = PMlex_aux(); |
type = PMlex_aux(); |
Line 97 static char *putstr(int c) { |
|
Line 115 static char *putstr(int c) { |
|
return putstr(c); |
return putstr(c); |
} |
} |
} |
} |
|
static char *putstr2(int c) { |
|
static char *s=NULL; |
|
static int pt=0; |
|
static int limit=0; |
|
int i; |
|
char *old; |
|
if (c < 0) { |
|
s = (char *)mymalloc(PUTSTR_INIT); |
|
if (s == NULL) {fprintf(stderr,"No more memory.\n"); exit(10);} |
|
limit = PUTSTR_INIT; |
|
pt = 0; s[pt] = 0; |
|
return s; |
|
} |
|
if (s == NULL) putstr2(-1); |
|
if (pt < limit-1) { |
|
s[pt++]=c; s[pt]=0; |
|
return s; |
|
}else{ |
|
old = s; |
|
limit = 2*limit; |
|
s = (char *)mymalloc(limit); |
|
if (s == NULL) {fprintf(stderr,"No more memory.\n"); exit(10);} |
|
for (i=0; i<=pt; i++) { |
|
s[i] = old[i]; |
|
} |
|
return putstr2(c); |
|
} |
|
} |
|
static char *putstr2s(char *s) { |
|
int i; |
|
char *ss; |
|
for (i=0; i<strlen(s); i++) { |
|
ss = putstr2(s[i]); |
|
} |
|
return ss; |
|
} |
|
|
pmPreprocess() { |
pmPreprocess() { |
int newp,oldp; |
int newp,oldp; |
Line 156 pmPreprocess() { |
|
Line 210 pmPreprocess() { |
|
} |
} |
} |
} |
|
|
|
/* --------------- pmObjects --------------------- */ |
pmObjectp pmNewStrObject(char *s) { |
pmObjectp pmNewStrObject(char *s) { |
pmObjectp ob; |
pmObjectp ob; |
ob = (pmObjectp) mymalloc(sizeof(struct pmObject)); |
ob = (pmObjectp) mymalloc(sizeof(struct pmObject)); |
Line 278 pmObjectp pmAddChild(pmObjectp c,pmObjectp a) { |
|
Line 333 pmObjectp pmAddChild(pmObjectp c,pmObjectp a) { |
|
warning_yylex_polymake(char *s) { |
warning_yylex_polymake(char *s) { |
fprintf(stderr,"Warning: %s",s); |
fprintf(stderr,"Warning: %s",s); |
} |
} |
|
|
void pmPrintObject(FILE *fp,pmObjectp p) { |
void pmPrintObject(FILE *fp,pmObjectp p) { |
|
fprintf(fp,"%s",pmObjectToStr(p)); |
|
} |
|
char *pmObjectToStr(pmObjectp p) { |
|
char *s; |
|
s=putstr2(-1); |
|
s=pmObjectToStr_aux(p); |
|
return putstr2(0); |
|
} |
|
char *pmObjectToStr_aux(pmObjectp p) { |
int n,i; |
int n,i; |
struct pmList *list; |
struct pmList *list; |
struct pmList *t; |
struct pmList *t; |
struct pmTree *tree; |
struct pmTree *tree; |
|
char *ans; |
if (p == NULL) { |
if (p == NULL) { |
/* fprintf(stderr,"NULL "); */ |
/* fprintf(stderr,"NULL "); */ |
return; |
return putstr2s("[]"); |
} |
} |
/* fprintf(stderr,"tag=%d ",p->tag); */ |
/* fprintf(stderr,"tag=%d ",p->tag); */ |
switch (p->tag) { |
switch (p->tag) { |
case PMobject_str: |
case PMobject_str: |
fprintf(fp,"%s",(char *)(p->body)); |
ans=putstr2s((char *)(p->body)); |
break; |
break; |
case PMobject_list: |
case PMobject_list: |
list = (struct pmList *)(p->body); |
list = (struct pmList *)(p->body); |
if (list == NULL) break; |
if (list == NULL) break; |
n = pmListLength(list); |
n = pmListLength(list); |
t = list; |
t = list; |
fprintf(fp,"["); |
ans=putstr2s("["); |
for (i=0; i<n; i++) { |
for (i=0; i<n; i++) { |
pmPrintObject(fp,t->left); |
ans=pmObjectToStr_aux(t->left); |
if (i != n-1) fprintf(fp,","); |
if (i != n-1) ans=putstr2s(","); |
if (t == NULL) break; else t = t->right; |
if (t == NULL) break; else t = t->right; |
} |
} |
fprintf(fp,"]"); |
ans=putstr2s("]"); |
break; |
break; |
case PMobject_tree: |
case PMobject_tree: |
tree = p->body; |
tree = p->body; |
fprintf(fp,"polymake.%s(",tree->nodeName); |
ans=putstr2s("polymake."); ans=putstr2s(tree->nodeName); |
|
ans=putstr2s("("); |
/* Ignore attribute list */ |
/* Ignore attribute list */ |
if (tree->childs == NULL) {n = 0; t = NULL; } |
if (tree->childs == NULL) {n = 0; t = NULL; } |
else { |
else { |
Line 315 void pmPrintObject(FILE *fp,pmObjectp p) { |
|
Line 382 void pmPrintObject(FILE *fp,pmObjectp p) { |
|
n = pmListLength(t); |
n = pmListLength(t); |
} |
} |
for (i=0; i<n; i++) { |
for (i=0; i<n; i++) { |
pmPrintObject(fp,t->left); |
ans=pmObjectToStr_aux(t->left); |
t = t->right; |
t = t->right; |
if (i != n-1) fprintf(fp,","); |
if (i != n-1) ans=putstr2(','); |
} |
} |
fprintf(fp,")"); |
ans = putstr2s(")"); |
break; |
break; |
default: |
default: |
fprintf(stderr,"Unknown object tag %d.\n",p->tag); |
fprintf(stderr,"Unknown object tag %d.\n",p->tag); |
/* sleep(100); to call debugger. */ |
/* sleep(100); to call debugger. */ |
break; |
break; |
} |
} |
|
return ans; |
} |
} |
|
|
main_t() { |
|
int c,type; |
|
putstr(-1); |
|
while ((c=getchar()) != EOF) { |
|
putstr(c); |
|
} |
|
S = putstr(0); |
|
printf("%s\n",S); |
|
pmPreprocess(S); |
|
printf("--------------------------\n"); |
|
printf("%s\n",S); |
|
printf("--------------------------\n"); |
|
while ((type=PMlex()) != PM_noToken) { |
|
printf("type=%d ",type); |
|
if ((type == PM_number) || (type == PM_keyword)) { |
|
printf("value="); pmPrintObject(stdout,PMlval); |
|
} |
|
printf("\n"); |
|
} |
|
} |
|
|
|
main() { |
|
int c,type; |
|
|
|
|
|
putstr(-1); |
|
while ((c=getchar()) != EOF) { |
|
putstr(c); |
|
} |
|
S = putstr(0); |
|
printf("%s\n",S); |
|
pmPreprocess(S); |
|
printf("--------------------------\n"); |
|
printf("%s\n",S); |
|
printf("--------------------------\n"); |
|
PMparse(); |
|
} |
|
|
|
PMerror() { |
|
} |
|