27#define RACC_VERSION "1.4.15"
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)
42static VALUE CparseParams;
45static ID id_nexttoken;
48static ID id_errstatus;
53static ID id_d_read_token;
54static 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)
75#ifndef HAVE_RB_ARY_SUBSEQ
76# define rb_ary_subseq(ary, beg, len) rb_ary_new4(len, RARRAY_PTR(ary) + beg)
80static inline long num_to_long
_((
VALUE n));
98 ((0 <= idx && idx < RARRAY_LEN(s)) ? rb_ary_entry(s, idx) : Qnil)
105static void cut_stack_tail
_((
VALUE stack,
long len));
108get_stack_tail(
VALUE stack,
long len)
116cut_stack_tail(
VALUE stack,
long len)
124#define STACK_INIT_LEN 64
125#define NEW_STACK() rb_ary_new2(STACK_INIT_LEN)
126#define PUSH(s, i) rb_ary_store(s, RARRAY_LEN(s), i)
127#define POP(s) rb_ary_pop(s)
129 ((RARRAY_LEN(s) > 0) ? rb_ary_entry(s, RARRAY_LEN(s) - 1) : Qnil)
130#define GET_TAIL(s, len) get_stack_tail(s, len)
131#define CUT_TAIL(s, len) cut_stack_tail(s, len)
180#define CP_FIN_ACCEPT 1
182#define CP_FIN_CANTPOP 3
202static long assert_integer
_((
VALUE n));
206static void cparse_params_mark
_((
void *
ptr));
207static size_t cparse_params_memsize
_((
const void *
ptr));
218# define D_puts(msg) if (v->sys_debug) puts(msg)
219# define D_printf(fmt,arg) if (v->sys_debug) printf(fmt,arg)
222# define D_printf(fmt,arg)
225#undef RUBY_UNTYPED_DATA_WARNING
226#define RUBY_UNTYPED_DATA_WARNING 1
233 cparse_params_memsize,
235#ifdef RUBY_TYPED_FREE_IMMEDIATELY
248 &cparse_params_type, v);
249 D_puts(
"starting cparse");
266 &cparse_params_type, v);
268 D_puts(
"start C yyparse");
271 D_puts(
"params initialized");
283#ifdef HAVE_RB_BLOCK_CALL
291lexer_iter(
VALUE data)
314 extract_user_token(v, block_args, &
tok, &val);
315 parse_main(v,
tok, val, 1);
336assert_integer(
VALUE n)
404cparse_params_mark(
void *
ptr)
429cparse_params_memsize(
const void *
ptr)
438 if (
NIL_P(block_args)) {
445 if (!RB_TYPE_P(block_args,
T_ARRAY)) {
447 "%s() %s %"PRIsVALUE" (must be Array[2])",
454 "%s() %s wrong size of array (%ld for 2)",
460 *val =
AREF(block_args, 1);
463#define SHIFT(v,act,tok,val) shift(v,act,tok,val)
464#define REDUCE(v,act) do {\
465 switch (reduce(v,act)) { \
471 D_puts("u accept"); \
492 D_puts(
"---- enter new loop ----");
497 if (
NIL_P(tmp))
goto notfound;
498 D_puts(
"(act) pointer[k1] ok");
501 D_printf(
"read_next=%d\n", read_next);
515 extract_user_token(v, tmp, &
tok, &val);
532 if (
i < 0)
goto notfound;
535 if (
NIL_P(act_value))
goto notfound;
537 D_printf(
"(act) table[i]=%ld\n", act);
540 if (
NIL_P(tmp))
goto notfound;
550 D_puts(
"(act) not found: use default");
557 if (act > 0 && act < v->
shift_n) {
566 else if (act < 0 && act > -(v->
reduce_n)) {
580 rb_raise(RaccBug,
"[Racc Bug] unknown act value %ld", act);
622 if (
NIL_P(tmp))
goto error_pop;
623 D_puts(
"(err) pointer[k1] ok");
627 if (
i < 0)
goto error_pop;
630 if (
NIL_P(act_value)) {
631 D_puts(
"(err) table[i] == nil");
635 D_printf(
"(err) table[i]=%ld\n", act);
639 D_puts(
"(err) check[i] == nil");
643 D_puts(
"(err) check[i] != k1");
647 D_puts(
"(err) found: can handle error token");
651 D_puts(
"(err) act not found: can't handle error token; pop");
669 if (act > 0 && act < v->
shift_n) {
673 else if (act < 0 && act > -(v->
reduce_n)) {
682 rb_raise(RaccBug,
"[Racc Bug] unknown act value %ld", act);
684 goto error_recovered;
714 VALUE reduce_to, reduce_len, method_id;
725 mid = value_to_id(method_id);
730 if (mid != id_noreduce)
736 if (mid != id_noreduce) {
750 if (mid != id_noreduce) {
753 3, tmp_v, v->
vstack, tmp);
771 rb_raise(RaccBug,
"state stack unexpectedly empty");
773 k1 = num_to_long(reduce_to) - v->
nt_base;
778 if (
NIL_P(tmp))
goto notfound;
782 if (
i < 0)
goto notfound;
785 if (
NIL_P(goto_state)) {
786 D_puts(
"(goto) table[i] == nil");
793 D_puts(
"(goto) check[i] == nil");
797 D_puts(
"(goto) check[i] != table[i]");
809 D_puts(
"(goto) not found: use default");
822#ifdef HAVE_RB_EXT_RACTOR_SAFE
827 ID id_racc = rb_intern_const(
"Racc");
842 rb_str_new2(
"$originalId: cparse.c,v 1.8 2006/07/06 11:39:46 aamine Exp $"));
851 id_yydebug = rb_intern_const(
"@yydebug");
852 id_nexttoken = rb_intern_const(
"next_token");
853 id_onerror = rb_intern_const(
"on_error");
854 id_noreduce = rb_intern_const(
"_reduce_none");
855 id_errstatus = rb_intern_const(
"@racc_error_status");
857 id_d_shift = rb_intern_const(
"racc_shift");
858 id_d_reduce = rb_intern_const(
"racc_reduce");
859 id_d_accept = rb_intern_const(
"racc_accept");
860 id_d_read_token = rb_intern_const(
"racc_read_token");
861 id_d_next_state = rb_intern_const(
"racc_next_state");
862 id_d_e_pop = rb_intern_const(
"racc_e_pop");
VALUE rb_ary_pop(VALUE ary)
VALUE rb_ary_entry(VALUE ary, long offset)
#define SHIFT(v, act, tok, val)
#define D_printf(fmt, arg)
#define rb_ary_subseq(ary, beg, len)
#define rb_define_private_method(klass, mid, func, arity)
Defines klass#mid and makes it private.
void rb_gc_mark(VALUE ptr)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_define_module(const char *name)
void rb_undef_method(VALUE klass, const char *name)
void rb_raise(VALUE exc, const char *fmt,...)
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
VALUE rb_cObject
Object class.
VALUE rb_obj_class(VALUE)
VALUE rb_hash_aref(VALUE hash, VALUE key)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
void rb_ext_ractor_safe(bool flag)
#define rb_str_new(str, len)
VALUE rb_const_get(VALUE, ID)
VALUE rb_ivar_get(VALUE, ID)
VALUE rb_const_get_at(VALUE, ID)
VALUE rb_ivar_set(VALUE, ID, VALUE)
int rb_const_defined(VALUE, ID)
void rb_undef_alloc_func(VALUE)
const char * rb_id2name(ID)
VALUE rb_iv_set(VALUE, const char *, VALUE)
void rb_define_const(VALUE, const char *, VALUE)
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
VALUE rb_block_call_func(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
VALUE rb_catch(const char *q, type *w, VALUE e)
An equivalent of Kernel#catch.
VALUE rb_block_call(VALUE q, ID w, int e, const VALUE *r, type *t, VALUE y)
Call a method with a block.
VALUE rb_iterate(onearg_type *q, VALUE w, type *e, VALUE r)
Old way to implement iterators.
#define RUBY_TYPED_DEFAULT_FREE
@ RUBY_TYPED_FREE_IMMEDIATELY
#define TypedData_Make_Struct(klass, type, data_type, sval)
void error(const char *msg)