%option prefix="code_" outfile="lex.yy.c"
%{
+#include <config.h>
+#include "system.h"
+
/* Work around a bug in flex 2.5.31. See Debian bug 333231
<http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>. */
#undef code_wrap
#define code_wrap() 1
#define FLEX_PREFIX(Id) code_ ## Id
+#include "complain.h"
#include "flex-scanner.h"
#include "reader.h"
#include "getargs.h"
#define YY_USER_ACTION location_compute (loc, &loc->end, yytext, yyleng);
-static void handle_action_dollar (char *cp, location loc);
-static void handle_action_at (char *cp, location loc);
+static void handle_action_dollar (char *cp, location dollar_loc);
+static void handle_action_at (char *cp, location at_loc);
static location the_location;
static location *loc = &the_location;
%%
%{
+ /* Nesting level of the current code in braces. */
+ int braces_level IF_LINT (= 0);
+
/* This scanner is special: it is invoked only once, henceforth
is expected to return only once. This initialization is
therefore done once per action to translate. */
warn_at (*loc, _("stray `@'"));
obstack_sgrow (&obstack_for_string, "@@");
}
+
+ "{" STRING_GROW; ++braces_level;
+ "}" {
+ bool outer_brace = --braces_level < 0;
+
+ /* As an undocumented Bison extension, append `;' before the last
+ brace in braced code, so that the user code can omit trailing
+ `;'. But do not append `;' if emulating Yacc, since Yacc does
+ not append one.
+
+ FIXME: Bison should warn if a semicolon seems to be necessary
+ here, and should omit the semicolon if it seems unnecessary
+ (e.g., after ';', '{', or '}', each followed by comments or
+ white space). Such a warning shouldn't depend on --yacc; it
+ should depend on a new --pedantic option, which would cause
+ Bison to warn if it detects an extension to POSIX. --pedantic
+ should also diagnose other Bison extensions like %yacc.
+ Perhaps there should also be a GCC-style --pedantic-errors
+ option, so that such warnings are diagnosed as errors. */
+ if (outer_brace && ! yacc_flag)
+ obstack_1grow (&obstack_for_string, ';');
+
+ STRING_GROW;
+ }
}
<SC_SYMBOL_ACTION>
`------------------------------------------------------------------*/
static void
-handle_action_dollar (char *text, location loc)
+handle_action_dollar (char *text, location dollar_loc)
{
const char *type_name = NULL;
char *cp = text + 1;
if (*cp == '$')
{
if (!type_name)
- type_name = symbol_list_n_type_name_get (current_rule, loc, 0);
+ type_name = symbol_list_n_type_name_get (current_rule, dollar_loc, 0);
if (!type_name && typed)
- complain_at (loc, _("$$ of `%s' has no declared type"),
+ complain_at (dollar_loc, _("$$ of `%s' has no declared type"),
current_rule->sym->tag);
if (!type_name)
type_name = "";
if (1-n > max_left_semantic_context)
max_left_semantic_context = 1-n;
if (!type_name && n > 0)
- type_name = symbol_list_n_type_name_get (current_rule, loc, n);
+ type_name =
+ symbol_list_n_type_name_get (current_rule, dollar_loc, n);
if (!type_name && typed)
- complain_at (loc, _("$%d of `%s' has no declared type"),
+ complain_at (dollar_loc, _("$%d of `%s' has no declared type"),
n, current_rule->sym->tag);
if (!type_name)
type_name = "";
symbol_list_n_used_set (current_rule, n, true);
}
else
- complain_at (loc, _("integer out of range: %s"), quote (text));
+ complain_at (dollar_loc, _("integer out of range: %s"), quote (text));
}
}
`------------------------------------------------------*/
static void
-handle_action_at (char *text, location loc)
+handle_action_at (char *text, location at_loc)
{
char *cp = text + 1;
int rule_length = symbol_list_length (current_rule->next);
rule_length, n);
}
else
- complain_at (loc, _("integer out of range: %s"), quote (text));
+ complain_at (at_loc, _("integer out of range: %s"), quote (text));
}
}