lex 使用 lex.yy.c 文件中的 flex -gettin 输出
我写了一个 lex 程序(.l 文件)用于行计数和字符计数 程序:
%{
int charcount=0,linecount=0;
%}
%%
.charcount++
\n linecount++,charcount++;
%%
main()
{
yylex();
printf(“lines %d”,linecount);
printf(“characters %d”,charcount);
}
int yywrap()
{
return 1;
}
我使用 flex bison 和 codeblocks 写完程序后 我使用命令 flex lccc.l 执行它(lccc 是文件名) 现在我有 lex.yy.c 文件 请告诉我如何获得输出 编译 lex.yy.c 是 igivng 和错误..但是这个程序在我大学的 Linux 上运行良好,在家里我在 Windows 上使用上述调整..请帮忙!
这是错误:
J:\> gcc lex.yy.c
lccc.l: In function 'main':
lccc.l:13: error: stray'\223' in program
lccc.l:13: error: 'lines' undeclared (first use in this function )
lccc.l:13: error: (Each undeclared identifier is reported only once
lccc.l:13: error: for each function it appears in. )
lccc.l:13: error: stray'\224' in program
lccc.l:13: error: 'd' undeclared (first use in this function )
lccc.l:14: error: stray'\223' in program
lccc.l:14: error: 'characters' undeclared (first use in this function )
lccc.l:14: error: stray'\224' in program
i have written a lex program ( .l file ) for line count and character count
PROGRAM:
%{
int charcount=0,linecount=0;
%}
%%
.charcount++
\n linecount++,charcount++;
%%
main()
{
yylex();
printf(“lines %d”,linecount);
printf(“characters %d”,charcount);
}
int yywrap()
{
return 1;
}
i use flex bison and codeblocks
after writing the program
i executed it with the command flex lccc.l (lccc is the file name)
now i have lex.yy.c file
please tell me how do i get the output
compiling lex.yy.c is igivng and error.. but this program works fine on linux which is at my college, at home i use the above mentioned tweaks on windows.. please help!
this is the error :
J:\> gcc lex.yy.c
lccc.l: In function 'main':
lccc.l:13: error: stray'\223' in program
lccc.l:13: error: 'lines' undeclared (first use in this function )
lccc.l:13: error: (Each undeclared identifier is reported only once
lccc.l:13: error: for each function it appears in. )
lccc.l:13: error: stray'\224' in program
lccc.l:13: error: 'd' undeclared (first use in this function )
lccc.l:14: error: stray'\223' in program
lccc.l:14: error: 'characters' undeclared (first use in this function )
lccc.l:14: error: stray'\224' in program
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将自定义代码括在大括号中。并且后面没有分号:
charcount++
and 不能用逗号分隔语句,因此linecount++, charcount++;
应该是行数++; charcount++;
。试试这个:
You need to enclose custom code in braces. And there's no semi-colon after:
charcount++
and you can't separate statements with a comma, solinecount++, charcount++;
should belinecount++; charcount++;
.Try this: