=================================================================== RCS file: /home/cvs/OpenXM/src/ox_toolkit/parse.c,v retrieving revision 1.15 retrieving revision 1.18 diff -u -p -r1.15 -r1.18 --- OpenXM/src/ox_toolkit/parse.c 2004/12/01 17:32:26 1.15 +++ OpenXM/src/ox_toolkit/parse.c 2018/04/05 06:05:44 1.18 @@ -1,5 +1,5 @@ /* -*- mode: C; coding: euc-japan -*- */ -/* $OpenXM: OpenXM/src/ox_toolkit/parse.c,v 1.14 2003/06/02 10:25:57 ohara Exp $ */ +/* $OpenXM: OpenXM/src/ox_toolkit/parse.c,v 1.17 2015/08/27 03:03:34 ohara Exp $ */ /* This module is a parser for OX/CMO expressions. @@ -10,9 +10,11 @@ #include #include #include -#include #include #include +#if !defined(_MSC_VER) +#include +#endif #include "ox_toolkit.h" #include "parse.h" @@ -48,6 +50,8 @@ static union{ static int pflag_cmo_addrev = 1; /* definitions of local functions */ +static void init_parser(char *s); +static cmo *parse(); static void parse_error(char *s); static void parse_right_parenthesis(); static void parse_left_parenthesis(); @@ -76,6 +80,11 @@ static ox *parse_ox_data(); static void init_lex(char *s); static int lex(); +/* Parsing a Lisp-style expression of CMO. */ +cmo *ox_parse_lisp(char *s) +{ + return (s != NULL && strlen(s) > 0)? init_parser(s), parse(): NULL; +} static int is_token_cmo(int token) { @@ -101,39 +110,34 @@ static void parse_error(char *s) longjmp(env_parse, 1); } -void setflag_parse(int flag) +static void setflag_parse(int flag) { pflag_cmo_addrev = flag; } -void init_parser(char *s) +static void init_parser(char *s) { setflag_parse(PFLAG_ADDREV); init_lex(s); } -cmo *parse() +static cmo *parse() { - cmo *m; - - if (setjmp(env_parse) != 0) { - return NULL; - /* This is an error. */ - } - - token = lex(); - if (token == '(') { + cmo *m = NULL; + if (setjmp(env_parse) == 0) { token = lex(); - if (is_token_cmo(token)) { - m = parse_cmo(); - }else if(is_token_ox(token)) { - m = parse_ox(); - }else { - parse_error("invalid symbol."); + if (token == '(') { + token = lex(); + if (is_token_cmo(token)) { + m = parse_cmo(); + }else if(is_token_ox(token)) { + m = parse_ox(); + }else { + parse_error("invalid symbol."); + } } - return m; } - return NULL; + return m; } static ox *parse_ox() @@ -643,10 +647,13 @@ static struct symbol symbol_list[] = { MK_KEY_CMO(CMO_MONOMIAL32), MK_KEY_CMO(CMO_ZZ), MK_KEY_CMO(CMO_ZERO), + MK_KEY_CMO(CMO_TREE), 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_POLYNOMIAL_IN_ONE_VARIABLE), + MK_KEY_CMO(CMO_RECURSIVE_POLYNOMIAL), MK_KEY_CMO(CMO_ERROR2), MK_KEY_SM(SM_popCMO), MK_KEY_SM(SM_popString),