27 #define RACC_VERSION "1.4.5"
29 #define DEFAULT_TOKEN -1
33 #define vDEFAULT_TOKEN INT2FIX(DEFAULT_TOKEN)
34 #define vERROR_TOKEN INT2FIX(ERROR_TOKEN)
35 #define vFINAL_TOKEN INT2FIX(FINAL_TOKEN)
63 # define ID2SYM(i) ULONG2NUM(i)
66 # define SYM2ID(v) ((ID)NUM2ULONG(v))
69 # define SYMBOL_P(v) FIXNUM_P(v)
72 # define LONG2NUM(i) INT2NUM(i)
93 #define AREF(s, idx) \
94 ((0 <= idx && idx < RARRAY_LEN(s)) ? RARRAY_PTR(s)[idx] : Qnil)
106 if (len < 0)
return Qnil;
120 #define STACK_INIT_LEN 64
121 #define NEW_STACK() rb_ary_new2(STACK_INIT_LEN)
122 #define PUSH(s, i) rb_ary_store(s, RARRAY_LEN(s), i)
123 #define POP(s) rb_ary_pop(s)
125 ((RARRAY_LEN(s) > 0) ? RARRAY_PTR(s)[RARRAY_LEN(s) - 1] : Qnil)
126 #define GET_TAIL(s, len) get_stack_tail(s, len)
127 #define CUT_TAIL(s, len) cut_stack_tail(s, len)
176 #define CP_FIN_ACCEPT 1
178 #define CP_FIN_CANTPOP 3
213 # define D_puts(msg) if (v->sys_debug) puts(msg)
214 # define D_printf(fmt,arg) if (v->sys_debug) printf(fmt,arg)
217 # define D_printf(fmt,arg)
223 volatile VALUE vparams;
228 D_puts(
"starting cparse");
240 volatile VALUE vparams;
246 D_puts(
"start C yyparse");
249 D_puts(
"params initialized");
260 #ifdef HAVE_RB_BLOCK_CALL
412 if (
NIL_P(block_args)) {
421 "%s() %s %"PRIsVALUE" (must be Array[2])",
428 "%s() %s wrong size of array (%ld for 2)",
433 *tok =
AREF(block_args, 0);
434 *val =
AREF(block_args, 1);
437 #define SHIFT(v,act,tok,val) shift(v,act,tok,val)
438 #define REDUCE(v,act) do {\
439 switch (reduce(v,act)) { \
445 D_puts("u accept"); \
466 D_puts(
"---- enter new loop ----");
471 if (
NIL_P(tmp))
goto notfound;
472 D_puts(
"(act) pointer[k1] ok");
475 D_printf(
"read_next=%d\n", read_next);
506 if (i < 0)
goto notfound;
509 if (
NIL_P(act_value))
goto notfound;
511 D_printf(
"(act) table[i]=%ld\n", act);
514 if (
NIL_P(tmp))
goto notfound;
524 D_puts(
"(act) not found: use default");
531 if (act > 0 && act < v->
shift_n) {
540 else if (act < 0 && act > -(v->
reduce_n)) {
596 if (
NIL_P(tmp))
goto error_pop;
597 D_puts(
"(err) pointer[k1] ok");
601 if (i < 0)
goto error_pop;
604 if (
NIL_P(act_value)) {
605 D_puts(
"(err) table[i] == nil");
609 D_printf(
"(err) table[i]=%ld\n", act);
613 D_puts(
"(err) check[i] == nil");
617 D_puts(
"(err) check[i] != k1");
621 D_puts(
"(err) found: can handle error token");
625 D_puts(
"(err) act not found: can't handle error token; pop");
643 if (act > 0 && act < v->
shift_n) {
647 else if (act < 0 && act > -(v->
reduce_n)) {
658 goto error_recovered;
688 VALUE reduce_to, reduce_len, method_id;
728 3, tmp_v, v->
vstack, tmp);
753 if (
NIL_P(tmp))
goto notfound;
757 if (i < 0)
goto notfound;
760 if (
NIL_P(goto_state)) {
761 D_puts(
"(goto) table[i] == nil");
768 D_puts(
"(goto) check[i] == nil");
772 D_puts(
"(goto) check[i] != table[i]");
784 D_puts(
"(goto) not found: use default");
813 rb_str_new2(
"$originalId: cparse.c,v 1.8 2006/07/06 11:39:46 aamine Exp $"));
#define RB_TYPE_P(obj, type)
VALUE rb_const_get_at(VALUE, ID)
VALUE rb_ary_pop(VALUE ary)
VALUE rb_ary_new4(long n, const VALUE *elts)
static VALUE get_stack_tail(VALUE stack, long len)
static void parse_main(struct cparse_params *v, VALUE tok, VALUE val, int resume)
VALUE rb_iv_set(VALUE, const char *, VALUE)
#define Data_Make_Struct(klass, type, mark, free, sval)
static VALUE lexer_i(VALUE block_args, VALUE data, VALUE self)
VALUE rb_const_get(VALUE, ID)
static ID id_d_next_state
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
static long num_to_long(VALUE n)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_obj_class(VALUE)
static void call_lexer(struct cparse_params *v)
static void extract_user_token(struct cparse_params *v, VALUE block_args, VALUE *tok, VALUE *val)
#define SHIFT(v, act, tok, val)
static long assert_integer(VALUE n)
static void cut_stack_tail(VALUE stack, long len)
VALUE rb_catch(const char *, VALUE(*)(ANYARGS), VALUE)
VALUE rb_iterate(VALUE(*)(VALUE), VALUE, VALUE(*)(ANYARGS), VALUE)
VALUE rb_ivar_get(VALUE, ID)
void rb_define_const(VALUE, const char *, VALUE)
static void cparse_params_mark(void *ptr)
static VALUE racc_cparse(VALUE parser, VALUE arg, VALUE sysdebug)
static VALUE assert_array(VALUE a)
int rb_const_defined(VALUE, ID)
static ID value_to_id(VALUE v)
VALUE rb_block_call(VALUE, ID, int, VALUE *, VALUE(*)(ANYARGS), VALUE)
static VALUE initialize_params(VALUE vparams, VALUE parser, VALUE arg, VALUE lexer, VALUE lexmid)
static int reduce(struct cparse_params *v, long act)
VALUE rb_ivar_set(VALUE, ID, VALUE)
static VALUE assert_hash(VALUE h)
RUBY_EXTERN VALUE rb_cObject
#define D_printf(fmt, arg)
static VALUE CparseParams
#define Data_Get_Struct(obj, type, sval)
static VALUE racc_yyparse(VALUE parser, VALUE lexer, VALUE lexmid, VALUE arg, VALUE sysdebug)
static VALUE lexer_iter(VALUE data)
VALUE rb_str_new(const char *, long)
static VALUE reduce0(VALUE val, VALUE data, VALUE self)
struct parser_params * parser
const char * rb_id2name(ID id)
VALUE rb_hash_aref(VALUE, VALUE)
VALUE rb_define_module(const char *name)
static ID id_d_read_token