version 1.15, 2004/12/01 17:32:26 |
version 1.17, 2015/08/27 03:03:34 |
|
|
/* -*- mode: C; coding: euc-japan -*- */ |
/* -*- 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.16 2005/07/20 17:48:03 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() |