westes / flex

The Fast Lexical Analyzer - scanner generator for lexing in C and C++
Other
3.63k stars 536 forks source link

Allow white space in yymore and yyreject checks #608

Closed taniwha closed 7 months ago

taniwha commented 1 year ago

AC_PROG_LEX puts a space between yymore and its ()s causing the yymore check to fail and thus break configure.

westes commented 11 months ago

I'm confused on where/when configure is broken. I just rebuilt configure and ran it from my local copy of the git repo. It completed successfully.

d125q commented 11 months ago

It is broken in the sense that AC_PROG_LEX does not detect flex built from HEAD (8453b08 at the time of writing).

AC_PROG_LEX generates the following program:

%{
#ifdef __cplusplus
extern "C"
#endif
int yywrap(void);
%}
%%
a { ECHO; }
b { REJECT; }
c { yymore (); }
d { yyless (1); }
e { /* IRIX 6.5 flex 2.5.4 underquotes its yyless argument.  */
#ifdef __cplusplus
    yyless ((yyinput () != 0));
#else
    yyless ((input () != 0));
#endif
  }
f { unput (yytext[0]); }
. { BEGIN INITIAL; }
%%
#ifdef YYTEXT_POINTER
extern char *yytext;
#endif
int
yywrap (void)
{
  return 1;
}
int
main (void)
{
  return ! yylex ();
}

As you can see, the parentheses are preceded by a space. This causes flex to fail with:

conftest.l:10:3: error: use of undeclared identifier 'yymore_used_but_not_detected'
{ yymore (); }
  ^
conftest.c:614:18: note: expanded from macro 'yymore'
#define yymore() yymore_used_but_not_detected
                 ^
lex.yy.c:1704:25: warning: equality comparison with extraneous parentheses [-Wparentheses-equality]
                if ( (yy_buffer_stack == NULL) ) {
                      ~~~~~~~~~~~~~~~~^~~~~~~
lex.yy.c:1704:25: note: remove extraneous parentheses around the comparison to silence this warning
                if ( (yy_buffer_stack == NULL) ) {
                     ~                ^      ~
lex.yy.c:1704:25: note: use '=' to turn this equality comparison into an assignment
                if ( (yy_buffer_stack == NULL) ) {
                                      ^~
                                      =
1 warning and 1 error generated.
configure:14088: $? = 1

For the record, I was attempting to build bedeb7dc of wget.

westes commented 11 months ago

What are the exact steps I need to follow to reproduce the problem?

d125q commented 11 months ago

Create a configure.ac file:

AC_INIT
AC_PROG_LEX([noyywrap])
AS_IF([test "x$LEX" != xflex], [AC_MSG_ERROR([flex not found])])
AC_OUTPUT

Run:

$ autoreconf -ifv
$ ./configure

Result:

Mightyjo commented 11 months ago

Prior to 2.6.4, we didn't include the parentheses in the yymore check at all. I think returning to that construction is the best solution.

This patch will also work, but it prefers C-like function calls. Since I'm slowly working on other output language backends I'm biased toward solutions that will work more generally.

Thanks for pointing this out!

westes commented 7 months ago

Researching, commit 191d706 is where the particular change was made for yymore.

Mightyjo commented 7 months ago

Sitting with this for a few months, I'm happy with @d125q's solution. I was concerned that using {OPTWS} in the rules would lead to line length problems like those in #620, but we already use this construction in scan.l without trouble so I'm withdraw that concern.

If we ever support an action language that doesn't put parentheses around its argument/parameter lists, I expect we'll be able to search for this thread.

westes commented 7 months ago

I'm working up a test case for this. It's subtler to sort out that I'd like, so I want to be sure we're able to catch it from happening again.

westes commented 7 months ago

Thanks for this; it's now on master.