2011-08-03 10 views
0

フレックスの使用に問題があります。
私はその後、私は私はa EXEファイルを生成したコマンドgcc lex.yy.c -lflを与えそしてlex.yy
を生成コマンドflex happy.cを与えフレックスで生成された出力を生成する

int num_lines = 0, num_chars = 0; 

%% 
\n  ++num_lines; ++num_chars; 
.  ++num_chars; 

%% 
main() 
    { 
     yylex(); 
     printf("# of lines = %d, # of chars = %d\n", 
         num_lines, num_chars); 
     } 

としてCファイルhappy.cを書きました。
しかし、このexeファイルの使い方はわかりません。例えば:私がコマンドを与えたとき

それは何も生産しなかった。プログラムがハングしているようだ。

exeファイルの使い方を教えてください。

答えて

1

は、代わりにこれを試してみてください:

%{ 
int num_lines = 0, num_chars = 0; 
%} 
%% 
\n  { ++num_lines; ++num_chars; } 
.  { ++num_chars; } 

%% 
main() 
{ 
    yylex(); 
    printf("# of lines = %d, # of chars = %d\n", num_lines, num_chars); 
} 

、その後:

testが含ま
[email protected]:~/Programming/GNU-Flex-Bison/lexer$ flex happy.c 
[email protected]:~/Programming/GNU-Flex-Bison/lexer$ gcc lex.yy.c -lfl 
[email protected]:~/Programming/GNU-Flex-Bison/lexer$ ./a.out < test 
# of lines = 2, # of chars = 8 

を:

foo 
bar 
+0

私もこれを試してみました。 そして './a test'と打ちました。しかし、何も起こらなかった。私は入力を続け、何も起こらない。 –

+0

'./a test'ではなく' ./a

+0

Ok ...ありがとうございます。 –

関連する問題