我是Lex和Yacc的新手.我有一个Lex程序.示例:wordcount.l
我正在使用窗户和腻子.
我只是想运行这个文件..
> wordcount.l文件是否在C盘上?
>我是否编译了Lex程序并生成了一个.c程序,然后我运行了什么?
我试过命令行:Lex wordcount.l
但我只是找不到档案……
wordcount.l
%{
#include
#include
int charCount=0;
int wordCount=0;
int lineCount=0;
%}
%%
\n {charCount++; lineCount++;}
[^ \t\n]+ {wordCount++; charCount+=yyleng;}
. {charCount++;}
%%
main(argc, argv)
int argc;
char** argv;
{
if (argc > 1)
{
FILE *file;
file = fopen(argv[1], "r");
if (!file)
{
fprintf(stderr, "Could not open %s\n", argv[1]);
exit(1);
}
yyin = file;
}
yylex();
printf("%d %d %d\n", charCount, wordCount, lineCount);
}
在putty中如何编译和运行该程序?