[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bison scanner patch to fix POSIX incompatibilities, etc.
From: |
Paul Eggert |
Subject: |
Re: Bison scanner patch to fix POSIX incompatibilities, etc. |
Date: |
Tue, 5 Nov 2002 16:01:38 -0800 (PST) |
> From: Akim Demaille <address@hidden>
> Date: 05 Nov 2002 09:30:47 +0100
>
> Paul> While we're on the subject of POSIX conformance, I notice that
> Paul> we're not handling C digraphs correctly. I'll throw that in
> Paul> too; might as well, while I'm at it, since it's easy.
>
> Really, I see no interest at all in making it that perfect.
I'm a perfectionist so I went ahead and wrote it up anyway. If it
turns into a problem we can always rip it out. As a side effect I
noticed that one of the scanner's static variables can easily be made
auto, so I did that too. I installed this patch.
2002-11-05 Paul Eggert <address@hidden>
Scan <% and %> digraphs in C code as POSIX 1003.1-2001 requires.
Also, remove one static variable in the scanner.
* src/scan-gram.l (braces_level): Now auto, not static.
Initialize to zero if the compiler is being picky.
(INITIAL): Clear braces_level instead of incrementing it.
(SC_BRACED_CODE): Treat <% and %> as { and } when inside C code,
as POSIX 1003.1-2001 requires.
* src/system.h (IF_LINT): New macro, taken from coreutils.
* configure.ac: Define "lint" if --enable-gcc-warnings.
Index: src/scan-gram.l
===================================================================
RCS file: /cvsroot/bison/bison/src/scan-gram.l,v
retrieving revision 1.32
retrieving revision 1.33
diff -p -u -r1.32 -r1.33
--- src/scan-gram.l 5 Nov 2002 21:20:14 -0000 1.32
+++ src/scan-gram.l 5 Nov 2002 23:50:11 -0000 1.33
@@ -163,7 +163,6 @@ scanner_last_string_free (void)
}
-static int braces_level = 0;
static int percent_percent_count = 0;
/* Within well-formed rules, RULE_LENGTH is the number of values in
@@ -202,6 +201,8 @@ splice (\\[ \f\t\v]*\n)*
%%
%{
+ int braces_level IF_LINT (= 0);
+
/* At each yylex invocation, mark the current position as the
start of the next token. */
YY_STEP;
@@ -294,7 +295,7 @@ splice (\\[ \f\t\v]*\n)*
"%{" yy_push_state (SC_PROLOGUE);
/* Code in between braces. */
- "{" YY_OBS_GROW; ++braces_level; yy_push_state (SC_BRACED_CODE);
+ "{" YY_OBS_GROW; braces_level = 0; yy_push_state (SC_BRACED_CODE);
/* A type. */
"<"{tag}">" {
@@ -583,9 +584,12 @@ splice (\\[ \f\t\v]*\n)*
<SC_BRACED_CODE>
{
+ "{"|"<"{splice}"%" YY_OBS_GROW; braces_level++;
+ "%"{splice}">" YY_OBS_GROW; braces_level--;
"}" {
YY_OBS_GROW;
- if (--braces_level == 0)
+ braces_level--;
+ if (braces_level < 0)
{
yy_pop_state ();
YY_OBS_FINISH;
@@ -595,17 +599,14 @@ splice (\\[ \f\t\v]*\n)*
}
}
- "{" YY_OBS_GROW; braces_level++;
-
"$"("<"{tag}">")?(-?[0-9]+|"$") { handle_dollar (current_braced_code,
yytext, *yylloc); }
"@"(-?[0-9]+|"$") { handle_at (current_braced_code,
yytext, *yylloc); }
- address@hidden/\'\"\{\}]+ YY_OBS_GROW;
-
- /* A stray $, or /, or etc. */
- . YY_OBS_GROW;
+ /* `"<"{splice}"<"' tokenizes `<<%' correctly (as `<<' `%') rather
+ than incorrrectly (as `<' `<%'). */
+ [^\"$%\'/<@\[\]\{\}]+|[$%/<@]|"<"{splice}"<" YY_OBS_GROW;
<<EOF>> {
complain_at (*yylloc, _("unexpected end of file in a braced code"));
Index: src/system.h
===================================================================
RCS file: /cvsroot/bison/bison/src/system.h,v
retrieving revision 1.54
retrieving revision 1.55
diff -p -u -r1.54 -r1.55
--- src/system.h 3 Nov 2002 06:16:55 -0000 1.54
+++ src/system.h 5 Nov 2002 23:42:51 -0000 1.55
@@ -129,6 +129,14 @@ void *memrchr (const void *s, int c, siz
| GCC extensions. |
`-----------------*/
+/* Use this to suppress gcc's `...may be used before initialized'
+ warnings. */
+#ifdef lint
+# define IF_LINT(Code) Code
+#else
+# define IF_LINT(Code) /* empty */
+#endif
+
#ifndef __attribute__
/* This feature is available in gcc versions 2.5 and later. */
# if !defined (__GNUC__) || __GNUC__ < 2 || \
Index: configure.ac
===================================================================
RCS file: /cvsroot/bison/bison/configure.ac,v
retrieving revision 1.20
retrieving revision 1.21
diff -p -u -r1.20 -r1.21
--- configure.ac 3 Nov 2002 08:39:16 -0000 1.20
+++ configure.ac 5 Nov 2002 23:42:10 -0000 1.21
@@ -56,6 +56,7 @@ if test "${enableval}" = yes; then
BISON_WARNING(-Wshadow)
BISON_WARNING(-Wstrict-prototypes)
BISON_WARNING(-Wwrite-strings)
+ AC_DEFINE([lint], 1, [Define to 1 if the compiler is checking for lint.])
fi
# Checks for programs.
- Bison scanner patch to fix POSIX incompatibilities, etc., Paul Eggert, 2002/11/03
- Re: Bison scanner patch to fix POSIX incompatibilities, etc., Akim Demaille, 2002/11/04
- Re: Bison scanner patch to fix POSIX incompatibilities, etc., Paul Eggert, 2002/11/04
- Re: Bison scanner patch to fix POSIX incompatibilities, etc., Akim Demaille, 2002/11/05
- Re: Bison scanner patch to fix POSIX incompatibilities, etc., Paul Eggert, 2002/11/05
- Re: Bison scanner patch to fix POSIX incompatibilities, etc., Akim Demaille, 2002/11/06
- Re: Bison scanner patch to fix POSIX incompatibilities, etc., Paul Eggert, 2002/11/06
- Re: Bison scanner patch to fix POSIX incompatibilities, etc., Akim Demaille, 2002/11/07
- Re: Bison scanner patch to fix POSIX incompatibilities, etc.,
Paul Eggert <=
- Re: Bison scanner patch to fix POSIX incompatibilities, etc., Paul Eggert, 2002/11/06
- Re: Bison scanner patch to fix POSIX incompatibilities, etc., Akim Demaille, 2002/11/06
- Re: Bison scanner patch to fix POSIX incompatibilities, etc., Paul Eggert, 2002/11/07
Re: Bison scanner patch to fix POSIX incompatibilities, etc., Akim Demaille, 2002/11/04