salezica
salezica

Reputation: 76939

Lex: forcing scan?

I'm writing a fairly simple program with LEX, that after parsing a few files, parses input from a user.

Now, with the files, everything works like a charm. However, when it comes to user input from stdin, LEX rules won't run until an EOF (via ctrl+D) character is sent. When I do that, LEX parses all I wrote and then waits for more input. A second consecutive EOF terminates the scanner.

Thing is, I want the program to react on \n, outputting some data. Is there a way to force a scan from inside a rule, or to configure LEX buffering somehow to match this behaviour?

Upvotes: 3

Views: 115

Answers (2)

richmb
richmb

Reputation: 1595

Here is a snippet from a unix shell I did with lex and yacc. I think it'll do the trick.

"\n"                    |
";"                     {
                        //yylval.sb = getsb(yytext);  for yacc stuff
                        fprintf(stderr,"EOL\n");
                        return(EOL);
                        }

Upvotes: 0

salezica
salezica

Reputation: 76939

Solved! This did the trick:

%option always-interactive

I'm leaving this here for future reference, in case... well, who knows.

Upvotes: 4

Related Questions