1

I'm new to flex and bison and i couldn't figure it out. I want to read a file. This is okey for now. But while bison/flex parse and read file, I want to make it wait for new input and get it from command line. Is there a keyword or way to do it?

I tried abort yyparse() with yyerror() and get input by scanf(). But it didn't work. It doesn't wait for input and goes on.

mehmet
  • 11
  • 1
  • You are saying `scanf` doesn't wait for input? Best guess in the codeless void is [scanf() leaves the newline char in the buffer](https://stackoverflow.com/questions/5240789/scanf-leaves-the-new-line-char-in-the-buffer). – Weather Vane Feb 15 '23 at 20:31
  • 2
    You'll need to work a bit harder at communicating what it is that you want to do. For example, what is "it" in "I want to make it wait..."? Some would be optimal, or eve pseudocode. Or an illustration of what you would like to happen. (Please note that "command line" is not the same thing as "my terminal". That makes your question even more confusing.) – rici Feb 15 '23 at 20:47
  • If the lexer is reading its input from a regular file (that is, not from stdin), then there is no reason why the program could not simultaneously read from stdin as well. But you do need to do that in a separate thread, of course, as the one that calls `yyparse()` will be occupied with that until parsing is complete. – John Bollinger Feb 15 '23 at 22:35

1 Answers1

0

I did a project school named mini_shell and what we asked to do was to code something like bash. the main thing was to wait for user input and execute the command he entered, you can do that by a function named. char *readline(const char *prompt); (you can read the man page to understand more https://man7.org/linux/man-pages/man3/readline.3.html) but I think you need to install it first before you can use it, you can find a lot of tutorials explaining how to do that based on your OS.