| version 1.4, 1999/11/02 19:51:18 |
version 1.7, 1999/11/06 21:39:37 |
|
|
| /* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
| /* $OpenXM: OpenXM/src/ox_math/parse.c,v 1.3 1999/11/02 18:58:25 ohara Exp $ */ |
/* $OpenXM: OpenXM/src/ox_math/parse.c,v 1.6 1999/11/04 18:15:20 ohara Exp $ */ |
| /* $Id$ */ |
|
| /* OX expression, CMO expression ¥Ñ¡¼¥µ */ |
/* OX expression, CMO expression ¥Ñ¡¼¥µ */ |
| |
|
| #include <stdio.h> |
#include <stdio.h> |
|
|
| CMO_MONOMIAL32 ¤Ï̵»ë¤·¤Ê¤¤. (¤Ä¤Þ¤ê¤ª¤«¤·¤¤¤È¤¤Ï¹½Ê¸¥¨¥é¡¼¤Ë¤Ê¤ë) |
CMO_MONOMIAL32 ¤Ï̵»ë¤·¤Ê¤¤. (¤Ä¤Þ¤ê¤ª¤«¤·¤¤¤È¤¤Ï¹½Ê¸¥¨¥é¡¼¤Ë¤Ê¤ë) |
| */ |
*/ |
| |
|
| |
|
| /* parse.c, lex.c ¤Ç¤Ï, Lisp ɽ¸½¤µ¤ì¤¿ CMO ʸ»úÎó¤òÆÉ¤ß¹þ¤ß, |
/* parse.c, lex.c ¤Ç¤Ï, Lisp ɽ¸½¤µ¤ì¤¿ CMO ʸ»úÎó¤òÆÉ¤ß¹þ¤ß, |
| ¥Ð¥¤¥ÈÎó¤ò½ÐÎϤ¹¤ë. Ãæ´Öɽ¸½¤È¤·¤Æ¡¢cmo *¤òÍøÍѤ¹¤ë. |
¥Ð¥¤¥ÈÎó¤ò½ÐÎϤ¹¤ë. Ãæ´Öɽ¸½¤È¤·¤Æ¡¢cmo ¹½Â¤ÂΤòÍøÍѤ¹¤ë. |
| parse() ¤Ï¥È¡¼¥¯¥ó¤ÎÎ󤫤é cmo *(¤Î»Ø¤¹¹½Â¤ÂÎ)¤òÀ¸À®¤¹¤ë. |
parse() ¤Ï¥È¡¼¥¯¥ó¤ÎÎ󤫤é cmo ¹½Â¤ÂΤòÀ¸À®¤·¡¢¤½¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹. |
| */ |
*/ |
| |
|
| /* ½ÅÍפʤ³¤È¤Ï¥Ñ¡¼¥µ(¤Î³Æ¥µ¥Ö¥ë¡¼¥Á¥ó)¤Ï |
/* ½ÅÍפʤ³¤È¤Ï¥Ñ¡¼¥µ(¤Î³Æ¥µ¥Ö¥ë¡¼¥Á¥ó)¤Ï |
|
|
| |
|
| /* ¥È¡¼¥¯¥ó¤Î°ÀÃÍ. yylval ¤Ï lex() ¤Ë¤è¤Ã¤Æ¥»¥Ã¥È¤µ¤ì¤ë. */ |
/* ¥È¡¼¥¯¥ó¤Î°ÀÃÍ. yylval ¤Ï lex() ¤Ë¤è¤Ã¤Æ¥»¥Ã¥È¤µ¤ì¤ë. */ |
| static union{ |
static union{ |
| int d; |
int d; |
| char* sym; |
char *sym; |
| } yylval; |
} yylval; |
| |
|
| /* pflag_cmo_addrev ¤¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ì¤Ð¡¢¸·Ì©¤Ë¤Ï CMO expression ¤Ç¤Ï |
/* pflag_cmo_addrev ¤¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ì¤Ð¡¢¸·Ì©¤Ë¤Ï CMO expression ¤Ç¤Ï |
| Line 43 static int pflag_cmo_addrev = 1; /* CMO ¤Î¾ÊάµË¡¤òµ |
|
| Line 42 static int pflag_cmo_addrev = 1; /* CMO ¤Î¾ÊάµË¡¤òµ |
|
| static int pflag_cmo_addrev = 1; /* CMO ¤Î¾ÊάµË¡¤òµö¤¹¤«Èݤ«¤Î¥Õ¥é¥° */ |
static int pflag_cmo_addrev = 1; /* CMO ¤Î¾ÊάµË¡¤òµö¤¹¤«Èݤ«¤Î¥Õ¥é¥° */ |
| |
|
| /* ´Ø¿ô¤ÎÀë¸À */ |
/* ´Ø¿ô¤ÎÀë¸À */ |
| static int parse_error(char *s); |
static int parse_error(char *s); |
| static int parse_lf(); |
static int parse_lf(); |
| static int parse_right_parenthesis(); |
static int parse_right_parenthesis(); |
| static int parse_left_parenthesis(); |
static int parse_left_parenthesis(); |
| static int parse_comma(); |
static int parse_comma(); |
| static int parse_integer(); |
static int parse_integer(); |
| static cmo *parse_cmo_null(); |
|
| static cmo *parse_cmo_int32(); |
|
| static cmo *parse_cmo_string(); |
|
| static cmo *parse_cmo_mathcap(); |
|
| static cmo *parse_cmo_dms_generic(); |
|
| static cmo *parse_cmo_ring_by_name(); |
|
| static cmo *parse_cmo_error2(); |
|
| static cmo *parse_cmo_zero(); |
|
| static cmo *parse_cmo_zz(); |
|
| static cmo *parse_cmo_list(); |
|
| static cmo *parse_cmo(); |
|
| static char *parse_string(); |
static char *parse_string(); |
| static int parse_sm(); |
static cmo *parse_cmo_null(); |
| static ox* parse_ox(); |
static cmo *parse_cmo_int32(); |
| static ox* parse_ox_command(); |
static cmo *parse_cmo_string(); |
| static ox* parse_ox_data(); |
static cmo *parse_cmo_mathcap(); |
| |
static cmo *parse_cmo_list(); |
| |
static cmo *parse_cmo_monomial32(); |
| |
static cmo *parse_cmo_zz(); |
| |
static cmo *parse_cmo_zero(); |
| |
static cmo *parse_cmo_dms_generic(); |
| |
static cmo *parse_cmo_ring_by_name(); |
| |
static cmo *parse_cmo_distributed_polynomial(); |
| |
static cmo *parse_cmo_indeterminate(); |
| |
static cmo *parse_cmo_error2(); |
| |
static cmo *parse_cmo(); |
| |
static int parse_sm(); |
| |
static ox *parse_ox(); |
| |
static ox *parse_ox_command(); |
| |
static ox *parse_ox_data(); |
| |
|
| static int is_token_cmo(int token) |
static int is_token_cmo(int token) |
| { |
{ |
| Line 128 static int parse_lf() |
|
| Line 130 static int parse_lf() |
|
| } |
} |
| |
|
| |
|
| static ox* parse_ox() |
static ox *parse_ox() |
| { |
{ |
| ox *m = NULL; |
ox *m = NULL; |
| |
|
| Line 147 static ox* parse_ox() |
|
| Line 149 static ox* parse_ox() |
|
| return m; |
return m; |
| } |
} |
| |
|
| static ox* parse_ox_data() |
static ox *parse_ox_data() |
| { |
{ |
| ox* m; |
ox *m; |
| |
|
| parse_comma(); |
parse_comma(); |
| parse_left_parenthesis(); |
parse_left_parenthesis(); |
| Line 158 static ox* parse_ox_data() |
|
| Line 160 static ox* parse_ox_data() |
|
| return m; |
return m; |
| } |
} |
| |
|
| static ox* parse_ox_command() |
static ox *parse_ox_command() |
| { |
{ |
| ox* m; |
ox *m; |
| |
|
| parse_comma(); |
parse_comma(); |
| parse_left_parenthesis(); |
parse_left_parenthesis(); |
| Line 233 static cmo *parse_cmo() |
|
| Line 235 static cmo *parse_cmo() |
|
| token = lex(); |
token = lex(); |
| m = parse_cmo_distributed_polynomial(); |
m = parse_cmo_distributed_polynomial(); |
| break; |
break; |
| |
case TOKEN(CMO_INDETERMINATE): |
| |
token = lex(); |
| |
m = parse_cmo_indeterminate(); |
| |
break; |
| case TOKEN(CMO_ERROR2): |
case TOKEN(CMO_ERROR2): |
| token = lex(); |
token = lex(); |
| m = parse_cmo_error2(); |
m = parse_cmo_error2(); |
| Line 489 static cmo *parse_cmo_distributed_polynomial() |
|
| Line 495 static cmo *parse_cmo_distributed_polynomial() |
|
| if (ob->tag != CMO_MONOMIAL32 && ob->tag != CMO_ZERO) { |
if (ob->tag != CMO_MONOMIAL32 && ob->tag != CMO_ZERO) { |
| parse_error("invalid cmo."); |
parse_error("invalid cmo."); |
| } |
} |
| append_cmo_list(m, ob); |
append_cmo_list((cmo_list *)m, ob); |
| if (token != ',') { |
if (token != ',') { |
| break; |
break; |
| } |
} |
| Line 502 static cmo *parse_cmo_distributed_polynomial() |
|
| Line 508 static cmo *parse_cmo_distributed_polynomial() |
|
| return (cmo *)m; |
return (cmo *)m; |
| } |
} |
| |
|
| |
static cmo *parse_cmo_indeterminate() |
| |
{ |
| |
cmo *ob; |
| |
|
| |
parse_comma(); |
| |
parse_left_parenthesis(); |
| |
ob = parse_cmo(); |
| |
parse_right_parenthesis(); |
| |
return (cmo *)new_cmo_indeterminate(ob); |
| |
} |
| |
|
| static cmo *parse_cmo_error2() |
static cmo *parse_cmo_error2() |
| { |
{ |
| cmo *ob; |
cmo *ob; |
| Line 546 static int lex_digit() |
|
| Line 562 static int lex_digit() |
|
| return d; |
return d; |
| } |
} |
| |
|
| |
#define MK_KEY_CMO(x) { #x , x , TOKEN(x) , IS_CMO } |
| |
#define MK_KEY_SM(x) { #x , x , TOKEN(SM) , IS_SM } |
| |
#define MK_KEY_OX(x) { #x , x , TOKEN(x) , IS_OX } |
| |
|
| |
static symbol symbol_list[] = { |
| |
MK_KEY_CMO(CMO_NULL), |
| |
MK_KEY_CMO(CMO_INT32), |
| |
MK_KEY_CMO(CMO_DATUM), |
| |
MK_KEY_CMO(CMO_STRING), |
| |
MK_KEY_CMO(CMO_MATHCAP), |
| |
MK_KEY_CMO(CMO_LIST), |
| |
MK_KEY_CMO(CMO_MONOMIAL32), |
| |
MK_KEY_CMO(CMO_ZZ), |
| |
MK_KEY_CMO(CMO_ZERO), |
| |
MK_KEY_CMO(CMO_DMS_GENERIC), |
| |
MK_KEY_CMO(CMO_RING_BY_NAME), |
| |
MK_KEY_CMO(CMO_INDETERMINATE), |
| |
MK_KEY_CMO(CMO_DISTRIBUTED_POLYNOMIAL), |
| |
MK_KEY_CMO(CMO_ERROR2), |
| |
MK_KEY_SM(SM_popCMO), |
| |
MK_KEY_SM(SM_popString), |
| |
MK_KEY_SM(SM_mathcap), |
| |
MK_KEY_SM(SM_pops), |
| |
MK_KEY_SM(SM_executeStringByLocalParser), |
| |
MK_KEY_SM(SM_executeFunction), |
| |
MK_KEY_SM(SM_setMathCap), |
| |
MK_KEY_SM(SM_control_kill), |
| |
MK_KEY_SM(SM_control_reset_connection), |
| |
MK_KEY_OX(OX_COMMAND), |
| |
MK_KEY_OX(OX_DATA), |
| |
{NULL, 0, 0, 0} /* a gate keeper */ |
| |
}; |
| |
|
| |
symbol* lookup_by_symbol(char *key) |
| |
{ |
| |
symbol *symp; |
| |
for(symp = symbol_list; symp->key != NULL; symp++) { |
| |
if (strcmp(key, symp->key)==0) { |
| |
return symp; |
| |
} |
| |
} |
| |
return NULL; |
| |
} |
| |
|
| |
symbol* lookup_by_token(int tok) |
| |
{ |
| |
symbol *symp; |
| |
for(symp = symbol_list; symp->key != NULL; symp++) { |
| |
if (tok == symp->token) { |
| |
return symp; |
| |
} |
| |
} |
| |
return NULL; |
| |
} |
| |
|
| |
symbol* lookup_by_tag(int tag) |
| |
{ |
| |
symbol *symp; |
| |
for(symp = symbol_list; symp->key != NULL; symp++) { |
| |
if (tag == symp->tag) { |
| |
return symp; |
| |
} |
| |
} |
| |
return NULL; |
| |
} |
| |
|
| |
symbol* lookup(int i) |
| |
{ |
| |
return &symbol_list[i]; |
| |
} |
| |
|
| /* ¥Ð¥Ã¥Õ¥¡¤¢¤Õ¤ì¤·¤¿¾ì¹ç¤ÎÂкö¤ò¤Á¤ã¤ó¤È¹Í¤¨¤ë¤Ù¤ */ |
/* ¥Ð¥Ã¥Õ¥¡¤¢¤Õ¤ì¤·¤¿¾ì¹ç¤ÎÂкö¤ò¤Á¤ã¤ó¤È¹Í¤¨¤ë¤Ù¤ */ |
| static char *lex_quoted_string() |
static char *lex_quoted_string() |
| { |
{ |
| Line 575 static char *lex_quoted_string() |
|
| Line 662 static char *lex_quoted_string() |
|
| /* return NULL; */ |
/* return NULL; */ |
| } |
} |
| |
|
| typedef struct { |
|
| char *key; |
|
| int token; |
|
| int op; |
|
| } symbol; |
|
| |
|
| #define MK_KEY_CMO(x) { #x , TOKEN(x) , 0} |
|
| #define MK_KEY_SM(x) { #x , TOKEN(SM) , x} |
|
| #define MK_KEY(x) { #x , TOKEN(x) , 0} |
|
| |
|
| static symbol symbol_list[] = { |
|
| MK_KEY_CMO(CMO_NULL), |
|
| MK_KEY_CMO(CMO_INT32), |
|
| MK_KEY_CMO(CMO_DATUM), |
|
| MK_KEY_CMO(CMO_STRING), |
|
| MK_KEY_CMO(CMO_MATHCAP), |
|
| MK_KEY_CMO(CMO_LIST), |
|
| MK_KEY_CMO(CMO_MONOMIAL32), |
|
| MK_KEY_CMO(CMO_ZZ), |
|
| MK_KEY_CMO(CMO_ZERO), |
|
| MK_KEY_CMO(CMO_DMS_GENERIC), |
|
| MK_KEY_CMO(CMO_RING_BY_NAME), |
|
| MK_KEY_CMO(CMO_INDETERMINATE), |
|
| MK_KEY_CMO(CMO_DISTRIBUTED_POLYNOMIAL), |
|
| MK_KEY_CMO(CMO_ERROR2), |
|
| MK_KEY_SM(SM_popCMO), |
|
| MK_KEY_SM(SM_popString), |
|
| MK_KEY_SM(SM_mathcap), |
|
| MK_KEY_SM(SM_pops), |
|
| MK_KEY_SM(SM_executeStringByLocalParser), |
|
| MK_KEY_SM(SM_executeFunction), |
|
| MK_KEY_SM(SM_setMathCap), |
|
| MK_KEY_SM(SM_control_kill), |
|
| MK_KEY_SM(SM_control_reset_connection), |
|
| MK_KEY(OX_COMMAND), |
|
| MK_KEY(OX_DATA), |
|
| {NULL, 0} /* a gate keeper */ |
|
| }; |
|
| |
|
| static int token_of_symbol(char *key) |
static int token_of_symbol(char *key) |
| { |
{ |
| symbol *kp; |
symbol *symp = lookup_by_symbol(key); |
| for(kp = symbol_list; kp->key != NULL; kp++) { |
if (symp != NULL) { |
| if (strcmp(key, kp->key)==0) { |
yylval.d = symp->tag; |
| yylval.d = kp->op; |
return symp->token; |
| return kp->token; |
|
| } |
|
| } |
} |
| #if DEBUG |
#if DEBUG |
| fprintf(stderr, "lex error\n"); |
fprintf(stderr, "lex error:: \"%s\" is unknown symbol.\n", key); |
| #endif |
#endif |
| return 0; |
return 0; |
| } |
} |
| Line 644 static int lex_symbol() |
|
| Line 690 static int lex_symbol() |
|
| return 0; |
return 0; |
| } |
} |
| |
|
| /* return ¤¹¤ëÁ°¤Ë°ìʸ»úÀèÆÉ¤ß¤·¤Æ¤ª¤¯¡£ */ |
/* return ¤¹¤ëÁ°¤Ë°ìʸ»úÀèÆÉ¤ß¤·¤Æ¤ª¤¯. */ |
| int lex() |
int lex() |
| { |
{ |
| int c_dash = 0; |
int c_dash = 0; |
|
|
| return 0; |
return 0; |
| } |
} |
| |
|
| |
/* °ìʸ»úÆÉ¤ß¹þ¤à´Ø¿ô */ |
| static char *mygetc_line; |
static char *mygetc_line; |
| static int mygetc_counter; |
static int mygetc_counter; |
| static int mygetc_counter_max; |
static int mygetc_counter_max; |
| |
static int mygetc_nonlf_flag; |
| |
|
| int mygetc() |
int mygetc() |
| { |
{ |
| if (mygetc_counter <= mygetc_counter_max) { |
int c = '\0'; |
| return mygetc_line[mygetc_counter++]; |
|
| |
if (mygetc_nonlf_flag && mygetc_counter <= mygetc_counter_max) { |
| |
c = mygetc_line[mygetc_counter++]; |
| |
if (c == '\0') { |
| |
c = '\n'; |
| |
mygetc_nonlf_flag = 0; |
| |
} |
| } |
} |
| return 0; |
return c; |
| } |
} |
| |
|
| int setmode_mygetc(char *s, int len) |
int setmode_mygetc(char *s, int len) |
| { |
{ |
| |
mygetc_nonlf_flag=1; |
| mygetc_counter=0; |
mygetc_counter=0; |
| mygetc_counter_max=len; |
mygetc_counter_max=len; |
| mygetc_line=s; |
mygetc_line=s; |