views:

295

answers:

1

Hi,

I'm trying to figure out how I can display a message/prompt when using lex/yacc (flex/bison).

For instance, main looks like so:

int main(int argc, char *argv[])
{
    yyparse();
}

Which calls yacc, which calls yylex(). This yields a blank line waiting on STDIN. How can i display a message like...

message $ _

instead of

_

Where the underscore represents the cursor position, waiting on input from STDIN...

Forgot to mention, I'd like the prompt to be printed repeatedly... so before each time lex/yacc request input from stdin..

+4  A: 

Figured it out. I had to integrate it as an action in my yacc file.

My mine looks like:

int main(int argc, char *argv[])
{
    prompt();
    yyparse();
}

And my yacc file (.y) looks like...

stmnt
     : /* empty */
     | stmnt whatever { do_something(); prompt(); }
     ;

So that each time it parses a stmnt (the top-level), it'll display the prompt afterwards.