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) 42 static VALUE CparseParams;
45 static ID id_nexttoken;
47 static ID id_noreduce;
48 static ID id_errstatus;
51 static ID id_d_reduce;
52 static ID id_d_accept;
53 static ID id_d_read_token;
54 static ID id_d_next_state;
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) 76 static inline long num_to_long
_((
VALUE n));
93 #define AREF(s, idx) \ 94 ((0 <= idx && idx < RARRAY_LEN(s)) ? rb_ary_entry(s, idx) : Qnil) 101 static void cut_stack_tail
_((
VALUE stack,
long len));
104 get_stack_tail(
VALUE stack,
long len)
106 if (len < 0)
return Qnil;
112 cut_stack_tail(
VALUE stack,
long len)
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 198 static long assert_integer
_((
VALUE n));
202 static void cparse_params_mark
_((
void *ptr));
203 static size_t cparse_params_memsize
_((
const void *ptr));
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 229 cparse_params_memsize,
231 #ifdef RUBY_TYPED_FREE_IMMEDIATELY 244 &cparse_params_type, v);
245 D_puts(
"starting cparse");
247 vparams = initialize_params(vparams, parser, arg,
Qnil,
Qnil);
262 &cparse_params_type, v);
264 D_puts(
"start C yyparse");
265 vparams = initialize_params(vparams, parser, arg, lexer, lexmid);
267 D_puts(
"params initialized");
279 #ifdef HAVE_RB_BLOCK_CALL 287 lexer_iter(
VALUE data)
310 extract_user_token(v, block_args, &tok, &val);
311 parse_main(v, tok, val, 1);
318 assert_array(
VALUE a)
332 assert_integer(
VALUE n)
346 v->
lexmid = value_to_id(lexmid);
400 cparse_params_mark(
void *ptr)
425 cparse_params_memsize(
const void *ptr)
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);
511 extract_user_token(v, tmp, &tok, &val);
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)) {
576 rb_raise(RaccBug,
"[Racc Bug] unknown act value %ld", act);
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)) {
678 rb_raise(RaccBug,
"[Racc Bug] unknown act value %ld", act);
680 goto error_recovered;
710 VALUE reduce_to, reduce_len, method_id;
721 mid = value_to_id(method_id);
726 if (mid != id_noreduce)
732 if (mid != id_noreduce) {
746 if (mid != id_noreduce) {
749 3, tmp_v, v->
vstack, tmp);
767 rb_raise(RaccBug,
"state stack unexpectedly empty");
769 k1 = num_to_long(reduce_to) - v->
nt_base;
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 $"));
849 id_errstatus =
rb_intern(
"@racc_error_status");
854 id_d_read_token =
rb_intern(
"racc_read_token");
855 id_d_next_state =
rb_intern(
"racc_next_state");
VALUE rb_ary_pop(VALUE ary)
VALUE rb_ary_entry(VALUE ary, long offset)
#define RUBY_TYPED_FREE_IMMEDIATELY
void rb_undef_alloc_func(VALUE)
VALUE rb_ary_subseq(VALUE ary, long beg, long len)
void rb_raise(VALUE exc, const char *fmt,...)
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_iterate(VALUE(*)(VALUE), VALUE, VALUE(*)(ANYARGS), VALUE)
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.
VALUE rb_ivar_get(VALUE, ID)
int rb_const_defined(VALUE, ID)
VALUE rb_block_call(VALUE, ID, int, const VALUE *, rb_block_call_func_t, VALUE)
void rb_gc_mark(VALUE ptr)
#define SHIFT(v, act, tok, val)
void rb_undef_method(VALUE klass, const char *name)
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
VALUE rb_obj_class(VALUE)
call-seq: obj.class -> class
#define RB_TYPE_P(obj, type)
RUBY_EXTERN VALUE rb_cObject
void rb_define_const(VALUE, const char *, VALUE)
VALUE rb_const_get(VALUE, ID)
VALUE rb_ivar_set(VALUE, ID, VALUE)
VALUE rb_catch(const char *, VALUE(*)(ANYARGS), VALUE)
const char * rb_id2name(ID)
register unsigned int len
VALUE rb_hash_aref(VALUE hash, VALUE key)
#define D_printf(fmt, arg)
#define TypedData_Make_Struct(klass, type, data_type, sval)
VALUE rb_const_get_at(VALUE, ID)
#define RUBY_TYPED_DEFAULT_FREE
VALUE rb_define_module(const char *name)
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
VALUE rb_str_new(const char *, long)