현재 Lex 유틸리티를 사용하여 C 프로그램을 읽으려고하고 예약 된 C 단어가 아닌 모든 단어의 줄 항목을 표시하려고합니다. 나는 'yyin' 'yyout' 'yylex' 'yy_create_buffer'등의 다중 정의를 말하는 거대한 오류 목록을 실행 중입니다 ...Lex를 사용하여 문자열 발생 수 계산, 메이크 파일의 가능한 문제
현재 내 makefile에 문제가있는 것처럼 느껴질 수 있습니다. 또한 코드. 도움을 주시면 감사하겠습니다.
내 코드 : 여기
#include <string.h>
char currentLines[20][80];
char identifier[1000][80];
void foundWord(char *, int);
int numLine = 1;
%}
%s newStr
%x BLOCK
%%
"/*" BEGIN(BLOCK);
<BLOCK>[^*\n]*
<BLOCK>"*"+[^*/\n]*
<BLOCK>\n ++numLine;
<BLOCK>"*"+"/" BEGIN(INITIAL);
"\n" ++numLine;
auto ;
break ;
case ; //full list of reserved words...
[*]?[a-zA-Z][a-zA-Z0-9_]* foundWord(yytext, numLine);
[^a-zA-Z0-9_]+ ;
[0-9]+ ;
%%
void foundWord(char* newStr, int nLine)
{
char num[10];
sprintf (newStr, "%d", nLine);
int i;
for(i = 0; i <= 20; i++)
{
if (strcmp(identifier[i], newStr) == 0)
{
strcat(currentLines[i], ", ");
strcat(currentLines[i], num);
return;
}
}
strcpy(identifier[i], newStr);
strcat(identifier[i], ": ");
strcpy(currentLines[i], num);
}
그리고는 렉스 라이브러리 'C_words.l를'연결을 시도 내가 쓴 메이크입니다.
이것은 입력 파일입니다.
#include <stdio.h>
void main()
{
int m,n;
printf("Enter the values for M and N\n");
scanf("%d %d", &m,&n);
if(m == n)
printf("M and N are equal\n");
else
printf("M and N are not equal\n");
}
'yywrap의 다중 정의'를 처리 한 것처럼 보입니다.하지만 여전히 많은 오류 목록이 있습니다. – Nicktard