76 |
} |
} |
77 |
|
|
78 |
|
|
|
|
|
79 |
static int braces_level = 0; |
static int braces_level = 0; |
80 |
static int percent_percent_count = 0; |
static int percent_percent_count = 0; |
81 |
|
|
82 |
static void handle_action_dollar PARAMS ((char *cp, location_t location)); |
static void handle_dollar PARAMS ((braced_code_t code_kind, |
83 |
static void handle_destructor_dollar PARAMS ((char *cp, location_t location)); |
char *cp, location_t location)); |
84 |
static void handle_at PARAMS ((char *cp)); |
static void handle_at PARAMS ((braced_code_t code_kind, |
85 |
|
char *cp, location_t location)); |
86 |
|
|
87 |
%} |
%} |
88 |
%x SC_COMMENT |
%x SC_COMMENT |
443 |
|
|
444 |
"{" YY_OBS_GROW; braces_level++; |
"{" YY_OBS_GROW; braces_level++; |
445 |
|
|
446 |
"$"("<"[^>]+">")?(-?[0-9]+|"$") { |
"$"("<"[^>]+">")?(-?[0-9]+|"$") { handle_dollar (current_braced_code, |
447 |
switch (current_braced_code) |
yytext, *yylloc); } |
448 |
{ |
"@"(-?[0-9]+|"$") { handle_at (current_braced_code, |
449 |
case action_braced_code: |
yytext, *yylloc); } |
|
handle_action_dollar (yytext, *yylloc); |
|
|
break; |
|
|
|
|
|
case destructor_braced_code: |
|
|
handle_destructor_dollar (yytext, *yylloc); |
|
|
break; |
|
|
} |
|
|
} |
|
|
"@"(-?[0-9]+|"$") { handle_at (yytext); } |
|
450 |
|
|
451 |
[^$@\[\]/\'\"\{\}\n\r]+ YY_OBS_GROW; |
[^$@\[\]/\'\"\{\}\n\r]+ YY_OBS_GROW; |
452 |
{eols} YY_OBS_GROW; YY_LINES; |
{eols} YY_OBS_GROW; YY_LINES; |
523 |
| Output to the STRING_OBSTACK a reference to this semantic value. | |
| Output to the STRING_OBSTACK a reference to this semantic value. | |
524 |
`------------------------------------------------------------------*/ |
`------------------------------------------------------------------*/ |
525 |
|
|
526 |
static void |
static inline void |
527 |
handle_action_dollar (char *cp, location_t location) |
handle_action_dollar (char *cp, location_t location) |
528 |
{ |
{ |
529 |
const char *type_name = NULL; |
const char *type_name = NULL; |
587 |
} |
} |
588 |
|
|
589 |
|
|
590 |
/*---------------------------------------------------------------. |
/*---------------------------------------. |
591 |
| CP is pointing to $$ in a destructor. This should probably be | |
| CP is pointing to $$ in a destructor. | |
592 |
| done once the grammar completely parsed, instead of during its | |
`---------------------------------------*/ |
|
| parsing, since that means %type must be specified before | |
|
|
| %destructor. | |
|
|
`---------------------------------------------------------------*/ |
|
593 |
|
|
594 |
static void |
static inline void |
595 |
handle_destructor_dollar (char *cp, location_t location) |
handle_destructor_dollar (char *cp, location_t location) |
596 |
{ |
{ |
597 |
++cp; |
++cp; |
598 |
if (*cp == '$') |
if (*cp == '$') |
599 |
{ |
{ |
600 |
/* FIXME: We should find something more robust. */ |
obstack_sgrow (&string_obstack, "]b4_dollar_dollar["); |
|
obstack_sgrow (&string_obstack, "b4_dollar_dollar"); |
|
601 |
} |
} |
602 |
else |
else |
603 |
{ |
{ |
607 |
} |
} |
608 |
} |
} |
609 |
|
|
610 |
/*-------------------------------------------------------. |
|
611 |
| CP is pointing to a location (i.e., a `@'). Output to | |
/*-----------------------------------------------------------------. |
612 |
| STRING_OBSTACK a reference to this location. | |
| Dispatch onto handle_action_dollar, or handle_destructor_dollar, | |
613 |
`-------------------------------------------------------*/ |
| depending upon CODE_KIND. | |
614 |
|
`-----------------------------------------------------------------*/ |
615 |
|
|
616 |
static void |
static void |
617 |
handle_at (char *cp) |
handle_dollar (braced_code_t braced_code_kind, |
618 |
|
char *text, location_t location) |
619 |
|
{ |
620 |
|
switch (braced_code_kind) |
621 |
|
{ |
622 |
|
case action_braced_code: |
623 |
|
handle_action_dollar (text, location); |
624 |
|
break; |
625 |
|
|
626 |
|
case destructor_braced_code: |
627 |
|
handle_destructor_dollar (text, location); |
628 |
|
break; |
629 |
|
} |
630 |
|
} |
631 |
|
|
632 |
|
|
633 |
|
/*------------------------------------------------------. |
634 |
|
| TEXT is a location token (i.e., a `@...'). Output to | |
635 |
|
| STRING_OBSTACK a reference to this location. | |
636 |
|
`------------------------------------------------------*/ |
637 |
|
|
638 |
|
static inline void |
639 |
|
handle_action_at (char *text, location_t location) |
640 |
{ |
{ |
641 |
locations_flag = 1; |
locations_flag = 1; |
642 |
++cp; |
++text; |
643 |
|
|
644 |
if (*cp == '$') |
if (*text == '$') |
645 |
{ |
{ |
646 |
obstack_sgrow (&string_obstack, "]b4_lhs_location["); |
obstack_sgrow (&string_obstack, "]b4_lhs_location["); |
647 |
} |
} |
648 |
else if (isdigit (*cp) || *cp == '-') |
else if (isdigit (*text) || *text == '-') |
649 |
{ |
{ |
650 |
/* RULE_LENGTH is the number of values in the current rule so |
/* RULE_LENGTH is the number of values in the current rule so |
651 |
far, which says where to find `$0' with respect to the top of |
far, which says where to find `$0' with respect to the top of |
652 |
the stack. It is not the same as the rule->length in the |
the stack. It is not the same as the rule->length in the |
653 |
case of mid rule actions. */ |
case of mid rule actions. */ |
654 |
int rule_length = symbol_list_length (current_rule->next); |
int rule_length = symbol_list_length (current_rule->next); |
655 |
int n = strtol (cp, &cp, 10); |
int n = strtol (text, &text, 10); |
656 |
|
|
657 |
if (n > rule_length) |
if (n > rule_length) |
658 |
complain (_("invalid value: %s%d"), "@", n); |
complain_at (location, _("invalid value: %s%d"), "@", n); |
659 |
else |
else |
660 |
obstack_fgrow2 (&string_obstack, "]b4_rhs_location([%d], [%d])[", |
obstack_fgrow2 (&string_obstack, "]b4_rhs_location([%d], [%d])[", |
661 |
rule_length, n); |
rule_length, n); |
663 |
else |
else |
664 |
{ |
{ |
665 |
char buf[] = "@c"; |
char buf[] = "@c"; |
666 |
buf[1] = *cp; |
buf[1] = *text; |
667 |
complain (_("%s is invalid"), quote (buf)); |
complain_at (location, _("%s is invalid"), quote (buf)); |
668 |
} |
} |
669 |
} |
} |
670 |
|
|
671 |
|
|
672 |
|
/*--------------------------------------------. |
673 |
|
| TEXT is expexted tp be @$ in a destructor. | |
674 |
|
`--------------------------------------------*/ |
675 |
|
|
676 |
|
static inline void |
677 |
|
handle_destructor_at (char *text, location_t location) |
678 |
|
{ |
679 |
|
++text; |
680 |
|
if (*text == '$') |
681 |
|
{ |
682 |
|
obstack_sgrow (&string_obstack, "]b4_at_dollar["); |
683 |
|
} |
684 |
|
else |
685 |
|
{ |
686 |
|
char buf[] = "$c"; |
687 |
|
buf[1] = *text; |
688 |
|
complain_at (location, _("%s is invalid"), quote (buf)); |
689 |
|
} |
690 |
|
} |
691 |
|
|
692 |
|
|
693 |
|
/*-------------------------------------------------------------------. |
694 |
|
| Dispatch onto handle_action_at, or handle_destructor_at, depending | |
695 |
|
| upon CODE_KIND. | |
696 |
|
`-------------------------------------------------------------------*/ |
697 |
|
|
698 |
|
static void |
699 |
|
handle_at (braced_code_t braced_code_kind, |
700 |
|
char *text, location_t location) |
701 |
|
{ |
702 |
|
switch (braced_code_kind) |
703 |
|
{ |
704 |
|
case action_braced_code: |
705 |
|
handle_action_at (text, location); |
706 |
|
break; |
707 |
|
|
708 |
|
case destructor_braced_code: |
709 |
|
handle_destructor_at (text, location); |
710 |
|
break; |
711 |
|
} |
712 |
|
} |
713 |
|
|
714 |
|
|
715 |
|
/*-------------------------. |
716 |
|
| Initialize the scanner. | |
717 |
|
`-------------------------*/ |
718 |
|
|
719 |
void |
void |
720 |
scanner_initialize (void) |
scanner_initialize (void) |
721 |
{ |
{ |
723 |
} |
} |
724 |
|
|
725 |
|
|
726 |
|
/*-----------------------------------------------. |
727 |
|
| Free all the memory allocated to the scanner. | |
728 |
|
`-----------------------------------------------*/ |
729 |
|
|
730 |
void |
void |
731 |
scanner_free (void) |
scanner_free (void) |
732 |
{ |
{ |