我对莱克斯和雅克很陌生。我有个Lex程序。示例:wordcount.l
我用的是窗户和油灰。
我只是想运行这个文件..。
wordcount.l文件吗?.c程序,然后运行什么?我尝试了命令行: Lex wordcount.l
但我只是没找到文件。
wordcount.l
%{
#include <stdlib.h>
#include <stdio.h>
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中,如何编译和运行这个程序?
发布于 2012-01-14 03:26:52
首先,您必须转到wordcount.l文件所在的目录中使用cd。然后使用lex wordcount.l将文件lex.yy.c。要运行该程序,需要使用c ++编译器(如gcc )编译它。使用gcc,您可以使用gcc -lfl lex.yy.c编译它。这将创建可以使用a.out运行的./a.out
发布于 2018-01-21 08:51:14
lex file.l
gcc lex.yy.c -ly -ll
./a.out这些也能用。我在Ubuntu14.04中使用这个。
https://stackoverflow.com/questions/8859710
复制相似问题