I'm trying to figure out how I can display a message/prompt when using lex/yacc (flex/bison).
我正在试图弄清楚在使用lex / yacc(flex / bison)时如何显示消息/提示。
For instance, main looks like so:
例如,main看起来像这样:
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...
其中调用yacc,调用yylex()。这会产生一个等待STDIN的空行。我怎样才能显示像......这样的信息
message $ _
instead of
_
Where the underscore represents the cursor position, waiting on input from STDIN...
下划线表示光标位置,等待STDIN的输入......
Forgot to mention, I'd like the prompt to be printed repeatedly... so before each time lex/yacc request input from stdin..
忘了提,我想重复打印提示...所以在每次lex / yacc请求从stdin输入之前...
1 个解决方案
#1
Figured it out. I had to integrate it as an action in my yacc file.
弄清楚了。我必须将它作为一个动作集成到我的yacc文件中。
My mine looks like:
我的矿井看起来像:
int main(int argc, char *argv[])
{
prompt();
yyparse();
}
And my yacc file (.y) looks like...
我的yacc文件(.y)看起来像......
stmnt : /* empty */ | stmnt whatever { do_something(); prompt(); } ;
So that each time it parses a stmnt (the top-level), it'll display the prompt afterwards.
因此,每次它解析stmnt(*)时,它都会在之后显示提示。
#1
Figured it out. I had to integrate it as an action in my yacc file.
弄清楚了。我必须将它作为一个动作集成到我的yacc文件中。
My mine looks like:
我的矿井看起来像:
int main(int argc, char *argv[])
{
prompt();
yyparse();
}
And my yacc file (.y) looks like...
我的yacc文件(.y)看起来像......
stmnt : /* empty */ | stmnt whatever { do_something(); prompt(); } ;
So that each time it parses a stmnt (the top-level), it'll display the prompt afterwards.
因此,每次它解析stmnt(*)时,它都会在之后显示提示。