ext/racc/cparse/cparse.c File Reference

#include "ruby/ruby.h"

Go to the source code of this file.

Data Structures

struct  cparse_params

Defines

#define FALSE   0
#define TRUE   1
#define RACC_VERSION   "1.4.5"
#define DEFAULT_TOKEN   -1
#define ERROR_TOKEN   1
#define FINAL_TOKEN   0
#define vDEFAULT_TOKEN   INT2FIX(DEFAULT_TOKEN)
#define vERROR_TOKEN   INT2FIX(ERROR_TOKEN)
#define vFINAL_TOKEN   INT2FIX(FINAL_TOKEN)
#define AREF(s, idx)   ((0 <= idx && idx < RARRAY_LEN(s)) ? rb_ary_entry(s, idx) : Qnil)
#define STACK_INIT_LEN   64
#define NEW_STACK()   rb_ary_new2(STACK_INIT_LEN)
#define PUSH(s, i)   rb_ary_store(s, RARRAY_LEN(s), i)
#define POP(s)   rb_ary_pop(s)
#define LAST_I(s)   ((RARRAY_LEN(s) > 0) ? rb_ary_entry(s, RARRAY_LEN(s) - 1) : Qnil)
#define GET_TAIL(s, len)   get_stack_tail(s, len)
#define CUT_TAIL(s, len)   cut_stack_tail(s, len)
#define CP_FIN_ACCEPT   1
#define CP_FIN_EOT   2
#define CP_FIN_CANTPOP   3
#define D_puts(msg)
#define D_printf(fmt, arg)
#define SHIFT(v, act, tok, val)   shift(v,act,tok,val)
#define REDUCE(v, act)

Functions

static ID value_to_id _ ((VALUE v))
static long num_to_long _ ((VALUE n))
static ID value_to_id (VALUE v)
static long num_to_long (VALUE n)
static VALUE get_stack_tail _ ((VALUE stack, long len))
static VALUE get_stack_tail (VALUE stack, long len)
static void cut_stack_tail (VALUE stack, long len)
static VALUE racc_cparse _ ((VALUE parser, VALUE arg, VALUE sysdebug))
static VALUE racc_yyparse _ ((VALUE parser, VALUE lexer, VALUE lexmid, VALUE arg, VALUE sysdebug))
static void call_lexer _ ((struct cparse_params *v))
static VALUE lexer_i _ ((RB_BLOCK_CALL_FUNC_ARGLIST(block_args, data)))
static VALUE assert_array _ ((VALUE a))
static VALUE assert_hash _ ((VALUE h))
static VALUE initialize_params _ ((VALUE vparams, VALUE parser, VALUE arg, VALUE lexer, VALUE lexmid))
static void cparse_params_mark _ ((void *ptr))
static void parse_main _ ((struct cparse_params *v, VALUE tok, VALUE val, int resume))
static void extract_user_token _ ((struct cparse_params *v, VALUE block_args, VALUE *tok, VALUE *val))
static void shift _ ((struct cparse_params *v, long act, VALUE tok, VALUE val))
static int reduce _ ((struct cparse_params *v, long act))
static VALUE reduce0 _ ((VALUE block_args, VALUE data, VALUE self))
static VALUE racc_cparse (VALUE parser, VALUE arg, VALUE sysdebug)
static VALUE racc_yyparse (VALUE parser, VALUE lexer, VALUE lexmid, VALUE arg, VALUE sysdebug)
static VALUE lexer_iter (VALUE data)
static void call_lexer (struct cparse_params *v)
static VALUE lexer_i (RB_BLOCK_CALL_FUNC_ARGLIST(block_args, data))
static VALUE assert_array (VALUE a)
static VALUE assert_hash (VALUE h)
static long assert_integer (VALUE n)
static VALUE initialize_params (VALUE vparams, VALUE parser, VALUE arg, VALUE lexer, VALUE lexmid)
static void cparse_params_mark (void *ptr)
static void extract_user_token (struct cparse_params *v, VALUE block_args, VALUE *tok, VALUE *val)
static void parse_main (struct cparse_params *v, VALUE tok, VALUE val, int resume)
static void shift (struct cparse_params *v, long act, VALUE tok, VALUE val)
static int reduce (struct cparse_params *v, long act)
static VALUE reduce0 (VALUE val, VALUE data, VALUE self)
void Init_cparse (void)

Variables

static VALUE RaccBug
static VALUE CparseParams
static ID id_yydebug
static ID id_nexttoken
static ID id_onerror
static ID id_noreduce
static ID id_errstatus
static ID id_d_shift
static ID id_d_reduce
static ID id_d_accept
static ID id_d_read_token
static ID id_d_next_state
static ID id_d_e_pop


Define Documentation

#define AREF ( s,
idx   )     ((0 <= idx && idx < RARRAY_LEN(s)) ? rb_ary_entry(s, idx) : Qnil)

Definition at line 93 of file cparse.c.

Referenced by extract_user_token(), parse_main(), reduce0(), and vm_init_redefined_flag().

#define CP_FIN_ACCEPT   1

Definition at line 176 of file cparse.c.

Referenced by lexer_i(), and parse_main().

#define CP_FIN_CANTPOP   3

Definition at line 178 of file cparse.c.

Referenced by parse_main().

#define CP_FIN_EOT   2

Definition at line 177 of file cparse.c.

Referenced by parse_main().

#define CUT_TAIL ( s,
len   )     cut_stack_tail(s, len)

Definition at line 127 of file cparse.c.

Referenced by reduce0().

#define D_printf ( fmt,
arg   ) 

Definition at line 217 of file cparse.c.

Referenced by parse_main(), and reduce0().

#define D_puts ( msg   ) 

Definition at line 216 of file cparse.c.

Referenced by parse_main(), racc_cparse(), racc_yyparse(), and reduce0().

#define DEFAULT_TOKEN   -1

Definition at line 29 of file cparse.c.

#define ERROR_TOKEN   1

Definition at line 30 of file cparse.c.

Referenced by parse_main().

#define FALSE   0

Definition at line 17 of file cparse.c.

#define FINAL_TOKEN   0

Definition at line 31 of file cparse.c.

Referenced by initialize_params().

#define GET_TAIL ( s,
len   )     get_stack_tail(s, len)

Definition at line 126 of file cparse.c.

Referenced by reduce0().

#define LAST_I (  )     ((RARRAY_LEN(s) > 0) ? rb_ary_entry(s, RARRAY_LEN(s) - 1) : Qnil)

Definition at line 124 of file cparse.c.

Referenced by parse_main(), and reduce0().

 
#define NEW_STACK (  )     rb_ary_new2(STACK_INIT_LEN)

Definition at line 121 of file cparse.c.

Referenced by initialize_params().

#define POP (  )     rb_ary_pop(s)

Definition at line 123 of file cparse.c.

#define PUSH ( s,
 )     rb_ary_store(s, RARRAY_LEN(s), i)

Definition at line 122 of file cparse.c.

#define RACC_VERSION   "1.4.5"

Definition at line 27 of file cparse.c.

Referenced by Init_cparse().

#define REDUCE ( v,
act   ) 

Value:

do {\
    switch (reduce(v,act)) {  \
      case 0: /* normal */    \
        break;                \
      case 1: /* yyerror */   \
        goto user_yyerror;    \
      case 2: /* yyaccept */  \
        D_puts("u accept");   \
        goto accept;          \
      default:                \
        break;                \
    }                         \
} while (0)

Definition at line 438 of file cparse.c.

Referenced by parse_main().

#define SHIFT ( v,
act,
tok,
val   )     shift(v,act,tok,val)

Definition at line 437 of file cparse.c.

Referenced by parse_main().

#define STACK_INIT_LEN   64

Definition at line 120 of file cparse.c.

#define TRUE   1

Definition at line 20 of file cparse.c.

#define vDEFAULT_TOKEN   INT2FIX(DEFAULT_TOKEN)

Definition at line 33 of file cparse.c.

#define vERROR_TOKEN   INT2FIX(ERROR_TOKEN)

Definition at line 34 of file cparse.c.

Referenced by parse_main().

#define vFINAL_TOKEN   INT2FIX(FINAL_TOKEN)

Definition at line 35 of file cparse.c.

Referenced by parse_main().


Function Documentation

static VALUE reduce0 _ ( (VALUE block_args, VALUE data, VALUE self)   )  [static]

static int reduce _ ( (struct cparse_params *v, long act)   )  [static]

static void shift _ ( (struct cparse_params *v, long act, VALUE tok, VALUE val)   )  [static]

static void extract_user_token _ ( (struct cparse_params *v, VALUE block_args, VALUE *tok, VALUE *val)   )  [static]

static void parse_main _ ( (struct cparse_params *v, VALUE tok, VALUE val, int resume)   )  [static]

static void cparse_params_mark _ ( (void *ptr)   )  [static]

static VALUE initialize_params _ ( (VALUE vparams, VALUE parser, VALUE arg, VALUE lexer, VALUE lexmid)   )  [static]

static VALUE assert_hash _ ( (VALUE h)   )  [static]

static VALUE assert_array _ ( (VALUE a)   )  [static]

static VALUE lexer_i _ ( (RB_BLOCK_CALL_FUNC_ARGLIST(block_args, data))   )  [static]

static void call_lexer _ ( (struct cparse_params *v)   )  [static]

static VALUE racc_yyparse _ ( (VALUE parser, VALUE lexer, VALUE lexmid, VALUE arg, VALUE sysdebug)   )  [static]

static VALUE racc_cparse _ ( (VALUE parser, VALUE arg, VALUE sysdebug)   )  [static]

static void cut_stack_tail _ ( (VALUE stack, long len  )  [static]

static long assert_integer _ ( (VALUE n)   )  [inline, static]

static ID value_to_id _ ( (VALUE v)   )  [static]

static VALUE assert_array ( VALUE  a  )  [static]

Definition at line 301 of file cparse.c.

References Check_Type, and T_ARRAY.

Referenced by initialize_params().

static VALUE assert_hash ( VALUE  h  )  [static]

Definition at line 308 of file cparse.c.

References Check_Type, and T_HASH.

Referenced by initialize_params().

static long assert_integer ( VALUE  n  )  [static]

Definition at line 315 of file cparse.c.

References NUM2LONG.

Referenced by initialize_params().

static void call_lexer ( struct cparse_params v  )  [static]

Definition at line 278 of file cparse.c.

References lexer_i(), lexer_iter(), rb_iterate(), and cparse_params::value_v.

Referenced by racc_yyparse().

static void cparse_params_mark ( void *  ptr  )  [static]

Definition at line 384 of file cparse.c.

References cparse_params::action_check, cparse_params::action_default, cparse_params::action_pointer, cparse_params::action_table, cparse_params::goto_check, cparse_params::goto_default, cparse_params::goto_pointer, cparse_params::goto_table, cparse_params::lexer, cparse_params::parser, rb_gc_mark(), cparse_params::reduce_table, cparse_params::retval, cparse_params::state, cparse_params::t, cparse_params::token_table, cparse_params::tstack, cparse_params::value_v, and cparse_params::vstack.

Referenced by racc_cparse(), and racc_yyparse().

static void cut_stack_tail ( VALUE  stack,
long  len 
) [static]

Definition at line 112 of file cparse.c.

References rb_ary_pop().

static void extract_user_token ( struct cparse_params v,
VALUE  block_args,
VALUE *  tok,
VALUE *  val 
) [static]

Definition at line 409 of file cparse.c.

References AREF, cparse_params::lex_is_iterator, cparse_params::lexmid, NIL_P, PRIsVALUE, Qfalse, RARRAY_LEN, rb_eArgError, rb_eTypeError, rb_id2name(), rb_obj_class(), rb_raise(), rb_str_new(), RB_TYPE_P, and T_ARRAY.

Referenced by lexer_i(), and parse_main().

static VALUE get_stack_tail ( VALUE  stack,
long  len 
) [static]

Definition at line 104 of file cparse.c.

References Qnil, RARRAY_LEN, and rb_ary_subseq().

void Init_cparse ( void   ) 

Definition at line 795 of file cparse.c.

References CparseParams, id_d_accept, id_d_e_pop, id_d_next_state, id_d_read_token, id_d_reduce, id_d_shift, id_errstatus, id_nexttoken, id_noreduce, id_onerror, id_yydebug, racc_cparse(), RACC_VERSION, racc_yyparse(), RaccBug, rb_cObject, rb_const_defined(), rb_const_get(), rb_const_get_at(), rb_define_class_under(), rb_define_const(), rb_define_module(), rb_define_private_method(), rb_eRuntimeError, rb_intern, rb_str_new2, and VALUE.

static VALUE initialize_params ( VALUE  vparams,
VALUE  parser,
VALUE  arg,
VALUE  lexer,
VALUE  lexmid 
) [static]

Definition at line 321 of file cparse.c.

References cparse_params::action_check, cparse_params::action_default, cparse_params::action_pointer, cparse_params::action_table, assert_array(), assert_hash(), assert_integer(), Check_Type, cparse_params::curstate, Data_Get_Struct, cparse_params::debug, cparse_params::errstatus, FALSE, cparse_params::fin, FINAL_TOKEN, cparse_params::goto_check, cparse_params::goto_default, cparse_params::goto_pointer, cparse_params::goto_table, id_errstatus, id_yydebug, INT2FIX, cparse_params::lex_is_iterator, cparse_params::lexer, cparse_params::lexmid, LONG2NUM, cparse_params::nerr, NEW_STACK, NIL_P, cparse_params::nt_base, cparse_params::parser, PUSH, Qnil, RaccBug, RARRAY_LEN, rb_ary_entry(), rb_iv_set(), rb_ivar_get(), rb_ivar_set(), rb_raise(), cparse_params::reduce_n, cparse_params::reduce_table, cparse_params::retval, RTEST, cparse_params::shift_n, cparse_params::state, cparse_params::t, T_ARRAY, cparse_params::token_table, TRUE, cparse_params::tstack, cparse_params::use_result_var, value_to_id(), cparse_params::value_v, and cparse_params::vstack.

Referenced by racc_cparse(), and racc_yyparse().

static VALUE lexer_i ( RB_BLOCK_CALL_FUNC_ARGLIST(block_args, data)   )  [static]

Definition at line 285 of file cparse.c.

References CP_FIN_ACCEPT, Data_Get_Struct, extract_user_token(), cparse_params::fin, parse_main(), Qnil, rb_eArgError, rb_iter_break(), rb_raise(), tok, val, and VALUE.

Referenced by call_lexer().

static VALUE lexer_iter ( VALUE  data  )  [static]

Definition at line 268 of file cparse.c.

References Data_Get_Struct, cparse_params::lexer, cparse_params::lexmid, Qnil, and rb_funcall().

Referenced by call_lexer().

static long num_to_long ( VALUE  n  )  [inline, static]

Definition at line 88 of file cparse.c.

References NUM2LONG.

Referenced by parse_main(), reduce(), and reduce0().

static void parse_main ( struct cparse_params v,
VALUE  tok,
VALUE  val,
int  resume 
) [static]

Definition at line 453 of file cparse.c.

References cparse_params::action_check, cparse_params::action_default, cparse_params::action_pointer, cparse_params::action_table, AREF, CP_FIN_ACCEPT, CP_FIN_CANTPOP, CP_FIN_EOT, cparse_params::curstate, D_printf, D_puts, cparse_params::debug, ERROR_TOKEN, cparse_params::errstatus, extract_user_token(), cparse_params::fin, cparse_params::i, id_d_accept, id_d_e_pop, id_d_next_state, id_d_read_token, id_errstatus, id_nexttoken, id_onerror, LAST_I, cparse_params::lex_is_iterator, LONG2NUM, cparse_params::nerr, NIL_P, NUM2LONG, num_to_long(), cparse_params::parser, POP, Qfalse, Qnil, RaccBug, RARRAY_LEN, rb_ary_entry(), rb_eArgError, rb_funcall(), rb_hash_aref(), rb_ivar_set(), rb_raise(), REDUCE, cparse_params::reduce_n, cparse_params::retval, SHIFT, cparse_params::shift_n, cparse_params::state, cparse_params::t, cparse_params::token_table, cparse_params::tstack, VALUE, vERROR_TOKEN, vFINAL_TOKEN, and cparse_params::vstack.

Referenced by lexer_i(), racc_cparse(), and racc_yyparse().

static VALUE racc_cparse ( VALUE  parser,
VALUE  arg,
VALUE  sysdebug 
) [static]

Definition at line 221 of file cparse.c.

References cparse_params_mark(), CparseParams, D_puts, Data_Make_Struct, FALSE, initialize_params(), cparse_params::lex_is_iterator, parse_main(), Qnil, cparse_params::retval, RTEST, cparse_params::sys_debug, and VALUE.

Referenced by Init_cparse().

static VALUE racc_yyparse ( VALUE  parser,
VALUE  lexer,
VALUE  lexmid,
VALUE  arg,
VALUE  sysdebug 
) [static]

Definition at line 238 of file cparse.c.

References call_lexer(), cparse_params_mark(), CparseParams, D_puts, Data_Make_Struct, cparse_params::fin, initialize_params(), cparse_params::lex_is_iterator, cparse_params::lexmid, parse_main(), Qnil, rb_eArgError, rb_id2name(), rb_raise(), cparse_params::retval, RTEST, cparse_params::sys_debug, TRUE, and VALUE.

Referenced by Init_cparse().

static int reduce ( struct cparse_params v,
long  act 
) [static]

Definition at line 675 of file cparse.c.

References cparse_params::errstatus, id_errstatus, NUM2INT, num_to_long(), cparse_params::parser, rb_catch(), rb_ivar_get(), reduce0(), cparse_params::ruleno, VALUE, and cparse_params::value_v.

static VALUE reduce0 ( VALUE  val,
VALUE  data,
VALUE  self 
) [static]

Definition at line 685 of file cparse.c.

References AREF, cparse_params::curstate, CUT_TAIL, D_printf, D_puts, Data_Get_Struct, cparse_params::debug, GET_TAIL, cparse_params::goto_check, cparse_params::goto_default, cparse_params::goto_pointer, cparse_params::goto_table, cparse_params::i, id_d_reduce, id_noreduce, INT2FIX, LAST_I, len, LONG2NUM, NIL_P, cparse_params::nt_base, NUM2LONG, num_to_long(), cparse_params::parser, PUSH, Qnil, Qundef, RaccBug, RARRAY_LEN, rb_ary_entry(), rb_ary_new(), rb_funcall(), rb_raise(), cparse_params::reduce_table, cparse_params::ruleno, cparse_params::state, cparse_params::tstack, cparse_params::use_result_var, VALUE, value_to_id(), and cparse_params::vstack.

Referenced by reduce().

static void shift ( struct cparse_params v,
long  act,
VALUE  tok,
VALUE  val 
) [static]

Definition at line 662 of file cparse.c.

References cparse_params::curstate, cparse_params::debug, id_d_shift, LONG2NUM, cparse_params::parser, PUSH, rb_funcall(), cparse_params::state, cparse_params::tstack, and cparse_params::vstack.

Referenced by bary_divmod_normal(), big2str_karatsuba(), nkf_each_char_to_hex(), rb_ary_modify(), rb_big_aref(), rb_big_lshift(), rb_big_rshift(), ruby_brace_expand(), and VpToString().

static ID value_to_id ( VALUE  v  )  [static]

Definition at line 79 of file cparse.c.

References rb_eTypeError, rb_raise(), SYM2ID, and SYMBOL_P.

Referenced by initialize_params(), and reduce0().


Variable Documentation

VALUE CparseParams [static]

Definition at line 42 of file cparse.c.

Referenced by Init_cparse(), racc_cparse(), and racc_yyparse().

ID id_d_accept [static]

Definition at line 52 of file cparse.c.

Referenced by Init_cparse(), and parse_main().

ID id_d_e_pop [static]

Definition at line 55 of file cparse.c.

Referenced by Init_cparse(), and parse_main().

ID id_d_next_state [static]

Definition at line 54 of file cparse.c.

Referenced by Init_cparse(), and parse_main().

ID id_d_read_token [static]

Definition at line 53 of file cparse.c.

Referenced by Init_cparse(), and parse_main().

ID id_d_reduce [static]

Definition at line 51 of file cparse.c.

Referenced by Init_cparse(), and reduce0().

ID id_d_shift [static]

Definition at line 50 of file cparse.c.

Referenced by Init_cparse(), and shift().

ID id_errstatus [static]

Definition at line 48 of file cparse.c.

Referenced by Init_cparse(), initialize_params(), parse_main(), and reduce().

ID id_nexttoken [static]

Definition at line 45 of file cparse.c.

Referenced by Init_cparse(), and parse_main().

ID id_noreduce [static]

Definition at line 47 of file cparse.c.

Referenced by Init_cparse(), and reduce0().

ID id_onerror [static]

Definition at line 46 of file cparse.c.

Referenced by Init_cparse(), and parse_main().

ID id_yydebug [static]

Definition at line 44 of file cparse.c.

Referenced by Init_cparse(), and initialize_params().

VALUE RaccBug [static]

Definition at line 41 of file cparse.c.

Referenced by Init_cparse(), initialize_params(), parse_main(), and reduce0().


Generated on 19 Jul 2016 for Ruby by  doxygen 1.4.7