@@ -401,6 +401,23 @@ show_sub_messages (warnings warning,
401401 points to LHS ($$) of the current rule or midrule. */
402402#define LHS_REF (INT_MIN + 1)
403403
404+ /* Parse a positional reference in RULE. */
405+ static long
406+ parse_positional_ref (char * cp , int rule_length ,
407+ char * text , const location * text_loc )
408+ {
409+ long num = strtol (cp , & cp , 10 );
410+ if (1 - INT_MAX + rule_length <= num && num <= rule_length )
411+ return num ;
412+ else
413+ {
414+ complain (text_loc , complaint , _ ("integer out of range: %s" ),
415+ quote (text ));
416+ return INVALID_REF ;
417+ }
418+ }
419+
420+
404421/* Parse named or positional reference. In case of positional
405422 references, can return negative values for $-n "deep" stack
406423 accesses. */
@@ -412,18 +429,8 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
412429 if ('$' == * cp )
413430 return LHS_REF ;
414431
415- if (c_isdigit (* cp ) || (* cp == '-' && c_isdigit (* (cp + 1 ))))
416- {
417- long num = strtol (cp , & cp , 10 );
418- if (1 - INT_MAX + rule_length <= num && num <= rule_length )
419- return num ;
420- else
421- {
422- complain (text_loc , complaint , _ ("integer out of range: %s" ),
423- quote (text ));
424- return INVALID_REF ;
425- }
426- }
432+ if (c_isdigit (* cp ) || (* cp == '-' && c_isdigit (cp [1 ])))
433+ return parse_positional_ref (cp , rule_length , text , text_loc );
427434
428435 bool const explicit_bracketing = * cp == '[' ;
429436
@@ -585,7 +592,7 @@ fetch_type_name (char *cp, char const **type_name,
585592/*------------------------------------------------------------------.
586593| TEXT is pointing to a wannabee semantic value (i.e., a '$'). |
587594| |
588- | Possible inputs: $[<TYPENAME>]($|integer ) |
595+ | Possible inputs: $[<TYPENAME>]($|INTEGER ) |
589596| |
590597| Output to OBSTACK_FOR_STRING a reference to this semantic value. |
591598`------------------------------------------------------------------*/
0 commit comments