Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yyinput() with EOF has inconsistent behavior with documentation #444

Open
forewing opened this issue Mar 31, 2020 · 2 comments
Open

yyinput() with EOF has inconsistent behavior with documentation #444

forewing opened this issue Mar 31, 2020 · 2 comments

Comments

@forewing
Copy link

forewing commented Mar 31, 2020

Current Behavior

f863c94 changed the return value of yyinput() from EOF to 0 when encountering an end-of-file:

flex/src/flex.skl

Lines 1970 to 1973 in 3a4af34

case EOB_ACT_END_OF_FILE:
{
if ( yywrap( M4_YY_CALL_ONLY_ARG ) )
return EOF;

flex/src/flex.skl

Lines 1970 to 1973 in f863c94

case EOB_ACT_END_OF_FILE:
{
if ( yywrap( M4_YY_CALL_ONLY_ARG ) )
return 0;

Inconsistence

But as documentation showed, yyinput() return EOF when encountering an end-of-file:

flex/doc/flex.texi

Lines 4549 to 4553 in 8b1fbf6

The @code{input()} routine is not redefinable, though it may be called
to read characters following whatever has been matched by a rule. If
@code{input()} encounters an end-of-file the normal @code{yywrap()}
processing is done. A ``real'' end-of-file is returned by
@code{input()} as @code{EOF}.

And the example of comments discarding use EOF to check:

flex/doc/flex.texi

Lines 1410 to 1411 in 8b1fbf6

while ( (c = input()) != '*' &&
c != EOF )

flex/doc/flex.texi

Lines 1422 to 1426 in 8b1fbf6

if ( c == EOF )
{
error( "EOF in comment" );
break;
}

which will never break from the loop in current version.

Possible Solution

The documentation should be updated.

@zmajeed
Copy link
Contributor

zmajeed commented Nov 2, 2023

Could you provide a reproducible test case that shows yyinput() does not return EOF on end of file?

Isn't the code change you've pointed to what's described in chapter 9 of the doc?

"When the scanner receives an end-of-file indication from YY INPUT, it then checks the yywrap() function. If yywrap() returns false (zero), then it is assumed that the function has gone ahead and set up yyin to point to another input file, and scanning continues. If it returns true (non-zero), then the scanner terminates, returning 0 to its caller."

@zmajeed
Copy link
Contributor

zmajeed commented Nov 3, 2023

You're right - input() is shown returning EOF on end of file in some parts of flex docs while it returns 0 in other places - I found the Posix spec for input() - https://pubs.opengroup.org/onlinepubs/9699919799/utilities/lex.html - it's supposed to return 0 not EOF on end of file

int input(void)

Returns the next character from the input, or zero on end-of-file. It shall obtain input from the stream pointer yyin, although possibly via an intermediate buffer. Thus, once scanning has begun, the effect of altering the value of yyin is undefined. The character read shall be removed from the input stream of the scanner without any processing by the scanner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants