1

他の同様の投稿をチェックしましたが、もう 1 セットの目が必要だと思います。このファイルは、lex Unix ユーティリティ用です。

Makefile を作成しましたが、次のようなエラーが表示されます。

gcc -g -c lex.yy.c
cxref.l:57: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
make: *** [lex.yy.o] Error 1

Line 57void 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++;

}
4

1 に答える 1

1

あなたの問題は次のとおりです。

%s str

条件名を CAPS で書くのが普通であるのには理由があります: それはそれらをマクロのように見せます

そう

void insertId(char* str, int nLine)

マクロを次のように展開します。

void insertId(char* 2, int nLine)

2コンパイラは、宣言のその時点で実際には期待されていないと不平を言います。

于 2012-11-19T01:08:54.903 に答える