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)) ? rb_ary_entry(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) ? rb_ary_entry(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 214 # define D_puts(msg) if (v->sys_debug) puts(msg) 215 # define D_printf(fmt,arg) if (v->sys_debug) printf(fmt,arg) 218 # define D_printf(fmt,arg) 221 #undef RUBY_UNTYPED_DATA_WARNING 222 #define RUBY_UNTYPED_DATA_WARNING 1 231 #ifdef RUBY_TYPED_FREE_IMMEDIATELY 244 &cparse_params_type, v);
245 D_puts(
"starting cparse");
262 &cparse_params_type, v);
264 D_puts(
"start C yyparse");
267 D_puts(
"params initialized");
279 #ifdef HAVE_RB_BLOCK_CALL 434 if (
NIL_P(block_args)) {
443 "%s() %s %"PRIsVALUE" (must be Array[2])",
450 "%s() %s wrong size of array (%ld for 2)",
455 *tok =
AREF(block_args, 0);
456 *val =
AREF(block_args, 1);
459 #define SHIFT(v,act,tok,val) shift(v,act,tok,val) 460 #define REDUCE(v,act) do {\ 461 switch (reduce(v,act)) { \ 467 D_puts("u accept"); \ 488 D_puts(
"---- enter new loop ----");
493 if (
NIL_P(tmp))
goto notfound;
494 D_puts(
"(act) pointer[k1] ok");
497 D_printf(
"read_next=%d\n", read_next);
528 if (i < 0)
goto notfound;
531 if (
NIL_P(act_value))
goto notfound;
533 D_printf(
"(act) table[i]=%ld\n", act);
536 if (
NIL_P(tmp))
goto notfound;
546 D_puts(
"(act) not found: use default");
553 if (act > 0 && act < v->
shift_n) {
562 else if (act < 0 && act > -(v->
reduce_n)) {
618 if (
NIL_P(tmp))
goto error_pop;
619 D_puts(
"(err) pointer[k1] ok");
623 if (i < 0)
goto error_pop;
626 if (
NIL_P(act_value)) {
627 D_puts(
"(err) table[i] == nil");
631 D_printf(
"(err) table[i]=%ld\n", act);
635 D_puts(
"(err) check[i] == nil");
639 D_puts(
"(err) check[i] != k1");
643 D_puts(
"(err) found: can handle error token");
647 D_puts(
"(err) act not found: can't handle error token; pop");
665 if (act > 0 && act < v->
shift_n) {
669 else if (act < 0 && act > -(v->
reduce_n)) {
680 goto error_recovered;
710 VALUE reduce_to, reduce_len, method_id;
749 3, tmp_v, v->
vstack, tmp);
774 if (
NIL_P(tmp))
goto notfound;
778 if (i < 0)
goto notfound;
781 if (
NIL_P(goto_state)) {
782 D_puts(
"(goto) table[i] == nil");
789 D_puts(
"(goto) check[i] == nil");
793 D_puts(
"(goto) check[i] != table[i]");
805 D_puts(
"(goto) not found: use default");
819 #define rb_intern(str) rb_intern_const(str) 836 rb_str_new2(
"$originalId: cparse.c,v 1.8 2006/07/06 11:39:46 aamine Exp $"));
VALUE rb_ary_pop(VALUE ary)
VALUE rb_ary_entry(VALUE ary, long offset)
#define RUBY_TYPED_FREE_IMMEDIATELY
static VALUE get_stack_tail(VALUE stack, long len)
static void parse_main(struct cparse_params *v, VALUE tok, VALUE val, int resume)
void rb_undef_alloc_func(VALUE)
VALUE rb_ary_subseq(VALUE ary, long beg, long len)
static ID id_d_next_state
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_iterate(VALUE(*)(VALUE), VALUE, VALUE(*)(ANYARGS), VALUE)
static ID value_to_id _((VALUE v))
static long num_to_long(VALUE n)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
VALUE rb_iv_set(VALUE, const char *, VALUE)
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_ivar_get(VALUE, ID)
int rb_const_defined(VALUE, ID)
static void call_lexer(struct cparse_params *v)
VALUE rb_block_call(VALUE, ID, int, const VALUE *, rb_block_call_func_t, VALUE)
void rb_gc_mark(VALUE ptr)
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)
void rb_undef_method(VALUE klass, const char *name)
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
#define RB_TYPE_P(obj, type)
RUBY_EXTERN VALUE rb_cObject
static void cparse_params_mark(void *ptr)
void rb_define_const(VALUE, const char *, VALUE)
static VALUE racc_cparse(VALUE parser, VALUE arg, VALUE sysdebug)
static VALUE assert_array(VALUE a)
VALUE rb_const_get(VALUE, ID)
static size_t cparse_params_memsize(const void *ptr)
static ID value_to_id(VALUE v)
VALUE rb_ivar_set(VALUE, ID, VALUE)
VALUE rb_catch(const char *, VALUE(*)(ANYARGS), VALUE)
static VALUE initialize_params(VALUE vparams, VALUE parser, VALUE arg, VALUE lexer, VALUE lexmid)
const char * rb_id2name(ID)
static void shift(struct cparse_params *v, long act, VALUE tok, VALUE val)
static int reduce(struct cparse_params *v, long act)
register unsigned int len
static const rb_data_type_t cparse_params_type
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
VALUE rb_hash_aref(VALUE hash, VALUE key)
static VALUE lexer_i(RB_BLOCK_CALL_FUNC_ARGLIST(block_args, data))
static VALUE assert_hash(VALUE h)
#define D_printf(fmt, arg)
static VALUE CparseParams
static VALUE racc_yyparse(VALUE parser, VALUE lexer, VALUE lexmid, VALUE arg, VALUE sysdebug)
static VALUE lexer_iter(VALUE data)
#define TypedData_Make_Struct(klass, type, data_type, sval)
static VALUE reduce0(VALUE val, VALUE data, VALUE self)
VALUE rb_const_get_at(VALUE, ID)
#define RUBY_TYPED_DEFAULT_FREE
VALUE rb_define_module(const char *name)
static ID id_d_read_token
VALUE rb_obj_class(VALUE)
VALUE rb_str_new(const char *, long)