Compiler construction lex使用flex-gettin从lex.yy.c文件输出

Compiler construction lex使用flex-gettin从lex.yy.c文件输出,compiler-construction,compiler-errors,lex,lexical-analysis,Compiler Construction,Compiler Errors,Lex,Lexical Analysis,我已经为行计数和字符计数编写了一个lex程序.l文件 节目: 我使用flex bison和代码块 在编写程序之后 我用flex-lccc命令执行它。l lccc是文件名 现在我有了lex.yy.c文件 请告诉我如何获得输出 编译lex.yy.c时出错。。但是这个程序在我大学的linux上运行得很好,在家里我在windows上使用了上面提到的调整。。请帮忙 这就是错误: J:\> gcc lex.yy.c lccc.l: In function 'main': lccc.l:13:

我已经为行计数和字符计数编写了一个lex程序.l文件 节目:

我使用flex bison和代码块 在编写程序之后 我用flex-lccc命令执行它。l lccc是文件名 现在我有了lex.yy.c文件 请告诉我如何获得输出 编译lex.yy.c时出错。。但是这个程序在我大学的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

您需要将自定义代码括在大括号中。后面没有分号:charcount++并且不能用逗号分隔语句,所以linecount++,charcount++;应该是linecount++;charcount++

试试这个:

%{ int charcount=0,linecount=0; %} %% . {charcount++;} \n{linecount++;charcount++;} %% 主要的 { yylex; 打印行数%d,行数; printfcharacters%d,字符数; } // ...
给出什么错误?你不能从你的问题中忽略重要的信息,而理性地期望得到答案。试着阅读以下帖子:@Dr Beco我从你的建议开始,先生。。否则我根本就没有弹性。。谢谢你的来信,真的很管用,先生!!我为这些愚蠢的错误感到抱歉。。我们有一个非常糟糕的先生,他对这个问题一无所知。。但是先生,没有yy wrap,它说有一个未定义的引用yywrap。。然后当我把它包括进去。。它起作用了。。但是输出并不像预期的那样。。。我只是不停地输入文字,而且它一直在。。它不显示行数和字符数
 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