PageRenderTime 67ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/opensource.apple.com/source/ruby/ruby-75/ruby/parse.y

#
Happy | 3230 lines | 2993 code | 237 blank | 0 comment | 0 complexity | cf226a1b5f713d231e7eb29d1960b5e5 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-2.0, BSD-3-Clause, GPL-3.0, MPL-2.0, LGPL-2.0, LGPL-2.1, CC-BY-SA-3.0, IPL-1.0, ISC, AGPL-1.0, AGPL-3.0, JSON, Apache-2.0, 0BSD

Large files files are truncated, but you can click here to view the full file

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>parse.y</title>
  6. <style type="text/css">
  7. .enscript-comment { font-style: italic; color: rgb(178,34,34); }
  8. .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
  9. .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
  10. .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
  11. .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
  12. .enscript-string { font-weight: bold; color: rgb(188,143,143); }
  13. .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
  14. .enscript-type { font-weight: bold; color: rgb(34,139,34); }
  15. .enscript-highlight { text-decoration: underline; color: 0; }
  16. </style>
  17. </head>
  18. <body id="top">
  19. <h1 style="margin:8px;" id="f1">parse.y&nbsp;&nbsp;&nbsp;<span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
  20. <hr/>
  21. <div></div>
  22. <pre>
  23. /**********************************************************************
  24. parse.y -
  25. $Author: knu $
  26. $Date: 2008-06-06 19:39:57 +0900 (Fri, 06 Jun 2008) $
  27. created at: Fri May 28 18:02:42 JST 1993
  28. Copyright (C) 1993-2003 Yukihiro Matsumoto
  29. **********************************************************************/
  30. %{
  31. #define YYDEBUG 1
  32. #define YYERROR_VERBOSE 1
  33. #ifndef YYSTACK_USE_ALLOCA
  34. #define YYSTACK_USE_ALLOCA 0
  35. #endif
  36. #include &quot;ruby.h&quot;
  37. #include &quot;env.h&quot;
  38. #include &quot;intern.h&quot;
  39. #include &quot;node.h&quot;
  40. #include &quot;st.h&quot;
  41. #include &lt;stdio.h&gt;
  42. #include &lt;errno.h&gt;
  43. #include &lt;ctype.h&gt;
  44. #define YYMALLOC rb_parser_malloc
  45. #define YYREALLOC rb_parser_realloc
  46. #define YYCALLOC rb_parser_calloc
  47. #define YYFREE rb_parser_free
  48. #define malloc YYMALLOC
  49. #define realloc YYREALLOC
  50. #define calloc YYCALLOC
  51. #define free YYFREE
  52. static void *rb_parser_malloc _((size_t));
  53. static void *rb_parser_realloc _((void *, size_t));
  54. static void *rb_parser_calloc _((size_t, size_t));
  55. static void rb_parser_free _((void *));
  56. #define yyparse ruby_yyparse
  57. #define yylex ruby_yylex
  58. #define yyerror ruby_yyerror
  59. #define yylval ruby_yylval
  60. #define yychar ruby_yychar
  61. #define yydebug ruby_yydebug
  62. #define ID_SCOPE_SHIFT 3
  63. #define ID_SCOPE_MASK 0x07
  64. #define ID_LOCAL 0x01
  65. #define ID_INSTANCE 0x02
  66. #define ID_GLOBAL 0x03
  67. #define ID_ATTRSET 0x04
  68. #define ID_CONST 0x05
  69. #define ID_CLASS 0x06
  70. #define ID_JUNK 0x07
  71. #define ID_INTERNAL ID_JUNK
  72. #define is_notop_id(id) ((id)&gt;tLAST_TOKEN)
  73. #define is_local_id(id) (is_notop_id(id)&amp;&amp;((id)&amp;ID_SCOPE_MASK)==ID_LOCAL)
  74. #define is_global_id(id) (is_notop_id(id)&amp;&amp;((id)&amp;ID_SCOPE_MASK)==ID_GLOBAL)
  75. #define is_instance_id(id) (is_notop_id(id)&amp;&amp;((id)&amp;ID_SCOPE_MASK)==ID_INSTANCE)
  76. #define is_attrset_id(id) (is_notop_id(id)&amp;&amp;((id)&amp;ID_SCOPE_MASK)==ID_ATTRSET)
  77. #define is_const_id(id) (is_notop_id(id)&amp;&amp;((id)&amp;ID_SCOPE_MASK)==ID_CONST)
  78. #define is_class_id(id) (is_notop_id(id)&amp;&amp;((id)&amp;ID_SCOPE_MASK)==ID_CLASS)
  79. #define is_junk_id(id) (is_notop_id(id)&amp;&amp;((id)&amp;ID_SCOPE_MASK)==ID_JUNK)
  80. #define is_asgn_or_id(id) ((is_notop_id(id)) &amp;&amp; \
  81. (((id)&amp;ID_SCOPE_MASK) == ID_GLOBAL || \
  82. ((id)&amp;ID_SCOPE_MASK) == ID_INSTANCE || \
  83. ((id)&amp;ID_SCOPE_MASK) == ID_CLASS))
  84. NODE *ruby_eval_tree_begin = 0;
  85. NODE *ruby_eval_tree = 0;
  86. char *ruby_sourcefile; /* current source file */
  87. int ruby_sourceline; /* current line no. */
  88. static int yylex();
  89. static int yyerror();
  90. static enum lex_state {
  91. EXPR_BEG, /* ignore newline, +/- is a sign. */
  92. EXPR_END, /* newline significant, +/- is an operator. */
  93. EXPR_ARG, /* newline significant, +/- is an operator. */
  94. EXPR_CMDARG, /* newline significant, +/- is an operator. */
  95. EXPR_ENDARG, /* newline significant, +/- is an operator. */
  96. EXPR_MID, /* newline significant, +/- is an operator. */
  97. EXPR_FNAME, /* ignore newline, no reserved words. */
  98. EXPR_DOT, /* right after `.' or `::', no reserved words. */
  99. EXPR_CLASS, /* immediate after `class', no here document. */
  100. } lex_state;
  101. static NODE *lex_strterm;
  102. #ifdef HAVE_LONG_LONG
  103. typedef unsigned LONG_LONG stack_type;
  104. #else
  105. typedef unsigned long stack_type;
  106. #endif
  107. #define BITSTACK_PUSH(stack, n) (stack = (stack&lt;&lt;1)|((n)&amp;1))
  108. #define BITSTACK_POP(stack) (stack &gt;&gt;= 1)
  109. #define BITSTACK_LEXPOP(stack) (stack = (stack &gt;&gt; 1) | (stack &amp; 1))
  110. #define BITSTACK_SET_P(stack) (stack&amp;1)
  111. static stack_type cond_stack = 0;
  112. #define COND_PUSH(n) BITSTACK_PUSH(cond_stack, n)
  113. #define COND_POP() BITSTACK_POP(cond_stack)
  114. #define COND_LEXPOP() BITSTACK_LEXPOP(cond_stack)
  115. #define COND_P() BITSTACK_SET_P(cond_stack)
  116. static stack_type cmdarg_stack = 0;
  117. #define CMDARG_PUSH(n) BITSTACK_PUSH(cmdarg_stack, n)
  118. #define CMDARG_POP() BITSTACK_POP(cmdarg_stack)
  119. #define CMDARG_LEXPOP() BITSTACK_LEXPOP(cmdarg_stack)
  120. #define CMDARG_P() BITSTACK_SET_P(cmdarg_stack)
  121. static int class_nest = 0;
  122. static int in_single = 0;
  123. static int in_def = 0;
  124. static int compile_for_eval = 0;
  125. static ID cur_mid = 0;
  126. static int command_start = Qtrue;
  127. static NODE *cond();
  128. static NODE *logop();
  129. static int cond_negative();
  130. static NODE *newline_node();
  131. static void fixpos();
  132. static int value_expr0();
  133. static void void_expr0();
  134. static void void_stmts();
  135. static NODE *remove_begin();
  136. #define value_expr(node) value_expr0((node) = remove_begin(node))
  137. #define void_expr(node) void_expr0((node) = remove_begin(node))
  138. static NODE *block_append();
  139. static NODE *list_append();
  140. static NODE *list_concat();
  141. static NODE *arg_concat();
  142. static NODE *arg_prepend();
  143. static NODE *literal_concat();
  144. static NODE *new_evstr();
  145. static NODE *evstr2dstr();
  146. static NODE *call_op();
  147. static int in_defined = 0;
  148. static NODE *negate_lit();
  149. static NODE *ret_args();
  150. static NODE *arg_blk_pass();
  151. static NODE *new_call();
  152. static NODE *new_fcall();
  153. static NODE *new_super();
  154. static NODE *new_yield();
  155. static NODE *gettable();
  156. static NODE *assignable();
  157. static NODE *aryset();
  158. static NODE *attrset();
  159. static void rb_backref_error();
  160. static NODE *node_assign();
  161. static NODE *match_gen();
  162. static void local_push();
  163. static void local_pop();
  164. static int local_append();
  165. static int local_cnt();
  166. static int local_id();
  167. static ID *local_tbl();
  168. static ID internal_id();
  169. static struct RVarmap *dyna_push();
  170. static void dyna_pop();
  171. static int dyna_in_block();
  172. static NODE *dyna_init();
  173. static void top_local_init();
  174. static void top_local_setup();
  175. #define RE_OPTION_ONCE 0x80
  176. #define NODE_STRTERM NODE_ZARRAY /* nothing to gc */
  177. #define NODE_HEREDOC NODE_ARRAY /* 1, 3 to gc */
  178. #define SIGN_EXTEND(x,n) (((1&lt;&lt;(n)-1)^((x)&amp;~(~0&lt;&lt;(n))))-(1&lt;&lt;(n)-1))
  179. #define nd_func u1.id
  180. #if SIZEOF_SHORT == 2
  181. #define nd_term(node) ((signed short)(node)-&gt;u2.id)
  182. #else
  183. #define nd_term(node) SIGN_EXTEND((node)-&gt;u2.id, CHAR_BIT*2)
  184. #endif
  185. #define nd_paren(node) (char)((node)-&gt;u2.id &gt;&gt; CHAR_BIT*2)
  186. #define nd_nest u3.id
  187. #define NEW_BLOCK_VAR(b, v) NEW_NODE(NODE_BLOCK_PASS, 0, b, v)
  188. /* Older versions of Yacc set YYMAXDEPTH to a very low value by default (150,
  189. for instance). This is too low for Ruby to parse some files, such as
  190. date/format.rb, therefore bump the value up to at least Bison's default. */
  191. #ifdef OLD_YACC
  192. #ifndef YYMAXDEPTH
  193. #define YYMAXDEPTH 10000
  194. #endif
  195. #endif
  196. %}
  197. %union {
  198. NODE *node;
  199. ID id;
  200. int num;
  201. struct RVarmap *vars;
  202. }
  203. %token kCLASS
  204. kMODULE
  205. kDEF
  206. kUNDEF
  207. kBEGIN
  208. kRESCUE
  209. kENSURE
  210. kEND
  211. kIF
  212. kUNLESS
  213. kTHEN
  214. kELSIF
  215. kELSE
  216. kCASE
  217. kWHEN
  218. kWHILE
  219. kUNTIL
  220. kFOR
  221. kBREAK
  222. kNEXT
  223. kREDO
  224. kRETRY
  225. kIN
  226. kDO
  227. kDO_COND
  228. kDO_BLOCK
  229. kRETURN
  230. kYIELD
  231. kSUPER
  232. kSELF
  233. kNIL
  234. kTRUE
  235. kFALSE
  236. kAND
  237. kOR
  238. kNOT
  239. kIF_MOD
  240. kUNLESS_MOD
  241. kWHILE_MOD
  242. kUNTIL_MOD
  243. kRESCUE_MOD
  244. kALIAS
  245. kDEFINED
  246. klBEGIN
  247. klEND
  248. k__LINE__
  249. k__FILE__
  250. %token &lt;id&gt; tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR
  251. %token &lt;node&gt; tINTEGER tFLOAT tSTRING_CONTENT
  252. %token &lt;node&gt; tNTH_REF tBACK_REF
  253. %token &lt;num&gt; tREGEXP_END
  254. %type &lt;node&gt; singleton strings string string1 xstring regexp
  255. %type &lt;node&gt; string_contents xstring_contents string_content
  256. %type &lt;node&gt; words qwords word_list qword_list word
  257. %type &lt;node&gt; literal numeric dsym cpath
  258. %type &lt;node&gt; bodystmt compstmt stmts stmt expr arg primary command command_call method_call
  259. %type &lt;node&gt; expr_value arg_value primary_value
  260. %type &lt;node&gt; if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
  261. %type &lt;node&gt; args when_args call_args call_args2 open_args paren_args opt_paren_args
  262. %type &lt;node&gt; command_args aref_args opt_block_arg block_arg var_ref var_lhs
  263. %type &lt;node&gt; mrhs superclass block_call block_command
  264. %type &lt;node&gt; f_arglist f_args f_optarg f_opt f_rest_arg f_block_arg opt_f_block_arg
  265. %type &lt;node&gt; assoc_list assocs assoc undef_list backref string_dvar
  266. %type &lt;node&gt; for_var block_var opt_block_var block_par
  267. %type &lt;node&gt; brace_block cmd_brace_block do_block lhs none fitem
  268. %type &lt;node&gt; mlhs mlhs_head mlhs_basic mlhs_entry mlhs_item mlhs_node
  269. %type &lt;id&gt; fsym variable sym symbol operation operation2 operation3
  270. %type &lt;id&gt; cname fname op
  271. %type &lt;num&gt; f_norm_arg f_arg
  272. %token tUPLUS /* unary+ */
  273. %token tUMINUS /* unary- */
  274. %token tPOW /* ** */
  275. %token tCMP /* &lt;=&gt; */
  276. %token tEQ /* == */
  277. %token tEQQ /* === */
  278. %token tNEQ /* != */
  279. %token tGEQ /* &gt;= */
  280. %token tLEQ /* &lt;= */
  281. %token tANDOP tOROP /* &amp;&amp; and || */
  282. %token tMATCH tNMATCH /* =~ and !~ */
  283. %token tDOT2 tDOT3 /* .. and ... */
  284. %token tAREF tASET /* [] and []= */
  285. %token tLSHFT tRSHFT /* &lt;&lt; and &gt;&gt; */
  286. %token tCOLON2 /* :: */
  287. %token tCOLON3 /* :: at EXPR_BEG */
  288. %token &lt;id&gt; tOP_ASGN /* +=, -= etc. */
  289. %token tASSOC /* =&gt; */
  290. %token tLPAREN /* ( */
  291. %token tLPAREN_ARG /* ( */
  292. %token tRPAREN /* ) */
  293. %token tLBRACK /* [ */
  294. %token tLBRACE /* { */
  295. %token tLBRACE_ARG /* { */
  296. %token tSTAR /* * */
  297. %token tAMPER /* &amp; */
  298. %token tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tWORDS_BEG tQWORDS_BEG
  299. %token tSTRING_DBEG tSTRING_DVAR tSTRING_END
  300. /*
  301. * precedence table
  302. */
  303. %nonassoc tLOWEST
  304. %nonassoc tLBRACE_ARG
  305. %nonassoc kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD
  306. %left kOR kAND
  307. %right kNOT
  308. %nonassoc kDEFINED
  309. %right '=' tOP_ASGN
  310. %left kRESCUE_MOD
  311. %right '?' ':'
  312. %nonassoc tDOT2 tDOT3
  313. %left tOROP
  314. %left tANDOP
  315. %nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
  316. %left '&gt;' tGEQ '&lt;' tLEQ
  317. %left '|' '^'
  318. %left '&amp;'
  319. %left tLSHFT tRSHFT
  320. %left '+' '-'
  321. %left '*' '/' '%'
  322. %right tUMINUS_NUM tUMINUS
  323. %right tPOW
  324. %right '!' '~' tUPLUS
  325. %token tLAST_TOKEN
  326. %%
  327. program : {
  328. lex_state = EXPR_BEG;
  329. top_local_init();
  330. if (ruby_class == rb_cObject) class_nest = 0;
  331. else class_nest = 1;
  332. }
  333. compstmt
  334. {
  335. if ($2 &amp;&amp; !compile_for_eval) {
  336. /* last expression should not be void */
  337. if (nd_type($2) != NODE_BLOCK) void_expr($2);
  338. else {
  339. NODE *node = $2;
  340. while (node-&gt;nd_next) {
  341. node = node-&gt;nd_next;
  342. }
  343. void_expr(node-&gt;nd_head);
  344. }
  345. }
  346. ruby_eval_tree = block_append(ruby_eval_tree, $2);
  347. top_local_setup();
  348. class_nest = 0;
  349. }
  350. ;
  351. bodystmt : compstmt
  352. opt_rescue
  353. opt_else
  354. opt_ensure
  355. {
  356. $$ = $1;
  357. if ($2) {
  358. $$ = NEW_RESCUE($1, $2, $3);
  359. }
  360. else if ($3) {
  361. rb_warn(&quot;else without rescue is useless&quot;);
  362. $$ = block_append($$, $3);
  363. }
  364. if ($4) {
  365. $$ = NEW_ENSURE($$, $4);
  366. }
  367. fixpos($$, $1);
  368. }
  369. ;
  370. compstmt : stmts opt_terms
  371. {
  372. void_stmts($1);
  373. $$ = $1;
  374. }
  375. ;
  376. stmts : none
  377. | stmt
  378. {
  379. $$ = newline_node($1);
  380. }
  381. | stmts terms stmt
  382. {
  383. $$ = block_append($1, newline_node($3));
  384. }
  385. | error stmt
  386. {
  387. $$ = remove_begin($2);
  388. }
  389. ;
  390. stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
  391. {
  392. $$ = NEW_ALIAS($2, $4);
  393. }
  394. | kALIAS tGVAR tGVAR
  395. {
  396. $$ = NEW_VALIAS($2, $3);
  397. }
  398. | kALIAS tGVAR tBACK_REF
  399. {
  400. char buf[3];
  401. sprintf(buf, &quot;$%c&quot;, (char)$3-&gt;nd_nth);
  402. $$ = NEW_VALIAS($2, rb_intern(buf));
  403. }
  404. | kALIAS tGVAR tNTH_REF
  405. {
  406. yyerror(&quot;can't make alias for the number variables&quot;);
  407. $$ = 0;
  408. }
  409. | kUNDEF undef_list
  410. {
  411. $$ = $2;
  412. }
  413. | stmt kIF_MOD expr_value
  414. {
  415. $$ = NEW_IF(cond($3), remove_begin($1), 0);
  416. fixpos($$, $3);
  417. if (cond_negative(&amp;$$-&gt;nd_cond)) {
  418. $$-&gt;nd_else = $$-&gt;nd_body;
  419. $$-&gt;nd_body = 0;
  420. }
  421. }
  422. | stmt kUNLESS_MOD expr_value
  423. {
  424. $$ = NEW_UNLESS(cond($3), remove_begin($1), 0);
  425. fixpos($$, $3);
  426. if (cond_negative(&amp;$$-&gt;nd_cond)) {
  427. $$-&gt;nd_body = $$-&gt;nd_else;
  428. $$-&gt;nd_else = 0;
  429. }
  430. }
  431. | stmt kWHILE_MOD expr_value
  432. {
  433. if ($1 &amp;&amp; nd_type($1) == NODE_BEGIN) {
  434. $$ = NEW_WHILE(cond($3), $1-&gt;nd_body, 0);
  435. }
  436. else {
  437. $$ = NEW_WHILE(cond($3), $1, 1);
  438. }
  439. if (cond_negative(&amp;$$-&gt;nd_cond)) {
  440. nd_set_type($$, NODE_UNTIL);
  441. }
  442. }
  443. | stmt kUNTIL_MOD expr_value
  444. {
  445. if ($1 &amp;&amp; nd_type($1) == NODE_BEGIN) {
  446. $$ = NEW_UNTIL(cond($3), $1-&gt;nd_body, 0);
  447. }
  448. else {
  449. $$ = NEW_UNTIL(cond($3), $1, 1);
  450. }
  451. if (cond_negative(&amp;$$-&gt;nd_cond)) {
  452. nd_set_type($$, NODE_WHILE);
  453. }
  454. }
  455. | stmt kRESCUE_MOD stmt
  456. {
  457. NODE *resq = NEW_RESBODY(0, remove_begin($3), 0);
  458. $$ = NEW_RESCUE(remove_begin($1), resq, 0);
  459. }
  460. | klBEGIN
  461. {
  462. if (in_def || in_single) {
  463. yyerror(&quot;BEGIN in method&quot;);
  464. }
  465. local_push(0);
  466. }
  467. '{' compstmt '}'
  468. {
  469. ruby_eval_tree_begin = block_append(ruby_eval_tree_begin,
  470. NEW_PREEXE($4));
  471. local_pop();
  472. $$ = 0;
  473. }
  474. | klEND '{' compstmt '}'
  475. {
  476. if (in_def || in_single) {
  477. rb_warn(&quot;END in method; use at_exit&quot;);
  478. }
  479. $$ = NEW_ITER(0, NEW_POSTEXE(), $3);
  480. }
  481. | lhs '=' command_call
  482. {
  483. $$ = node_assign($1, $3);
  484. }
  485. | mlhs '=' command_call
  486. {
  487. value_expr($3);
  488. $1-&gt;nd_value = ($1-&gt;nd_head) ? NEW_TO_ARY($3) : NEW_ARRAY($3);
  489. $$ = $1;
  490. }
  491. | var_lhs tOP_ASGN command_call
  492. {
  493. value_expr($3);
  494. if ($1) {
  495. ID vid = $1-&gt;nd_vid;
  496. if ($2 == tOROP) {
  497. $1-&gt;nd_value = $3;
  498. $$ = NEW_OP_ASGN_OR(gettable(vid), $1);
  499. if (is_asgn_or_id(vid)) {
  500. $$-&gt;nd_aid = vid;
  501. }
  502. }
  503. else if ($2 == tANDOP) {
  504. $1-&gt;nd_value = $3;
  505. $$ = NEW_OP_ASGN_AND(gettable(vid), $1);
  506. }
  507. else {
  508. $$ = $1;
  509. $$-&gt;nd_value = call_op(gettable(vid),$2,1,$3);
  510. }
  511. }
  512. else {
  513. $$ = 0;
  514. }
  515. }
  516. | primary_value '[' aref_args ']' tOP_ASGN command_call
  517. {
  518. NODE *args;
  519. value_expr($6);
  520. if (!$3) $3 = NEW_ZARRAY();
  521. args = arg_concat($6, $3);
  522. if ($5 == tOROP) {
  523. $5 = 0;
  524. }
  525. else if ($5 == tANDOP) {
  526. $5 = 1;
  527. }
  528. $$ = NEW_OP_ASGN1($1, $5, args);
  529. fixpos($$, $1);
  530. }
  531. | primary_value '.' tIDENTIFIER tOP_ASGN command_call
  532. {
  533. value_expr($5);
  534. if ($4 == tOROP) {
  535. $4 = 0;
  536. }
  537. else if ($4 == tANDOP) {
  538. $4 = 1;
  539. }
  540. $$ = NEW_OP_ASGN2($1, $3, $4, $5);
  541. fixpos($$, $1);
  542. }
  543. | primary_value '.' tCONSTANT tOP_ASGN command_call
  544. {
  545. value_expr($5);
  546. if ($4 == tOROP) {
  547. $4 = 0;
  548. }
  549. else if ($4 == tANDOP) {
  550. $4 = 1;
  551. }
  552. $$ = NEW_OP_ASGN2($1, $3, $4, $5);
  553. fixpos($$, $1);
  554. }
  555. | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
  556. {
  557. value_expr($5);
  558. if ($4 == tOROP) {
  559. $4 = 0;
  560. }
  561. else if ($4 == tANDOP) {
  562. $4 = 1;
  563. }
  564. $$ = NEW_OP_ASGN2($1, $3, $4, $5);
  565. fixpos($$, $1);
  566. }
  567. | backref tOP_ASGN command_call
  568. {
  569. rb_backref_error($1);
  570. $$ = 0;
  571. }
  572. | lhs '=' mrhs
  573. {
  574. $$ = node_assign($1, NEW_SVALUE($3));
  575. }
  576. | mlhs '=' arg_value
  577. {
  578. $1-&gt;nd_value = ($1-&gt;nd_head) ? NEW_TO_ARY($3) : NEW_ARRAY($3);
  579. $$ = $1;
  580. }
  581. | mlhs '=' mrhs
  582. {
  583. $1-&gt;nd_value = $3;
  584. $$ = $1;
  585. }
  586. | expr
  587. ;
  588. expr : command_call
  589. | expr kAND expr
  590. {
  591. $$ = logop(NODE_AND, $1, $3);
  592. }
  593. | expr kOR expr
  594. {
  595. $$ = logop(NODE_OR, $1, $3);
  596. }
  597. | kNOT expr
  598. {
  599. $$ = NEW_NOT(cond($2));
  600. }
  601. | '!' command_call
  602. {
  603. $$ = NEW_NOT(cond($2));
  604. }
  605. | arg
  606. ;
  607. expr_value : expr
  608. {
  609. value_expr($$);
  610. $$ = $1;
  611. }
  612. ;
  613. command_call : command
  614. | block_command
  615. | kRETURN call_args
  616. {
  617. $$ = NEW_RETURN(ret_args($2));
  618. }
  619. | kBREAK call_args
  620. {
  621. $$ = NEW_BREAK(ret_args($2));
  622. }
  623. | kNEXT call_args
  624. {
  625. $$ = NEW_NEXT(ret_args($2));
  626. }
  627. ;
  628. block_command : block_call
  629. | block_call '.' operation2 command_args
  630. {
  631. $$ = new_call($1, $3, $4);
  632. }
  633. | block_call tCOLON2 operation2 command_args
  634. {
  635. $$ = new_call($1, $3, $4);
  636. }
  637. ;
  638. cmd_brace_block : tLBRACE_ARG
  639. {
  640. $&lt;vars&gt;$ = dyna_push();
  641. $&lt;num&gt;1 = ruby_sourceline;
  642. }
  643. opt_block_var {$&lt;vars&gt;$ = ruby_dyna_vars;}
  644. compstmt
  645. '}'
  646. {
  647. $$ = NEW_ITER($3, 0, dyna_init($5, $&lt;vars&gt;4));
  648. nd_set_line($$, $&lt;num&gt;1);
  649. dyna_pop($&lt;vars&gt;2);
  650. }
  651. ;
  652. command : operation command_args %prec tLOWEST
  653. {
  654. $$ = new_fcall($1, $2);
  655. fixpos($$, $2);
  656. }
  657. | operation command_args cmd_brace_block
  658. {
  659. $$ = new_fcall($1, $2);
  660. if ($3) {
  661. if (nd_type($$) == NODE_BLOCK_PASS) {
  662. rb_compile_error(&quot;both block arg and actual block given&quot;);
  663. }
  664. $3-&gt;nd_iter = $$;
  665. $$ = $3;
  666. }
  667. fixpos($$, $2);
  668. }
  669. | primary_value '.' operation2 command_args %prec tLOWEST
  670. {
  671. $$ = new_call($1, $3, $4);
  672. fixpos($$, $1);
  673. }
  674. | primary_value '.' operation2 command_args cmd_brace_block
  675. {
  676. $$ = new_call($1, $3, $4);
  677. if ($5) {
  678. if (nd_type($$) == NODE_BLOCK_PASS) {
  679. rb_compile_error(&quot;both block arg and actual block given&quot;);
  680. }
  681. $5-&gt;nd_iter = $$;
  682. $$ = $5;
  683. }
  684. fixpos($$, $1);
  685. }
  686. | primary_value tCOLON2 operation2 command_args %prec tLOWEST
  687. {
  688. $$ = new_call($1, $3, $4);
  689. fixpos($$, $1);
  690. }
  691. | primary_value tCOLON2 operation2 command_args cmd_brace_block
  692. {
  693. $$ = new_call($1, $3, $4);
  694. if ($5) {
  695. if (nd_type($$) == NODE_BLOCK_PASS) {
  696. rb_compile_error(&quot;both block arg and actual block given&quot;);
  697. }
  698. $5-&gt;nd_iter = $$;
  699. $$ = $5;
  700. }
  701. fixpos($$, $1);
  702. }
  703. | kSUPER command_args
  704. {
  705. $$ = new_super($2);
  706. fixpos($$, $2);
  707. }
  708. | kYIELD command_args
  709. {
  710. $$ = new_yield($2);
  711. fixpos($$, $2);
  712. }
  713. ;
  714. mlhs : mlhs_basic
  715. | tLPAREN mlhs_entry ')'
  716. {
  717. $$ = $2;
  718. }
  719. ;
  720. mlhs_entry : mlhs_basic
  721. | tLPAREN mlhs_entry ')'
  722. {
  723. $$ = NEW_MASGN(NEW_LIST($2), 0);
  724. }
  725. ;
  726. mlhs_basic : mlhs_head
  727. {
  728. $$ = NEW_MASGN($1, 0);
  729. }
  730. | mlhs_head mlhs_item
  731. {
  732. $$ = NEW_MASGN(list_append($1,$2), 0);
  733. }
  734. | mlhs_head tSTAR mlhs_node
  735. {
  736. $$ = NEW_MASGN($1, $3);
  737. }
  738. | mlhs_head tSTAR
  739. {
  740. $$ = NEW_MASGN($1, -1);
  741. }
  742. | tSTAR mlhs_node
  743. {
  744. $$ = NEW_MASGN(0, $2);
  745. }
  746. | tSTAR
  747. {
  748. $$ = NEW_MASGN(0, -1);
  749. }
  750. ;
  751. mlhs_item : mlhs_node
  752. | tLPAREN mlhs_entry ')'
  753. {
  754. $$ = $2;
  755. }
  756. ;
  757. mlhs_head : mlhs_item ','
  758. {
  759. $$ = NEW_LIST($1);
  760. }
  761. | mlhs_head mlhs_item ','
  762. {
  763. $$ = list_append($1, $2);
  764. }
  765. ;
  766. mlhs_node : variable
  767. {
  768. $$ = assignable($1, 0);
  769. }
  770. | primary_value '[' aref_args ']'
  771. {
  772. $$ = aryset($1, $3);
  773. }
  774. | primary_value '.' tIDENTIFIER
  775. {
  776. $$ = attrset($1, $3);
  777. }
  778. | primary_value tCOLON2 tIDENTIFIER
  779. {
  780. $$ = attrset($1, $3);
  781. }
  782. | primary_value '.' tCONSTANT
  783. {
  784. $$ = attrset($1, $3);
  785. }
  786. | primary_value tCOLON2 tCONSTANT
  787. {
  788. if (in_def || in_single)
  789. yyerror(&quot;dynamic constant assignment&quot;);
  790. $$ = NEW_CDECL(0, 0, NEW_COLON2($1, $3));
  791. }
  792. | tCOLON3 tCONSTANT
  793. {
  794. if (in_def || in_single)
  795. yyerror(&quot;dynamic constant assignment&quot;);
  796. $$ = NEW_CDECL(0, 0, NEW_COLON3($2));
  797. }
  798. | backref
  799. {
  800. rb_backref_error($1);
  801. $$ = 0;
  802. }
  803. ;
  804. lhs : variable
  805. {
  806. $$ = assignable($1, 0);
  807. }
  808. | primary_value '[' aref_args ']'
  809. {
  810. $$ = aryset($1, $3);
  811. }
  812. | primary_value '.' tIDENTIFIER
  813. {
  814. $$ = attrset($1, $3);
  815. }
  816. | primary_value tCOLON2 tIDENTIFIER
  817. {
  818. $$ = attrset($1, $3);
  819. }
  820. | primary_value '.' tCONSTANT
  821. {
  822. $$ = attrset($1, $3);
  823. }
  824. | primary_value tCOLON2 tCONSTANT
  825. {
  826. if (in_def || in_single)
  827. yyerror(&quot;dynamic constant assignment&quot;);
  828. $$ = NEW_CDECL(0, 0, NEW_COLON2($1, $3));
  829. }
  830. | tCOLON3 tCONSTANT
  831. {
  832. if (in_def || in_single)
  833. yyerror(&quot;dynamic constant assignment&quot;);
  834. $$ = NEW_CDECL(0, 0, NEW_COLON3($2));
  835. }
  836. | backref
  837. {
  838. rb_backref_error($1);
  839. $$ = 0;
  840. }
  841. ;
  842. cname : tIDENTIFIER
  843. {
  844. yyerror(&quot;class/module name must be CONSTANT&quot;);
  845. }
  846. | tCONSTANT
  847. ;
  848. cpath : tCOLON3 cname
  849. {
  850. $$ = NEW_COLON3($2);
  851. }
  852. | cname
  853. {
  854. $$ = NEW_COLON2(0, $$);
  855. }
  856. | primary_value tCOLON2 cname
  857. {
  858. $$ = NEW_COLON2($1, $3);
  859. }
  860. ;
  861. fname : tIDENTIFIER
  862. | tCONSTANT
  863. | tFID
  864. | op
  865. {
  866. lex_state = EXPR_END;
  867. $$ = $1;
  868. }
  869. | reswords
  870. {
  871. lex_state = EXPR_END;
  872. $$ = $&lt;id&gt;1;
  873. }
  874. ;
  875. fsym : fname
  876. | symbol
  877. ;
  878. fitem : fsym
  879. {
  880. $$ = NEW_LIT(ID2SYM($1));
  881. }
  882. | dsym
  883. ;
  884. undef_list : fitem
  885. {
  886. $$ = NEW_UNDEF($1);
  887. }
  888. | undef_list ',' {lex_state = EXPR_FNAME;} fitem
  889. {
  890. $$ = block_append($1, NEW_UNDEF($4));
  891. }
  892. ;
  893. op : '|' { $$ = '|'; }
  894. | '^' { $$ = '^'; }
  895. | '&amp;' { $$ = '&amp;'; }
  896. | tCMP { $$ = tCMP; }
  897. | tEQ { $$ = tEQ; }
  898. | tEQQ { $$ = tEQQ; }
  899. | tMATCH { $$ = tMATCH; }
  900. | '&gt;' { $$ = '&gt;'; }
  901. | tGEQ { $$ = tGEQ; }
  902. | '&lt;' { $$ = '&lt;'; }
  903. | tLEQ { $$ = tLEQ; }
  904. | tLSHFT { $$ = tLSHFT; }
  905. | tRSHFT { $$ = tRSHFT; }
  906. | '+' { $$ = '+'; }
  907. | '-' { $$ = '-'; }
  908. | '*' { $$ = '*'; }
  909. | tSTAR { $$ = '*'; }
  910. | '/' { $$ = '/'; }
  911. | '%' { $$ = '%'; }
  912. | tPOW { $$ = tPOW; }
  913. | '~' { $$ = '~'; }
  914. | tUPLUS { $$ = tUPLUS; }
  915. | tUMINUS { $$ = tUMINUS; }
  916. | tAREF { $$ = tAREF; }
  917. | tASET { $$ = tASET; }
  918. | '`' { $$ = '`'; }
  919. ;
  920. reswords : k__LINE__ | k__FILE__ | klBEGIN | klEND
  921. | kALIAS | kAND | kBEGIN | kBREAK | kCASE | kCLASS | kDEF
  922. | kDEFINED | kDO | kELSE | kELSIF | kEND | kENSURE | kFALSE
  923. | kFOR | kIN | kMODULE | kNEXT | kNIL | kNOT
  924. | kOR | kREDO | kRESCUE | kRETRY | kRETURN | kSELF | kSUPER
  925. | kTHEN | kTRUE | kUNDEF | kWHEN | kYIELD
  926. | kIF | kUNLESS | kWHILE | kUNTIL
  927. ;
  928. arg : lhs '=' arg
  929. {
  930. $$ = node_assign($1, $3);
  931. }
  932. | lhs '=' arg kRESCUE_MOD arg
  933. {
  934. $$ = node_assign($1, NEW_RESCUE($3, NEW_RESBODY(0,$5,0), 0));
  935. }
  936. | var_lhs tOP_ASGN arg
  937. {
  938. value_expr($3);
  939. if ($1) {
  940. ID vid = $1-&gt;nd_vid;
  941. if ($2 == tOROP) {
  942. $1-&gt;nd_value = $3;
  943. $$ = NEW_OP_ASGN_OR(gettable(vid), $1);
  944. if (is_asgn_or_id(vid)) {
  945. $$-&gt;nd_aid = vid;
  946. }
  947. }
  948. else if ($2 == tANDOP) {
  949. $1-&gt;nd_value = $3;
  950. $$ = NEW_OP_ASGN_AND(gettable(vid), $1);
  951. }
  952. else {
  953. $$ = $1;
  954. $$-&gt;nd_value = call_op(gettable(vid),$2,1,$3);
  955. }
  956. }
  957. else {
  958. $$ = 0;
  959. }
  960. }
  961. | primary_value '[' aref_args ']' tOP_ASGN arg
  962. {
  963. NODE *args;
  964. value_expr($6);
  965. if (!$3) $3 = NEW_ZARRAY();
  966. args = arg_concat($6, $3);
  967. if ($5 == tOROP) {
  968. $5 = 0;
  969. }
  970. else if ($5 == tANDOP) {
  971. $5 = 1;
  972. }
  973. $$ = NEW_OP_ASGN1($1, $5, args);
  974. fixpos($$, $1);
  975. }
  976. | primary_value '.' tIDENTIFIER tOP_ASGN arg
  977. {
  978. value_expr($5);
  979. if ($4 == tOROP) {
  980. $4 = 0;
  981. }
  982. else if ($4 == tANDOP) {
  983. $4 = 1;
  984. }
  985. $$ = NEW_OP_ASGN2($1, $3, $4, $5);
  986. fixpos($$, $1);
  987. }
  988. | primary_value '.' tCONSTANT tOP_ASGN arg
  989. {
  990. value_expr($5);
  991. if ($4 == tOROP) {
  992. $4 = 0;
  993. }
  994. else if ($4 == tANDOP) {
  995. $4 = 1;
  996. }
  997. $$ = NEW_OP_ASGN2($1, $3, $4, $5);
  998. fixpos($$, $1);
  999. }
  1000. | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg
  1001. {
  1002. value_expr($5);
  1003. if ($4 == tOROP) {
  1004. $4 = 0;
  1005. }
  1006. else if ($4 == tANDOP) {
  1007. $4 = 1;
  1008. }
  1009. $$ = NEW_OP_ASGN2($1, $3, $4, $5);
  1010. fixpos($$, $1);
  1011. }
  1012. | primary_value tCOLON2 tCONSTANT tOP_ASGN arg
  1013. {
  1014. yyerror(&quot;constant re-assignment&quot;);
  1015. $$ = 0;
  1016. }
  1017. | tCOLON3 tCONSTANT tOP_ASGN arg
  1018. {
  1019. yyerror(&quot;constant re-assignment&quot;);
  1020. $$ = 0;
  1021. }
  1022. | backref tOP_ASGN arg
  1023. {
  1024. rb_backref_error($1);
  1025. $$ = 0;
  1026. }
  1027. | arg tDOT2 arg
  1028. {
  1029. value_expr($1);
  1030. value_expr($3);
  1031. if (nd_type($1) == NODE_LIT &amp;&amp; FIXNUM_P($1-&gt;nd_lit) &amp;&amp;
  1032. nd_type($3) == NODE_LIT &amp;&amp; FIXNUM_P($3-&gt;nd_lit)) {
  1033. $1-&gt;nd_lit = rb_range_new($1-&gt;nd_lit, $3-&gt;nd_lit, Qfalse);
  1034. $$ = $1;
  1035. }
  1036. else {
  1037. $$ = NEW_DOT2($1, $3);
  1038. }
  1039. }
  1040. | arg tDOT3 arg
  1041. {
  1042. value_expr($1);
  1043. value_expr($3);
  1044. if (nd_type($1) == NODE_LIT &amp;&amp; FIXNUM_P($1-&gt;nd_lit) &amp;&amp;
  1045. nd_type($3) == NODE_LIT &amp;&amp; FIXNUM_P($3-&gt;nd_lit)) {
  1046. $1-&gt;nd_lit = rb_range_new($1-&gt;nd_lit, $3-&gt;nd_lit, Qtrue);
  1047. $$ = $1;
  1048. }
  1049. else {
  1050. $$ = NEW_DOT3($1, $3);
  1051. }
  1052. }
  1053. | arg '+' arg
  1054. {
  1055. $$ = call_op($1, '+', 1, $3);
  1056. }
  1057. | arg '-' arg
  1058. {
  1059. $$ = call_op($1, '-', 1, $3);
  1060. }
  1061. | arg '*' arg
  1062. {
  1063. $$ = call_op($1, '*', 1, $3);
  1064. }
  1065. | arg '/' arg
  1066. {
  1067. $$ = call_op($1, '/', 1, $3);
  1068. }
  1069. | arg '%' arg
  1070. {
  1071. $$ = call_op($1, '%', 1, $3);
  1072. }
  1073. | arg tPOW arg
  1074. {
  1075. $$ = call_op($1, tPOW, 1, $3);
  1076. }
  1077. | tUMINUS_NUM tINTEGER tPOW arg
  1078. {
  1079. $$ = call_op(call_op($2, tPOW, 1, $4), tUMINUS, 0, 0);
  1080. }
  1081. | tUMINUS_NUM tFLOAT tPOW arg
  1082. {
  1083. $$ = call_op(call_op($2, tPOW, 1, $4), tUMINUS, 0, 0);
  1084. }
  1085. | tUPLUS arg
  1086. {
  1087. if ($2 &amp;&amp; nd_type($2) == NODE_LIT) {
  1088. $$ = $2;
  1089. }
  1090. else {
  1091. $$ = call_op($2, tUPLUS, 0, 0);
  1092. }
  1093. }
  1094. | tUMINUS arg
  1095. {
  1096. $$ = call_op($2, tUMINUS, 0, 0);
  1097. }
  1098. | arg '|' arg
  1099. {
  1100. $$ = call_op($1, '|', 1, $3);
  1101. }
  1102. | arg '^' arg
  1103. {
  1104. $$ = call_op($1, '^', 1, $3);
  1105. }
  1106. | arg '&amp;' arg
  1107. {
  1108. $$ = call_op($1, '&amp;', 1, $3);
  1109. }
  1110. | arg tCMP arg
  1111. {
  1112. $$ = call_op($1, tCMP, 1, $3);
  1113. }
  1114. | arg '&gt;' arg
  1115. {
  1116. $$ = call_op($1, '&gt;', 1, $3);
  1117. }
  1118. | arg tGEQ arg
  1119. {
  1120. $$ = call_op($1, tGEQ, 1, $3);
  1121. }
  1122. | arg '&lt;' arg
  1123. {
  1124. $$ = call_op($1, '&lt;', 1, $3);
  1125. }
  1126. | arg tLEQ arg
  1127. {
  1128. $$ = call_op($1, tLEQ, 1, $3);
  1129. }
  1130. | arg tEQ arg
  1131. {
  1132. $$ = call_op($1, tEQ, 1, $3);
  1133. }
  1134. | arg tEQQ arg
  1135. {
  1136. $$ = call_op($1, tEQQ, 1, $3);
  1137. }
  1138. | arg tNEQ arg
  1139. {
  1140. $$ = NEW_NOT(call_op($1, tEQ, 1, $3));
  1141. }
  1142. | arg tMATCH arg
  1143. {
  1144. $$ = match_gen($1, $3);
  1145. }
  1146. | arg tNMATCH arg
  1147. {
  1148. $$ = NEW_NOT(match_gen($1, $3));
  1149. }
  1150. | '!' arg
  1151. {
  1152. $$ = NEW_NOT(cond($2));
  1153. }
  1154. | '~' arg
  1155. {
  1156. $$ = call_op($2, '~', 0, 0);
  1157. }
  1158. | arg tLSHFT arg
  1159. {
  1160. $$ = call_op($1, tLSHFT, 1, $3);
  1161. }
  1162. | arg tRSHFT arg
  1163. {
  1164. $$ = call_op($1, tRSHFT, 1, $3);
  1165. }
  1166. | arg tANDOP arg
  1167. {
  1168. $$ = logop(NODE_AND, $1, $3);
  1169. }
  1170. | arg tOROP arg
  1171. {
  1172. $$ = logop(NODE_OR, $1, $3);
  1173. }
  1174. | kDEFINED opt_nl {in_defined = 1;} arg
  1175. {
  1176. in_defined = 0;
  1177. $$ = NEW_DEFINED($4);
  1178. }
  1179. | arg '?' arg ':' arg
  1180. {
  1181. $$ = NEW_IF(cond($1), $3, $5);
  1182. fixpos($$, $1);
  1183. }
  1184. | primary
  1185. {
  1186. $$ = $1;
  1187. }
  1188. ;
  1189. arg_value : arg
  1190. {
  1191. value_expr($1);
  1192. $$ = $1;
  1193. }
  1194. ;
  1195. aref_args : none
  1196. | command opt_nl
  1197. {
  1198. $$ = NEW_LIST($1);
  1199. }
  1200. | args trailer
  1201. {
  1202. $$ = $1;
  1203. }
  1204. | args ',' tSTAR arg opt_nl
  1205. {
  1206. value_expr($4);
  1207. $$ = arg_concat($1, $4);
  1208. }
  1209. | assocs trailer
  1210. {
  1211. $$ = NEW_LIST(NEW_HASH($1));
  1212. }
  1213. | tSTAR arg opt_nl
  1214. {
  1215. value_expr($2);
  1216. $$ = NEW_NEWLINE(NEW_SPLAT($2));
  1217. }
  1218. ;
  1219. paren_args : '(' none ')'
  1220. {
  1221. $$ = $2;
  1222. }
  1223. | '(' call_args opt_nl ')'
  1224. {
  1225. $$ = $2;
  1226. }
  1227. | '(' block_call opt_nl ')'
  1228. {
  1229. $$ = NEW_LIST($2);
  1230. }
  1231. | '(' args ',' block_call opt_nl ')'
  1232. {
  1233. $$ = list_append($2, $4);
  1234. }
  1235. ;
  1236. opt_paren_args : none
  1237. | paren_args
  1238. ;
  1239. call_args : command
  1240. {
  1241. $$ = NEW_LIST($1);
  1242. }
  1243. | args opt_block_arg
  1244. {
  1245. $$ = arg_blk_pass($1, $2);
  1246. }
  1247. | args ',' tSTAR arg_value opt_block_arg
  1248. {
  1249. $$ = arg_concat($1, $4);
  1250. $$ = arg_blk_pass($$, $5);
  1251. }
  1252. | assocs opt_block_arg
  1253. {
  1254. $$ = NEW_LIST(NEW_HASH($1));
  1255. $$ = arg_blk_pass($$, $2);
  1256. }
  1257. | assocs ',' tSTAR arg_value opt_block_arg
  1258. {
  1259. $$ = arg_concat(NEW_LIST(NEW_HASH($1)), $4);
  1260. $$ = arg_blk_pass($$, $5);
  1261. }
  1262. | args ',' assocs opt_block_arg
  1263. {
  1264. $$ = list_append($1, NEW_HASH($3));
  1265. $$ = arg_blk_pass($$, $4);
  1266. }
  1267. | args ',' assocs ',' tSTAR arg opt_block_arg
  1268. {
  1269. value_expr($6);
  1270. $$ = arg_concat(list_append($1, NEW_HASH($3)), $6);
  1271. $$ = arg_blk_pass($$, $7);
  1272. }
  1273. | tSTAR arg_value opt_block_arg
  1274. {
  1275. $$ = arg_blk_pass(NEW_SPLAT($2), $3);
  1276. }
  1277. | block_arg
  1278. ;
  1279. call_args2 : arg_value ',' args opt_block_arg
  1280. {
  1281. $$ = arg_blk_pass(list_concat(NEW_LIST($1),$3), $4);
  1282. }
  1283. | arg_value ',' block_arg
  1284. {
  1285. $$ = arg_blk_pass($1, $3);
  1286. }
  1287. | arg_value ',' tSTAR arg_value opt_block_arg
  1288. {
  1289. $$ = arg_concat(NEW_LIST($1), $4);
  1290. $$ = arg_blk_pass($$, $5);
  1291. }
  1292. | arg_value ',' args ',' tSTAR arg_value opt_block_arg
  1293. {
  1294. $$ = arg_concat(list_concat(NEW_LIST($1),$3), $6);
  1295. $$ = arg_blk_pass($$, $7);
  1296. }
  1297. | assocs opt_block_arg
  1298. {
  1299. $$ = NEW_LIST(NEW_HASH($1));
  1300. $$ = arg_blk_pass($$, $2);
  1301. }
  1302. | assocs ',' tSTAR arg_value opt_block_arg
  1303. {
  1304. $$ = arg_concat(NEW_LIST(NEW_HASH($1)), $4);
  1305. $$ = arg_blk_pass($$, $5);
  1306. }
  1307. | arg_value ',' assocs opt_block_arg
  1308. {
  1309. $$ = list_append(NEW_LIST($1), NEW_HASH($3));
  1310. $$ = arg_blk_pass($$, $4);
  1311. }
  1312. | arg_value ',' args ',' assocs opt_block_arg
  1313. {
  1314. $$ = list_append(list_concat(NEW_LIST($1),$3), NEW_HASH($5));
  1315. $$ = arg_blk_pass($$, $6);
  1316. }
  1317. | arg_value ',' assocs ',' tSTAR arg_value opt_block_arg
  1318. {
  1319. $$ = arg_concat(list_append(NEW_LIST($1), NEW_HASH($3)), $6);
  1320. $$ = arg_blk_pass($$, $7);
  1321. }
  1322. | arg_value ',' args ',' assocs ',' tSTAR arg_value opt_block_arg
  1323. {
  1324. $$ = arg_concat(list_append(list_concat(NEW_LIST($1), $3), NEW_HASH($5)), $8);
  1325. $$ = arg_blk_pass($$, $9);
  1326. }
  1327. | tSTAR arg_value opt_block_arg
  1328. {
  1329. $$ = arg_blk_pass(NEW_SPLAT($2), $3);
  1330. }
  1331. | block_arg
  1332. ;
  1333. command_args : {
  1334. $&lt;num&gt;$ = cmdarg_stack;
  1335. CMDARG_PUSH(1);
  1336. }
  1337. open_args
  1338. {
  1339. /* CMDARG_POP() */
  1340. cmdarg_stack = $&lt;num&gt;1;
  1341. $$ = $2;
  1342. }
  1343. ;
  1344. open_args : call_args
  1345. | tLPAREN_ARG {lex_state = EXPR_ENDARG;} ')'
  1346. {
  1347. rb_warn(&quot;don't put space before argument parentheses&quot;);
  1348. $$ = 0;
  1349. }
  1350. | tLPAREN_ARG call_args2 {lex_state = EXPR_ENDARG;} ')'
  1351. {
  1352. rb_warn(&quot;don't put space before argument parentheses&quot;);
  1353. $$ = $2;
  1354. }
  1355. ;
  1356. block_arg : tAMPER arg_value
  1357. {
  1358. $$ = NEW_BLOCK_PASS($2);
  1359. }
  1360. ;
  1361. opt_block_arg : ',' block_arg
  1362. {
  1363. $$ = $2;
  1364. }
  1365. | none
  1366. ;
  1367. args : arg_value
  1368. {
  1369. $$ = NEW_LIST($1);
  1370. }
  1371. | args ',' arg_value
  1372. {
  1373. $$ = list_append($1, $3);
  1374. }
  1375. ;
  1376. mrhs : args ',' arg_value
  1377. {
  1378. $$ = list_append($1, $3);
  1379. }
  1380. | args ',' tSTAR arg_value
  1381. {
  1382. $$ = arg_concat($1, $4);
  1383. }
  1384. | tSTAR arg_value
  1385. {
  1386. $$ = NEW_SPLAT($2);
  1387. }
  1388. ;
  1389. primary : literal
  1390. | strings
  1391. | xstring
  1392. | regexp
  1393. | words
  1394. | qwords
  1395. | var_ref
  1396. | backref
  1397. | tFID
  1398. {
  1399. $$ = NEW_FCALL($1, 0);
  1400. }
  1401. | kBEGIN
  1402. {
  1403. $&lt;num&gt;1 = ruby_sourceline;
  1404. }
  1405. bodystmt
  1406. kEND
  1407. {
  1408. if ($3 == NULL)
  1409. $$ = NEW_NIL();
  1410. else
  1411. $$ = NEW_BEGIN($3);
  1412. nd_set_line($$, $&lt;num&gt;1);
  1413. }
  1414. | tLPAREN_ARG expr {lex_state = EXPR_ENDARG;} opt_nl ')'
  1415. {
  1416. rb_warning(&quot;(...) interpreted as grouped expression&quot;);
  1417. $$ = $2;
  1418. }
  1419. | tLPAREN compstmt ')'
  1420. {
  1421. if (!$2) $$ = NEW_NIL();
  1422. else $$ = $2;
  1423. }
  1424. | primary_value tCOLON2 tCONSTANT
  1425. {
  1426. $$ = NEW_COLON2($1, $3);
  1427. }
  1428. | tCOLON3 tCONSTANT
  1429. {
  1430. $$ = NEW_COLON3($2);
  1431. }
  1432. | primary_value '[' aref_args ']'
  1433. {
  1434. if ($1 &amp;&amp; nd_type($1) == NODE_SELF)
  1435. $$ = NEW_FCALL(tAREF, $3);
  1436. else
  1437. $$ = NEW_CALL($1, tAREF, $3);
  1438. fixpos($$, $1);
  1439. }
  1440. | tLBRACK aref_args ']'
  1441. {
  1442. if ($2 == 0) {
  1443. $$ = NEW_ZARRAY(); /* zero length array*/
  1444. }
  1445. else {
  1446. $$ = $2;
  1447. }
  1448. }
  1449. | tLBRACE assoc_list '}'
  1450. {
  1451. $$ = NEW_HASH($2);
  1452. }
  1453. | kRETURN
  1454. {
  1455. $$ = NEW_RETURN(0);
  1456. }
  1457. | kYIELD '(' call_args ')'
  1458. {
  1459. $$ = new_yield($3);
  1460. }
  1461. | kYIELD '(' ')'
  1462. {
  1463. $$ = NEW_YIELD(0, Qfalse);
  1464. }
  1465. | kYIELD
  1466. {
  1467. $$ = NEW_YIELD(0, Qfalse);
  1468. }
  1469. | kDEFINED opt_nl '(' {in_defined = 1;} expr ')'
  1470. {
  1471. in_defined = 0;
  1472. $$ = NEW_DEFINED($5);
  1473. }
  1474. | operation brace_block
  1475. {
  1476. $2-&gt;nd_iter = NEW_FCALL($1, 0);
  1477. $$ = $2;
  1478. fixpos($2-&gt;nd_iter, $2);
  1479. }
  1480. | method_call
  1481. | method_call brace_block
  1482. {
  1483. if ($1 &amp;&amp; nd_type($1) == NODE_BLOCK_PASS) {
  1484. rb_compile_error(&quot;both block arg and actual block given&quot;);
  1485. }
  1486. $2-&gt;nd_iter = $1;
  1487. $$ = $2;
  1488. fixpos($$, $1);
  1489. }
  1490. | kIF expr_value then
  1491. compstmt
  1492. if_tail
  1493. kEND
  1494. {
  1495. $$ = NEW_IF(cond($2), $4, $5);
  1496. fixpos($$, $2);
  1497. if (cond_negative(&amp;$$-&gt;nd_cond)) {
  1498. NODE *tmp = $$-&gt;nd_body;
  1499. $$-&gt;nd_body = $$-&gt;nd_else;
  1500. $$-&gt;nd_else = tmp;
  1501. }
  1502. }
  1503. | kUNLESS expr_value then
  1504. compstmt
  1505. opt_else
  1506. kEND
  1507. {
  1508. $$ = NEW_UNLESS(cond($2), $4, $5);
  1509. fixpos($$, $2);
  1510. if (cond_negative(&amp;$$-&gt;nd_cond)) {
  1511. NODE *tmp = $$-&gt;nd_body;
  1512. $$-&gt;nd_body = $$-&gt;nd_else;
  1513. $$-&gt;nd_else = tmp;
  1514. }
  1515. }
  1516. | kWHILE {COND_PUSH(1);} expr_value do {COND_POP();}
  1517. compstmt
  1518. kEND
  1519. {
  1520. $$ = NEW_WHILE(cond($3), $6, 1);
  1521. fixpos($$, $3);
  1522. if (cond_negative(&amp;$$-&gt;nd_cond)) {
  1523. nd_set_type($$, NODE_UNTIL);
  1524. }
  1525. }
  1526. | kUNTIL {COND_PUSH(1);} expr_value do {COND_POP();}
  1527. compstmt
  1528. kEND
  1529. {
  1530. $$ = NEW_UNTIL(cond($3), $6, 1);
  1531. fixpos($$, $3);
  1532. if (cond_negative(&amp;$$-&gt;nd_cond)) {
  1533. nd_set_type($$, NODE_WHILE);
  1534. }
  1535. }
  1536. | kCASE expr_value opt_terms
  1537. case_body
  1538. kEND
  1539. {
  1540. $$ = NEW_CASE($2, $4);
  1541. fixpos($$, $2);
  1542. }
  1543. | kCASE opt_terms case_body kEND
  1544. {
  1545. $$ = $3;
  1546. }
  1547. | kCASE opt_terms kELSE compstmt kEND
  1548. {
  1549. $$ = $4;
  1550. }
  1551. | kFOR for_var kIN {COND_PUSH(1);} expr_value do {COND_POP();}
  1552. compstmt
  1553. kEND
  1554. {
  1555. $$ = NEW_FOR($2, $5, $8);
  1556. fixpos($$, $2);
  1557. }
  1558. | kCLASS cpath superclass
  1559. {
  1560. if (in_def || in_single)
  1561. yyerror(&quot;class definition in method body&quot;);
  1562. class_nest++;
  1563. local_push(0);
  1564. $&lt;num&gt;$ = ruby_sourceline;
  1565. }
  1566. bodystmt
  1567. kEND
  1568. {
  1569. $$ = NEW_CLASS($2, $5, $3);
  1570. nd_set_line($$, $&lt;num&gt;4);
  1571. local_pop();
  1572. class_nest--;
  1573. }
  1574. | kCLASS tLSHFT expr
  1575. {
  1576. $&lt;num&gt;$ = in_def;
  1577. in_def = 0;
  1578. }
  1579. term
  1580. {
  1581. $&lt;num&gt;$ = in_single;
  1582. in_single = 0;
  1583. class_nest++;
  1584. local_push(0);
  1585. }
  1586. bodystmt
  1587. kEND
  1588. {
  1589. $$ = NEW_SCLASS($3, $7);
  1590. fixpos($$, $3);
  1591. local_pop();
  1592. class_nest--;
  1593. in_def = $&lt;num&gt;4;
  1594. in_single = $&lt;num&gt;6;
  1595. }
  1596. | kMODULE cpath
  1597. {
  1598. if (in_def || in_single)
  1599. yyerror(&quot;module definition in method body&quot;);
  1600. class_nest++;
  1601. local_push(0);
  1602. $&lt;num&gt;$ = ruby_sourceline;
  1603. }
  1604. bodystmt
  1605. kEND
  1606. {
  1607. $$ = NEW_MODULE($2, $4);
  1608. nd_set_line($$, $&lt;num&gt;3);
  1609. local_pop();
  1610. class_nest--;
  1611. }
  1612. | kDEF fname
  1613. {
  1614. $&lt;id&gt;$ = cur_mid;
  1615. cur_mid = $2;
  1616. in_def++;
  1617. local_push(0);
  1618. }
  1619. f_arglist
  1620. bodystmt
  1621. kEND
  1622. {
  1623. if (!$5) $5 = NEW_NIL();
  1624. $$ = NEW_DEFN($2, $4, $5, NOEX_PRIVATE);
  1625. fixpos($$, $4);
  1626. local_pop();
  1627. in_def--;
  1628. cur_mid = $&lt;id&gt;3;
  1629. }
  1630. | kDEF singleton dot_or_colon {lex_state = EXPR_FNAME;} fname
  1631. {
  1632. in_single++;
  1633. local_push(0);
  1634. lex_state = EXPR_END; /* force for args */
  1635. }
  1636. f_arglist
  1637. bodystmt
  1638. kEND
  1639. {
  1640. $$ = NEW_DEFS($2, $5, $7, $8);
  1641. fixpos($$, $2);
  1642. local_pop();
  1643. in_single--;
  1644. }
  1645. | kBREAK
  1646. {
  1647. $$ = NEW_BREAK(0);
  1648. }
  1649. | kNEXT
  1650. {
  1651. $$ = NEW_NEXT(0);
  1652. }
  1653. | kREDO
  1654. {
  1655. $$ = NEW_REDO();
  1656. }
  1657. | kRETRY
  1658. {
  1659. $$ = NEW_RETRY();
  1660. }
  1661. ;
  1662. primary_value : primary
  1663. {
  1664. value_expr($1);
  1665. $$ = $1;
  1666. }
  1667. ;
  1668. then : term
  1669. | ':'
  1670. | kTHEN
  1671. | term kTHEN
  1672. ;
  1673. do : term
  1674. | ':'
  1675. | kDO_COND
  1676. ;
  1677. if_tail : opt_else
  1678. | kELSIF expr_value then
  1679. compstmt
  1680. if_tail
  1681. {
  1682. $$ = NEW_IF(cond($2), $4, $5);
  1683. fixpos($$, $2);
  1684. }
  1685. ;
  1686. opt_else : none
  1687. | kELSE compstmt
  1688. {
  1689. $$ = $2;
  1690. }
  1691. ;
  1692. for_var : lhs
  1693. | mlhs
  1694. ;
  1695. block_par : mlhs_item
  1696. {
  1697. $$ = NEW_LIST($1);
  1698. }
  1699. | block_par ',' mlhs_item
  1700. {
  1701. $$ = list_append($1, $3);
  1702. }
  1703. ;
  1704. block_var : block_par
  1705. {
  1706. if ($1-&gt;nd_alen == 1) {
  1707. $$ = $1-&gt;nd_head;
  1708. rb_gc_force_recycle((VALUE)$1);
  1709. }
  1710. else {
  1711. $$ = NEW_MASGN($1, 0);
  1712. }
  1713. }
  1714. | block_par ','
  1715. {
  1716. $$ = NEW_MASGN($1, 0);
  1717. }
  1718. | block_par ',' tAMPER lhs
  1719. {
  1720. $$ = NEW_BLOCK_VAR($4, NEW_MASGN($1, 0));
  1721. }
  1722. | block_par ',' tSTAR lhs ',' tAMPER lhs
  1723. {
  1724. $$ = NEW_BLOCK_VAR($7, NEW_MASGN($1, $4));
  1725. }
  1726. | block_par ',' tSTAR ',' tAMPER lhs
  1727. {
  1728. $$ = NEW_BLOCK_VAR($6, NEW_MASGN($1, -1));
  1729. }
  1730. | block_par ',' tSTAR lhs
  1731. {
  1732. $$ = NEW_MASGN($1, $4);
  1733. }
  1734. | block_par ',' tSTAR
  1735. {
  1736. $$ = NEW_MASGN($1, -1);
  1737. }
  1738. | tSTAR lhs ',' tAMPER lhs
  1739. {
  1740. $$ = NEW_BLOCK_VAR($5, NEW_MASGN(0, $2));
  1741. }
  1742. | tSTAR ',' tAMPER lhs
  1743. {
  1744. $$ = NEW_BLOCK_VAR($4, NEW_MASGN(0, -1));
  1745. }
  1746. | tSTAR lhs
  1747. {
  1748. $$ = NEW_MASGN(0, $2);
  1749. }
  1750. | tSTAR
  1751. {
  1752. $$ = NEW_MASGN(0, -1);
  1753. }
  1754. | tAMPER lhs
  1755. {
  1756. $$ = NEW_BLOCK_VAR($2, (NODE*)1);
  1757. }
  1758. ;
  1759. opt_block_var : none
  1760. | '|' /* none */ '|'
  1761. {
  1762. $$ = (NODE*)1;
  1763. command_start = Qtrue;
  1764. }
  1765. | tOROP
  1766. {
  1767. $$ = (NODE*)1;
  1768. command_start = Qtrue;
  1769. }
  1770. | '|' block_var '|'
  1771. {
  1772. $$ = $2;
  1773. command_start = Qtrue;
  1774. }
  1775. ;
  1776. do_block : kDO_BLOCK
  1777. {
  1778. $&lt;vars&gt;$ = dyna_push();
  1779. $&lt;num&gt;1 = ruby_sourceline;
  1780. }
  1781. opt_block_var {$&lt;vars&gt;$ = ruby_dyna_vars;}
  1782. compstmt
  1783. kEND
  1784. {
  1785. $$ = NEW_ITER($3, 0, dyna_init($5, $&lt;vars&gt;4));
  1786. nd_set_line($$, $&lt;num&gt;1);
  1787. dyna_pop($&lt;vars&gt;2);
  1788. }
  1789. ;
  1790. block_call : command do_block
  1791. {
  1792. if ($1 &amp;&amp; nd_type($1) == NODE_BLOCK_PASS) {
  1793. rb_compile_error(&quot;both block arg and actual block given&quot;);
  1794. }
  1795. $2-&gt;nd_iter = $1;
  1796. $$ = $2;
  1797. fixpos($$, $1);
  1798. }
  1799. | block_call '.' operation2 opt_paren_args
  1800. {
  1801. $$ = new_call($1, $3, $4);
  1802. }
  1803. | block_call tCOLON2 operation2 opt_paren_args
  1804. {
  1805. $$ = new_call($1, $3, $4);
  1806. }
  1807. ;
  1808. method_call : operation paren_args
  1809. {
  1810. $$ = new_fcall($1, $2);
  1811. fixpos($$, $2);
  1812. }
  1813. | primary_value '.' operation2 opt_paren_args
  1814. {
  1815. $$ = new_call($1, $3, $4);
  1816. fixpos($$, $1);
  1817. }
  1818. | primary_value tCOLON2 operation2 paren_args
  1819. {
  1820. $$ = new_call($1, $3, $4);
  1821. fixpos($$, $1);
  1822. }
  1823. | primary_value tCOLON2 operation3
  1824. {
  1825. $$ = new_call($1, $3, 0);
  1826. }
  1827. | kSUPER paren_args
  1828. {
  1829. $$ = new_super($2);
  1830. }
  1831. | kSUPER
  1832. {
  1833. $$ = NEW_ZSUPER();
  1834. }
  1835. ;
  1836. brace_block : '{'
  1837. {
  1838. $&lt;vars&gt;$ = dyna_push();
  1839. $&lt;num&gt;1 = ruby_sourceline;
  1840. }
  1841. opt_block_var {$&lt;vars&gt;$ = ruby_dyna_vars;}
  1842. compstmt '}'
  1843. {
  1844. $$ = NEW_ITER($3, 0, dyna_init($5, $&lt;vars&gt;4));
  1845. nd_set_line($$, $&lt;num&gt;1);
  1846. dyna_pop($&lt;vars&gt;2);
  1847. }
  1848. | kDO
  1849. {
  1850. $&lt;vars&gt;$ = dyna_push();
  1851. $&lt;num&gt;1 = ruby_sourceline;
  1852. }
  1853. opt_block_var {$&lt;vars&gt;$ = ruby_dyna_vars;}
  1854. compstmt kEND
  1855. {
  1856. $$ = NEW_ITER($3, 0, dyna_init($5, $&lt;vars&gt;4));
  1857. nd_set_line($$, $&lt;num&gt;1);
  1858. dyna_pop($&lt;vars&gt;2);
  1859. }
  1860. ;
  1861. case_body : kWHEN when_args then
  1862. compstmt
  1863. cases
  1864. {
  1865. $$ = NEW_WHEN($2, $4, $5);
  1866. }
  1867. ;
  1868. when_args : args
  1869. | args ',' tSTAR arg_value
  1870. {
  1871. $$ = list_append($1, NEW_WHEN($4, 0, 0));
  1872. }
  1873. | tSTAR arg_value
  1874. {
  1875. $$ = NEW_LIST(NEW_WHEN($2, 0, 0));
  1876. }
  1877. ;
  1878. cases : opt_else
  1879. | case_body
  1880. ;
  1881. opt_rescue : kRESCUE exc_list exc_var then
  1882. compstmt
  1883. opt_rescue
  1884. {
  1885. if ($3) {
  1886. $3 = node_assign($3, NEW_GVAR(rb_intern(&quot;$!&quot;)));
  1887. $5 = block_append($3, $5);
  1888. }
  1889. $$ = NEW_RESBODY($2, $5, $6);
  1890. fixpos($$, $2?$2:$5);
  1891. }
  1892. | none
  1893. ;
  1894. exc_list : arg_value
  1895. {
  1896. $$ = NEW_LIST($1);
  1897. }
  1898. | mrhs
  1899. | none
  1900. ;
  1901. exc_var : tASSOC lhs
  1902. {
  1903. $$ = $2;
  1904. }
  1905. | none
  1906. ;
  1907. opt_ensure : kENSURE compstmt
  1908. {
  1909. if ($2)
  1910. $$ = $2;
  1911. else
  1912. /* place holder */
  1913. $$ = NEW_NIL();
  1914. }
  1915. | none
  1916. ;
  1917. literal : numeric
  1918. | symbol
  1919. {
  1920. $$ = NEW_LIT(ID2SYM($1));
  1921. }
  1922. | dsym
  1923. ;
  1924. strings : string
  1925. {
  1926. NODE *node = $1;
  1927. if (!node) {
  1928. node = NEW_STR(rb_str_new(0, 0));
  1929. }
  1930. else {
  1931. node = evstr2dstr(node);
  1932. }
  1933. $$ = node;
  1934. }
  1935. ;
  1936. string : string1
  1937. | string string1
  1938. {
  1939. $$ = literal_concat($1, $2);
  1940. }
  1941. ;
  1942. string1 : tSTRING_BEG string_contents tSTRING_END
  1943. {
  1944. $$ = $2;
  1945. }
  1946. ;
  1947. xstring : tXSTRING_BEG xstring_contents tSTRING_END
  1948. {
  1949. NODE *node = $2;
  1950. if (!node) {
  1951. node = NEW_XSTR(rb_str_new(0, 0));
  1952. }
  1953. else {
  1954. switch (nd_type(node)) {
  1955. case NODE_STR:
  1956. nd_set_type(node, NODE_XSTR);
  1957. break;
  1958. case NODE_DSTR:
  1959. nd_set_type(node, NODE_DXSTR);
  1960. break;
  1961. default:
  1962. node = NEW_NODE(NODE_DXSTR, rb_str_new(0, 0), 1, NEW_LIST(node));
  1963. break;
  1964. }
  1965. }
  1966. $$ = node;
  1967. }
  1968. ;
  1969. regexp : tREGEXP_BEG xstring_contents tREGEXP_END
  1970. {
  1971. int options = $3;
  1972. NODE *node = $2;
  1973. if (!node) {
  1974. node = NEW_LIT(rb_reg_new(&quot;&quot;, 0, options &amp; ~RE_OPTION_ONCE));
  1975. }
  1976. else switch (nd_type(node)) {
  1977. case NODE_STR:
  1978. {
  1979. VALUE src = node-&gt;nd_lit;
  1980. nd_set_type(node, NODE_LIT);
  1981. node-&gt;nd_lit = rb_reg_new(RSTRING(src)-&gt;ptr,
  1982. RSTRING(src)-&gt;len,
  1983. options &amp; ~RE_OPTION_ONCE);
  1984. }
  1985. break;
  1986. default:
  1987. node = NEW_NODE(NODE_DSTR, rb_str_new(0, 0), 1, NEW_LIST(node));
  1988. case NODE_DSTR:
  1989. if (options &amp; RE_OPTION_ONCE) {
  1990. nd_set_type(node, NODE_DREGX_ONCE);
  1991. }
  1992. else {
  1993. nd_set_type(node, NODE_DREGX);
  1994. }
  1995. node-&gt;nd_cflag = options &amp; ~RE_OPTION_ONCE;
  1996. break;
  1997. }
  1998. $$ = node;
  1999. }
  2000. ;
  2001. words : tWORDS_BEG ' ' tSTRING_END
  2002. {
  2003. $$ = NEW_ZARRAY();
  2004. }
  2005. | tWORDS_BEG word_list tSTRING_END
  2006. {
  2007. $$ = $2;
  2008. }
  2009. ;
  2010. word_list : /* none */
  2011. {
  2012. $$ = 0;
  2013. }
  2014. | word_list word ' '
  2015. {
  2016. $$ = list_append($1, evstr2dstr($2));
  2017. }
  2018. ;
  2019. word : string_content
  2020. | word string_content
  2021. {
  2022. $$ = literal_concat($1, $2);
  2023. }
  2024. ;
  2025. qwords : tQWORDS_BEG ' ' tSTRING_END
  2026. {
  2027. $$ = NEW_ZARRAY();
  2028. }
  2029. | tQWORDS_BEG qword_list tSTRING_END
  2030. {
  2031. $$ = $2;
  2032. }
  2033. ;
  2034. qword_list : /* none */
  2035. {
  2036. $$ = 0;
  2037. }
  2038. | qword_list tSTRING_CONTENT ' '
  2039. {
  2040. $$ = list_append($1, $2);
  2041. }
  2042. ;
  2043. string_contents : /* none */
  2044. {
  2045. $$ = 0;
  2046. }
  2047. | string_contents string_content
  2048. {
  2049. $$ = literal_concat($1, $2);
  2050. }
  2051. ;
  2052. xstring_contents: /* none */
  2053. {
  2054. $$ = 0;
  2055. }
  2056. | xstring_contents string_content
  2057. {
  2058. $$ = literal_concat($1, $2);
  2059. }
  2060. ;
  2061. string_content : tSTRING_CONTENT
  2062. | tSTRING_DVAR
  2063. {
  2064. $&lt;node&gt;$ = lex_strterm;
  2065. lex_strterm = 0;
  2066. lex_state = EXPR_BEG;
  2067. }
  2068. string_dvar
  2069. {
  2070. lex_strterm = $&lt;node&gt;2;
  2071. $$ = NEW_EVSTR($3);
  2072. }
  2073. | tSTRING_DBEG
  2074. {
  2075. $&lt;node&gt;$ = lex_strterm;
  2076. lex_strterm = 0;
  2077. lex_state = EXPR_BEG;
  2078. COND_PUSH(0);
  2079. CMDARG_PUSH(0);
  2080. }
  2081. compstmt '}'
  2082. {
  2083. lex_strterm = $&lt;node&gt;2;
  2084. COND_LEXPOP();
  2085. CMDARG_LEXPOP();
  2086. if (($$ = $3) &amp;&amp; nd_type($$) == NODE_NEWLINE) {
  2087. $$ = $$-&gt;nd_next;
  2088. rb_gc_force_recycle((VALUE)$3);
  2089. }
  2090. $$ = new_evstr($$);
  2091. }
  2092. ;
  2093. string_dvar : tGVAR {$$ = NEW_GVAR($1);}
  2094. | tIVAR {$$ = NEW_IVAR($1);}
  2095. | tCVAR {$$ = NEW_CVAR($1);}
  2096. | backref
  2097. ;
  2098. symbol : tSYMBEG sym
  2099. {
  2100. lex_state = EXPR_END;
  2101. $$ = $2;
  2102. }
  2103. ;
  2104. sym : fname
  2105. | tIVAR
  2106. | tGVAR
  2107. | tCVAR
  2108. ;
  2109. dsym : tSYMBEG xstring_contents tSTRING_END
  2110. {
  2111. lex_state = EXPR_END;
  2112. if (!($$ = $2)) {
  2113. $$ = NEW_NIL();
  2114. yyerror(&quot;empty symbol literal&quot;);
  2115. }
  2116. else {
  2117. VALUE lit;
  2118. switch (nd_type($$)) {
  2119. case NODE_DSTR:
  2120. nd_set_type($$, NODE_DSYM);
  2121. break;
  2122. case NODE_STR:
  2123. lit = $$-&gt;nd_lit;
  2124. if (RSTRING(lit)-&gt;len == 0) {
  2125. yyerror(&quot;empty symbol literal&quot;);
  2126. break;
  2127. }
  2128. if (strlen(RSTRING(lit)-&gt;ptr) == RSTRING(lit)-&gt;len) {
  2129. $$-&gt;nd_lit = ID2SYM(rb_intern(RSTRING($$-&gt;nd_lit)-&gt;ptr));
  2130. nd_set_type($$, NODE_LIT);
  2131. break;
  2132. }
  2133. /* fall through */
  2134. default:
  2135. $$ = NEW_NODE(NODE_DSYM, rb_str_new(0, 0), 1, NEW_LIST($$));
  2136. break;
  2137. }
  2138. }
  2139. }
  2140. ;
  2141. numeric : tINTEGER
  2142. | tFLOAT
  2143. | tUMINUS_NUM tINTEGER %prec tLOWEST
  2144. {
  2145. $$ = negate_lit($2);
  2146. }
  2147. | tUMINUS_NUM tFLOAT %prec tLOWEST
  2148. {
  2149. $$ = negate_lit($2);
  2150. }
  2151. ;
  2152. variable : tIDENTIFIER
  2153. | tIVAR
  2154. | tGVAR
  2155. | tCONSTANT
  2156. | tCVAR
  2157. | kNIL {$$ = kNIL;}
  2158. | kSELF {$$ = kSELF;}
  2159. | kTRUE {$$ = kTRUE;}
  2160. | kFALSE {$$ = kFALSE;}
  2161. | k__FILE__ {$$ = k__FILE__;}
  2162. | k__LINE__ {$$ = k__LINE__;}
  2163. ;
  2164. var_ref : variable
  2165. {
  2166. $$ = gettable($1);
  2167. }
  2168. ;
  2169. var_lhs : variable
  2170. {
  2171. $$ = assignable($1, 0);
  2172. }
  2173. ;
  2174. backref : tNTH_REF
  2175. | tBACK_REF
  2176. ;
  2177. superclass : term
  2178. {
  2179. $$ = 0;
  2180. }
  2181. | '&lt;'
  2182. {
  2183. lex_state = EXPR_BEG;
  2184. }
  2185. expr_value term
  2186. {
  2187. $$ = $3;
  2188. }
  2189. | error term {yyerrok; $$ = 0;}
  2190. ;
  2191. f_arglist : '(' f_args opt_nl ')'
  2192. {
  2193. $$ = $2;
  2194. lex_state = EXPR_BEG;
  2195. command_start = Qtrue;
  2196. }
  2197. | f_args term
  2198. {
  2199. $$ = $1;
  2200. }
  2201. ;
  2202. f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg
  2203. {
  2204. $$ = block_append(NEW_ARGS($1, $3, $5), $6);
  2205. }
  2206. | f_arg ',' f_optarg opt_f_block_arg
  2207. {
  2208. $$ = block_append(NEW_ARGS($1, $3, 0), $4);
  2209. }
  2210. | f_arg ',' f_rest_arg opt_f_block_arg
  2211. {
  2212. $$ = block_append(NEW_ARGS($1, 0, $3), $4);
  2213. }
  2214. | f_arg opt_f_block_arg
  2215. {
  2216. $$ = block_append(NEW_ARGS($1, 0, 0), $2);
  2217. }
  2218. | f_optarg ',' f_rest_arg opt_f_block_arg
  2219. {
  2220. $$ = block_append(NEW_ARGS(0, $1, $3), $4);
  2221. }
  2222. | f_optarg opt_f_block_arg
  2223. {
  2224. $$ = block_append(NEW_ARGS(0, $1, 0), $2);
  2225. }
  2226. | f_rest_arg opt_f_block_arg
  2227. {
  2228. $$ = block_append(NEW_ARGS(0, 0, $1), $2);
  2229. }
  2230. | f_block_arg
  2231. {
  2232. $$ = block_append(NEW_ARGS(0, 0, 0), $1);
  2233. }
  2234. | /* none */
  2235. {
  2236. $$ = NEW_ARGS(0, 0, 0);
  2237. }
  2238. ;
  2239. f_norm_arg : tCONSTANT
  2240. {
  2241. yyerror(&quot;formal argument cannot be a constant&quot;);
  2242. }
  2243. | tIVAR
  2244. {
  2245. yyerror(&quot;formal argument cannot be an instance variable&quot;);
  2246. }
  2247. | tGVAR
  2248. {
  2249. yyerror(&quot;formal argument cannot be a global variable&quot;);
  2250. }
  2251. | tCVAR
  2252. {
  2253. yyerror(&quot;formal argument cannot be a class variable&quot;);
  2254. }
  2255. | tIDENTIFIER
  2256. {
  2257. if (!is_local_id($1))
  2258. yyerror(&quot;formal argument must be local variable&quot;);
  2259. else if (local_id($1))
  2260. yyerror(&quot;duplicate argument name&quot;);
  2261. local_cnt($1);
  2262. $$ = 1;
  2263. }
  2264. ;
  2265. f_arg : f_norm_arg
  2266. | f_arg ',' f_norm_arg
  2267. {
  2268. $$ += 1;
  2269. }
  2270. ;
  2271. f_opt : tIDENTIFIER '=' arg_value
  2272. {
  2273. if (!is_local_id($1))
  2274. yyerror(&quot;formal argument must be local variable&quot;);
  2275. else if (local_id($1))
  2276. yyerror(&quot;duplicate optional argument name&quot;);
  2277. $$ = a

Large files files are truncated, but you can click here to view the full file