| version 1.14, 2003/06/02 10:25:57 |
version 1.18, 2018/04/05 06:05:44 |
|
|
| /* -*- mode: C; coding: euc-japan -*- */ |
/* -*- mode: C; coding: euc-japan -*- */ |
| /* $OpenXM: OpenXM/src/ox_toolkit/parse.c,v 1.13 2003/03/30 08:05:23 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. |
This module is a parser for OX/CMO expressions. |
|
|
| #include <stdio.h> |
#include <stdio.h> |
| #include <stdlib.h> |
#include <stdlib.h> |
| #include <string.h> |
#include <string.h> |
| #include <sys/param.h> |
|
| #include <setjmp.h> |
#include <setjmp.h> |
| #include <ctype.h> |
#include <ctype.h> |
| |
#if !defined(_MSC_VER) |
| |
#include <sys/param.h> |
| |
#endif |
| |
|
| #include "ox_toolkit.h" |
#include "ox_toolkit.h" |
| #include "parse.h" |
#include "parse.h" |
|
|
| static int pflag_cmo_addrev = 1; |
static int pflag_cmo_addrev = 1; |
| |
|
| /* definitions of local functions */ |
/* definitions of local functions */ |
| |
static void init_parser(char *s); |
| |
static cmo *parse(); |
| static void parse_error(char *s); |
static void parse_error(char *s); |
| static void parse_right_parenthesis(); |
static void parse_right_parenthesis(); |
| static void parse_left_parenthesis(); |
static void parse_left_parenthesis(); |
| Line 76 static ox *parse_ox_data(); |
|
| Line 80 static ox *parse_ox_data(); |
|
| static void init_lex(char *s); |
static void init_lex(char *s); |
| static int lex(); |
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) |
static int is_token_cmo(int token) |
| { |
{ |
| Line 101 static void parse_error(char *s) |
|
| Line 110 static void parse_error(char *s) |
|
| longjmp(env_parse, 1); |
longjmp(env_parse, 1); |
| } |
} |
| |
|
| void setflag_parse(int flag) |
static void setflag_parse(int flag) |
| { |
{ |
| pflag_cmo_addrev = flag; |
pflag_cmo_addrev = flag; |
| } |
} |
| |
|
| void init_parser(char *s) |
static void init_parser(char *s) |
| { |
{ |
| setflag_parse(PFLAG_ADDREV); |
setflag_parse(PFLAG_ADDREV); |
| init_lex(s); |
init_lex(s); |
| } |
} |
| |
|
| cmo *parse() |
static cmo *parse() |
| { |
{ |
| cmo *m; |
cmo *m = NULL; |
| |
if (setjmp(env_parse) == 0) { |
| if (setjmp(env_parse) != 0) { |
|
| return NULL; |
|
| /* This is an error. */ |
|
| } |
|
| |
|
| token = lex(); |
|
| if (token == '(') { |
|
| token = lex(); |
token = lex(); |
| if (is_token_cmo(token)) { |
if (token == '(') { |
| m = parse_cmo(); |
token = lex(); |
| }else if(is_token_ox(token)) { |
if (is_token_cmo(token)) { |
| m = parse_ox(); |
m = parse_cmo(); |
| }else { |
}else if(is_token_ox(token)) { |
| parse_error("invalid symbol."); |
m = parse_ox(); |
| |
}else { |
| |
parse_error("invalid symbol."); |
| |
} |
| } |
} |
| return m; |
|
| } |
} |
| return NULL; |
return m; |
| } |
} |
| |
|
| static ox *parse_ox() |
static ox *parse_ox() |
| Line 643 static struct symbol symbol_list[] = { |
|
| Line 647 static struct symbol symbol_list[] = { |
|
| MK_KEY_CMO(CMO_MONOMIAL32), |
MK_KEY_CMO(CMO_MONOMIAL32), |
| MK_KEY_CMO(CMO_ZZ), |
MK_KEY_CMO(CMO_ZZ), |
| MK_KEY_CMO(CMO_ZERO), |
MK_KEY_CMO(CMO_ZERO), |
| |
MK_KEY_CMO(CMO_TREE), |
| MK_KEY_CMO(CMO_DMS_GENERIC), |
MK_KEY_CMO(CMO_DMS_GENERIC), |
| MK_KEY_CMO(CMO_RING_BY_NAME), |
MK_KEY_CMO(CMO_RING_BY_NAME), |
| MK_KEY_CMO(CMO_INDETERMINATE), |
MK_KEY_CMO(CMO_INDETERMINATE), |
| MK_KEY_CMO(CMO_DISTRIBUTED_POLYNOMIAL), |
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_CMO(CMO_ERROR2), |
| MK_KEY_SM(SM_popCMO), |
MK_KEY_SM(SM_popCMO), |
| MK_KEY_SM(SM_popString), |
MK_KEY_SM(SM_popString), |
| Line 785 static int lex() |
|
| Line 792 static int lex() |
|
| yylval.sym = lex_quoted_string(); |
yylval.sym = lex_quoted_string(); |
| return T_STRING; |
return T_STRING; |
| default: |
default: |
| |
; |
| } |
} |
| |
|
| if (isalpha(c)) { |
if (isalpha(c)) { |