2012-11-17 78 views
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++; 

} 

回答

1

您的问题是:

%s str 

是有原因的,这是正常的CAPS写状态的名字:它使它们看起来像宏,这是究竟是什么

所以

void insertId(char* str, int nLine) 

获得宏扩展到了类似:

void insertId(char* 2, int nLine) 

和编译器抱怨2是不是真的有望在声明这一点。

相关问题