1
我檢查了其他類似的帖子,但我想我只需要第二組眼睛。該文件用於lex Unix實用程序。lex program:error:expected';',','或')'在數字常量之前?
我創建了一個Makefile文件,這是我收到的錯誤:
gcc -g -c lex.yy.c
cxref.l:57: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
make: *** [lex.yy.o] Error 1
Line 57
只是在靠近頂端處void inserID()
函數內。
下面是代碼:
%{
#include <stdio.h>
#include <string.h>
char identifier[1000][82];
char linesFound[100][100];
void insertId(char*, int);
int i = 0;
int lineNum = 1;
%}
%x comment
%s str
%%
"/*" BEGIN(comment);
<comment>[^*\n]* /* eat anything that's not a '*' */
<comment>"*"+[^*/\n]* /* eat up '*'s not followed by '/'s */
<comment>\n ++lineNum;
<comment>"*"+"/" BEGIN(INITIAL);
"\n" ++lineNum;
auto ;
break ;
case ;
char ;
continue ;
default ;
do ;
double ;
else ;
extern ;
float ;
for ;
goto ;
if ;
int ;
long ;
register ;
return ;
short ;
sizeof ;
static ;
struct ;
switch ;
typedef ;
union ;
unsigned ;
void ;
while ;
[*]?[a-zA-Z][a-zA-Z0-9_]* insertId(yytext, lineNum);
[^a-zA-Z0-9_]+ ;
[0-9]+ ;
%%
void insertId(char* str, int nLine)
{
char num[2];
sprintf (num, "%d", nLine);
int iter;
for(iter = 0; iter <= i; iter++)
{
if (strcmp(identifier[iter], str) == 0)
{
strcat(linesFound[iter], ", ");
strcat(linesFound[iter], num);
return;
}
}
strcpy(identifier[i], str);
strcat(identifier[i], ": ");
strcpy(linesFound[i], num);
i++;
}