version 1.2, 1999/11/02 06:11:58 |
version 1.4, 1999/11/02 19:51:18 |
|
|
/* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
/* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/ox_math/parse.c,v 1.3 1999/11/02 18:58:25 ohara Exp $ */ |
/* $Id$ */ |
/* $Id$ */ |
/* OX expression, CMO expression パーサ */ |
/* OX expression, CMO expression パーサ */ |
|
|
Line 66 static ox* parse_ox(); |
|
Line 66 static ox* parse_ox(); |
|
static ox* parse_ox_command(); |
static ox* parse_ox_command(); |
static ox* parse_ox_data(); |
static ox* parse_ox_data(); |
|
|
static int is_t_cmo(int token) |
static int is_token_cmo(int token) |
{ |
{ |
return (token >= MIN_T_CMO && token < MAX_T_CMO) || token == TOKEN(CMO_ERROR2); |
return (token >= MIN_T_CMO && token < MAX_T_CMO) || token == TOKEN(CMO_ERROR2); |
} |
} |
|
|
static int is_t_sm(int token) |
static int is_token_sm(int token) |
{ |
{ |
return token >= MIN_T_SM && token < MAX_T_SM; |
return token == TOKEN(SM); |
} |
} |
|
|
static int is_t_ox(int token) |
static int is_token_ox(int token) |
{ |
{ |
return token >= MIN_T_OX && token < MAX_T_OX; |
return token >= MIN_T_OX && token < MAX_T_OX; |
} |
} |
Line 86 static jmp_buf env_parse; |
|
Line 86 static jmp_buf env_parse; |
|
/* 構文解析に失敗したことを意味する. */ |
/* 構文解析に失敗したことを意味する. */ |
static int parse_error(char *s) |
static int parse_error(char *s) |
{ |
{ |
fprintf(stderr, "%s\n", s); |
fprintf(stderr, "syntax error: %s\n", s); |
longjmp(env_parse, 1); |
longjmp(env_parse, 1); |
} |
} |
|
|
|
|
|
|
if (token == '(') { |
if (token == '(') { |
token = lex(); |
token = lex(); |
if (is_t_cmo(token)) { |
if (is_token_cmo(token)) { |
m = parse_cmo(); |
m = parse_cmo(); |
}else if(is_t_ox(token)) { |
}else if(is_token_ox(token)) { |
m = parse_ox(); |
m = parse_ox(); |
}else { |
}else { |
parse_error("syntax error: unknown symbol."); |
parse_error("invalid symbol."); |
} |
} |
parse_lf(); |
parse_lf(); |
return m; |
return m; |
|
|
static int parse_lf() |
static int parse_lf() |
{ |
{ |
if (token != '\n') { |
if (token != '\n') { |
parse_error("syntax error: not new line."); |
parse_error("no new line."); |
} |
} |
return 0; |
return 0; |
} |
} |
Line 142 static ox* parse_ox() |
|
Line 142 static ox* parse_ox() |
|
m = parse_ox_data(); |
m = parse_ox_data(); |
break; |
break; |
default: |
default: |
parse_error("syntax error: invalid ox_tag."); |
parse_error("invalid ox."); |
} |
} |
return m; |
return m; |
} |
} |
Line 158 static ox* parse_ox_data() |
|
Line 158 static ox* parse_ox_data() |
|
return m; |
return m; |
} |
} |
|
|
static int parse_sm() |
|
{ |
|
int sm_code; |
|
if (!is_t_sm(token)) { |
|
parse_error("syntax error: invalid sm code."); |
|
} |
|
sm_code = token - T_MAGIC; |
|
token = lex(); |
|
return sm_code; |
|
} |
|
|
|
|
|
static ox* parse_ox_command() |
static ox* parse_ox_command() |
{ |
{ |
ox* m; |
ox* m; |
|
|
parse_comma(); |
parse_comma(); |
|
parse_left_parenthesis(); |
m = (ox *)new_ox_command(parse_sm()); |
m = (ox *)new_ox_command(parse_sm()); |
parse_right_parenthesis(); |
parse_right_parenthesis(); |
return m; |
return m; |
} |
} |
|
|
|
static int parse_sm() |
|
{ |
|
int sm_code; |
|
if (token != TOKEN(SM)) { |
|
parse_error("no opecode."); |
|
} |
|
sm_code = yylval.d; |
|
token = lex(); |
|
parse_right_parenthesis(); |
|
return sm_code; |
|
} |
|
|
|
|
/* 正しい入力ならば, parse_cmo を呼ぶ時点で, token には |
/* 正しい入力ならば, parse_cmo を呼ぶ時点で, token には |
TOKEN(CMO_xxx), TOKEN(OX_xxx) のいずれかがセットされている. */ |
TOKEN(CMO_xxx), TOKEN(OX_xxx) のいずれかがセットされている. */ |
static cmo *parse_cmo() |
static cmo *parse_cmo() |
Line 227 static cmo *parse_cmo() |
|
Line 229 static cmo *parse_cmo() |
|
token = lex(); |
token = lex(); |
m = parse_cmo_ring_by_name(); |
m = parse_cmo_ring_by_name(); |
break; |
break; |
|
case TOKEN(CMO_DISTRIBUTED_POLYNOMIAL): |
|
token = lex(); |
|
m = parse_cmo_distributed_polynomial(); |
|
break; |
case TOKEN(CMO_ERROR2): |
case TOKEN(CMO_ERROR2): |
token = lex(); |
token = lex(); |
m = parse_cmo_error2(); |
m = parse_cmo_error2(); |
break; |
break; |
default: |
default: |
parse_error("syntax error: invalid cmo_tag."); |
parse_error("invalid cmo."); |
} |
} |
return m; |
return m; |
} |
} |
Line 240 static cmo *parse_cmo() |
|
Line 246 static cmo *parse_cmo() |
|
static int parse_left_parenthesis() |
static int parse_left_parenthesis() |
{ |
{ |
if (token != '(') { |
if (token != '(') { |
parse_error("syntax error: no left parenthesis."); |
parse_error("no left parenthesis."); |
} |
} |
token = lex(); |
token = lex(); |
} |
} |
Line 248 static int parse_left_parenthesis() |
|
Line 254 static int parse_left_parenthesis() |
|
static int parse_right_parenthesis() |
static int parse_right_parenthesis() |
{ |
{ |
if (token != ')') { |
if (token != ')') { |
parse_error("syntax error: no right parenthesis."); |
parse_error("no right parenthesis."); |
} |
} |
token = lex(); |
token = lex(); |
} |
} |
Line 256 static int parse_right_parenthesis() |
|
Line 262 static int parse_right_parenthesis() |
|
static int parse_comma() |
static int parse_comma() |
{ |
{ |
if (token != ',') { |
if (token != ',') { |
parse_error("syntax error: no comma."); |
parse_error("no comma."); |
} |
} |
token = lex(); |
token = lex(); |
} |
} |
Line 265 static int parse_integer() |
|
Line 271 static int parse_integer() |
|
{ |
{ |
int val; |
int val; |
if (token != T_INTEGER) { |
if (token != T_INTEGER) { |
parse_error("syntax error: no integer."); |
parse_error("no integer."); |
} |
} |
val = yylval.d; |
val = yylval.d; |
token = lex(); |
token = lex(); |
Line 276 static char *parse_string() |
|
Line 282 static char *parse_string() |
|
{ |
{ |
char *s; |
char *s; |
if (token != T_STRING) { |
if (token != T_STRING) { |
parse_error("syntax error: no string."); |
parse_error("no string."); |
} |
} |
s = yylval.sym; |
s = yylval.sym; |
token = lex(); |
token = lex(); |
Line 309 static cmo *parse_cmo_string() |
|
Line 315 static cmo *parse_cmo_string() |
|
parse_integer(); |
parse_integer(); |
parse_comma(); |
parse_comma(); |
}else if (!pflag_cmo_addrev) { |
}else if (!pflag_cmo_addrev) { |
parse_error("syntax error: not a cmo string."); |
parse_error("invalid cmo string."); |
} |
} |
s = parse_string(); |
s = parse_string(); |
m = new_cmo_string(s); |
m = new_cmo_string(s); |
Line 342 static cmo *parse_cmo_list() |
|
Line 348 static cmo *parse_cmo_list() |
|
parse_integer(); |
parse_integer(); |
parse_comma(); |
parse_comma(); |
}else if (!pflag_cmo_addrev) { |
}else if (!pflag_cmo_addrev) { |
parse_error("syntax error: not a list."); |
parse_error("invalid cmo_list."); |
} |
} |
|
|
while(token == '(') { |
while(token == '(') { |
Line 355 static cmo *parse_cmo_list() |
|
Line 361 static cmo *parse_cmo_list() |
|
parse_comma(); |
parse_comma(); |
} |
} |
}else if (!pflag_cmo_addrev) { |
}else if (!pflag_cmo_addrev) { |
parse_error("syntax error: not a list."); |
parse_error("invalid cmo_list."); |
} |
} |
parse_right_parenthesis(); |
parse_right_parenthesis(); |
return (cmo *)m; |
return (cmo *)m; |
Line 367 static cmo *parse_cmo_monomial32() |
|
Line 373 static cmo *parse_cmo_monomial32() |
|
int *exps; |
int *exps; |
int i; |
int i; |
cmo_monomial32 *m; |
cmo_monomial32 *m; |
|
int tag; |
|
|
parse_comma(); |
parse_comma(); |
size = parse_integer(); |
size = parse_integer(); |
if (size <= 0) { |
if (size < 0) { |
parse_error("syntax error: invalid value."); |
parse_error("invalid value."); |
} |
} |
m = new_cmo_monomial32_size(size); |
m = new_cmo_monomial32_size(size); |
|
|
Line 382 static cmo *parse_cmo_monomial32() |
|
Line 389 static cmo *parse_cmo_monomial32() |
|
parse_comma(); |
parse_comma(); |
parse_left_parenthesis(); |
parse_left_parenthesis(); |
m->coef = parse_cmo(); |
m->coef = parse_cmo(); |
/* 意味的チェックの必要あり */ |
tag = m->coef->tag; |
|
|
|
/* m->coef は CMO_ZZ 型か CMO_INT32 型でなければならない */ |
|
if (tag != CMO_ZZ && tag != CMO_INT32) { |
|
parse_error("invalid cmo."); |
|
} |
parse_right_parenthesis(); |
parse_right_parenthesis(); |
return (cmo *)m; |
return (cmo *)m; |
} |
} |
Line 407 static cmo *parse_cmo_zz() |
|
Line 419 static cmo *parse_cmo_zz() |
|
}else if (pflag_cmo_addrev) { |
}else if (pflag_cmo_addrev) { |
m = new_cmo_zz_set_si(length); |
m = new_cmo_zz_set_si(length); |
}else { |
}else { |
parse_error("syntax error: invalid symbol."); |
parse_error("no comma."); |
} |
} |
|
|
parse_right_parenthesis(); |
parse_right_parenthesis(); |
Line 433 static cmo *parse_cmo_ring_by_name() |
|
Line 445 static cmo *parse_cmo_ring_by_name() |
|
parse_comma(); |
parse_comma(); |
parse_left_parenthesis(); |
parse_left_parenthesis(); |
ob = parse_cmo(); |
ob = parse_cmo(); |
/* 意味的チェックが必要(ob->tag == CMO_STRINGでなければいけない) */ |
|
|
/* ob は CMO_STRING 型でなければならない */ |
|
if (ob->tag != CMO_STRING) { |
|
parse_error("invalid cmo."); |
|
} |
parse_right_parenthesis(); |
parse_right_parenthesis(); |
return (cmo *)new_cmo_ring_by_name(ob); |
return (cmo *)new_cmo_ring_by_name(ob); |
} |
} |
|
|
|
static cmo *parse_cmo_distributed_polynomial() |
|
{ |
|
int length=0; |
|
int i=0; |
|
cmo_distributed_polynomial *m = new_cmo_distributed_polynomial(); |
|
cmo *ob; |
|
int tag; |
|
|
|
if (token == ',') { |
|
parse_comma(); |
|
|
|
if (token == T_INTEGER) { |
|
parse_integer(); |
|
parse_comma(); |
|
}else if (!pflag_cmo_addrev) { |
|
parse_error("invalid d-polynomial."); |
|
} |
|
|
|
parse_left_parenthesis(); |
|
m->ringdef = parse_cmo(); |
|
tag = m->ringdef->tag; |
|
/* m->ringdef は DringDefinition でなければならない */ |
|
if (tag != CMO_RING_BY_NAME && tag != CMO_DMS_GENERIC |
|
&& tag != CMO_DMS_OF_N_VARIABLES) { |
|
parse_error("invalid cmo."); |
|
} |
|
|
|
parse_comma(); |
|
|
|
while(token == '(') { |
|
parse_left_parenthesis(); |
|
ob = parse_cmo(); |
|
if (ob->tag != CMO_MONOMIAL32 && ob->tag != CMO_ZERO) { |
|
parse_error("invalid cmo."); |
|
} |
|
append_cmo_list(m, ob); |
|
if (token != ',') { |
|
break; |
|
} |
|
parse_comma(); |
|
} |
|
}else if (!pflag_cmo_addrev) { |
|
parse_error("invalid d-polynomial."); |
|
} |
|
parse_right_parenthesis(); |
|
return (cmo *)m; |
|
} |
|
|
|
|
static cmo *parse_cmo_error2() |
static cmo *parse_cmo_error2() |
{ |
{ |
cmo *ob; |
cmo *ob; |
Line 513 static char *lex_quoted_string() |
|
Line 578 static char *lex_quoted_string() |
|
typedef struct { |
typedef struct { |
char *key; |
char *key; |
int token; |
int token; |
|
int op; |
} symbol; |
} symbol; |
|
|
#define MK_KEY(x) { #x , TOKEN(x) } |
#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[] = { |
static symbol symbol_list[] = { |
MK_KEY(CMO_NULL), |
MK_KEY_CMO(CMO_NULL), |
MK_KEY(CMO_INT32), |
MK_KEY_CMO(CMO_INT32), |
MK_KEY(CMO_DATUM), |
MK_KEY_CMO(CMO_DATUM), |
MK_KEY(CMO_STRING), |
MK_KEY_CMO(CMO_STRING), |
MK_KEY(CMO_MATHCAP), |
MK_KEY_CMO(CMO_MATHCAP), |
MK_KEY(CMO_LIST), |
MK_KEY_CMO(CMO_LIST), |
MK_KEY(CMO_MONOMIAL32), |
MK_KEY_CMO(CMO_MONOMIAL32), |
MK_KEY(CMO_ZZ), |
MK_KEY_CMO(CMO_ZZ), |
MK_KEY(CMO_ZERO), |
MK_KEY_CMO(CMO_ZERO), |
MK_KEY(CMO_DMS_GENERIC), |
MK_KEY_CMO(CMO_DMS_GENERIC), |
MK_KEY(CMO_RING_BY_NAME), |
MK_KEY_CMO(CMO_RING_BY_NAME), |
MK_KEY(CMO_INDETERMINATE), |
MK_KEY_CMO(CMO_INDETERMINATE), |
MK_KEY(CMO_ERROR2), |
MK_KEY_CMO(CMO_DISTRIBUTED_POLYNOMIAL), |
MK_KEY(SM_popCMO), |
MK_KEY_CMO(CMO_ERROR2), |
MK_KEY(SM_popString), |
MK_KEY_SM(SM_popCMO), |
MK_KEY(SM_mathcap), |
MK_KEY_SM(SM_popString), |
MK_KEY(SM_pops), |
MK_KEY_SM(SM_mathcap), |
MK_KEY(SM_executeStringByLocalParser), |
MK_KEY_SM(SM_pops), |
MK_KEY(SM_executeFunction), |
MK_KEY_SM(SM_executeStringByLocalParser), |
MK_KEY(SM_setMathCap), |
MK_KEY_SM(SM_executeFunction), |
MK_KEY(SM_control_kill), |
MK_KEY_SM(SM_setMathCap), |
MK_KEY(SM_control_reset_connection), |
MK_KEY_SM(SM_control_kill), |
MK_KEY(OX_COMMAND), MK_KEY(OX_DATA), |
MK_KEY_SM(SM_control_reset_connection), |
|
MK_KEY(OX_COMMAND), |
|
MK_KEY(OX_DATA), |
{NULL, 0} /* a gate keeper */ |
{NULL, 0} /* a gate keeper */ |
}; |
}; |
|
|
Line 549 static int token_of_symbol(char *key) |
|
Line 619 static int token_of_symbol(char *key) |
|
symbol *kp; |
symbol *kp; |
for(kp = symbol_list; kp->key != NULL; kp++) { |
for(kp = symbol_list; kp->key != NULL; kp++) { |
if (strcmp(key, kp->key)==0) { |
if (strcmp(key, kp->key)==0) { |
|
yylval.d = kp->op; |
return kp->token; |
return kp->token; |
} |
} |
} |
} |