1

I create a simple file, using flex, it generate a file lex.yy.c, for now, I want to put it to C++ program.

%{

 #include < stdio.h>

%}

%%

stop    printf("Stop command received\n");

start   printf("Start command received\n");

%%

When I type start or stop in command line, there is a output. What I want to do is to give the input by my C++ program, and the output of it should be sent to a variable in my program, is it possible? Thanks a lot!

I know the code I post is quite simple, but the result I imagine is:

create c file by flex and bison, and I use it as a header, so in the c++ program, I just need to call a function lex_yacc() to use it. ex. lex_yacc() is a calculator, so I sent an expression with evariables to this function, and it will return the result. I want to use this function in a C++ program, I am confused...Thanks a lot!

4

1 に答える 1

1

マニュアルの複数の入力バッファに関するセクションを参照してください。特に と についてのyy_scan_stringセクションyy_scan_bytes

「出力」については、もちろん、入力として「停止」または「開始」を与えると「出力」になります。明示的にそれを行います(つまり、printf呼び出し)。そこに好きなコードを入れることができます。

于 2012-09-21T07:44:57.483 に答える