version 1.2, 1999/11/02 06:11:58 |
version 1.3, 1999/11/02 18:58:25 |
|
|
/* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
/* $OpenXM$ */ |
/* $OpenXM: OpenXM/src/ox_math/parse.c,v 1.2 1999/11/02 06:11:58 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 >= MIN_T_SM && token < MAX_T_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 161 static ox* parse_ox_data() |
|
Line 161 static ox* parse_ox_data() |
|
static int parse_sm() |
static int parse_sm() |
{ |
{ |
int sm_code; |
int sm_code; |
if (!is_t_sm(token)) { |
if (!is_token_sm(token)) { |
parse_error("syntax error: invalid sm code."); |
parse_error("invalid SM opecode."); |
} |
} |
sm_code = token - T_MAGIC; |
sm_code = token - T_MAGIC; |
token = lex(); |
token = lex(); |
Line 227 static cmo *parse_cmo() |
|
Line 227 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 244 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 252 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 260 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 269 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 280 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 313 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 346 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 359 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 371 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 387 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 417 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 443 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 515 typedef struct { |
|
Line 578 typedef struct { |
|
int token; |
int token; |
} symbol; |
} symbol; |
|
|
|
#define MK_KEY_CMO(x) { #x , TOKEN(x) } |
#define MK_KEY(x) { #x , TOKEN(x) } |
#define MK_KEY(x) { #x , TOKEN(x) } |
|
|
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_CMO(CMO_ERROR2), |
MK_KEY(SM_popCMO), |
MK_KEY(SM_popCMO), |
MK_KEY(SM_popString), |
MK_KEY(SM_popString), |
MK_KEY(SM_mathcap), |
MK_KEY(SM_mathcap), |