函数 'yyparse()' 中对 'yylex' 的未定义引用

Undefined reference to 'yylex' in function 'yyparse()'

每次我尝试解决问题时都会收到此错误。我不知道我做错了什么。这是我的 yacc 文件和我的 lexx 文件:

这是我的 YFILE.Y

%{

#include <iostream>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define YYSTYPE double
#include "y.tab.h"
extern "C" FILE * yyin;
extern "C" int yylex();
extern int yyparse(void *);
using namespace std;
int yyerror(const char* s);
%}



%token DIGIT CHARACTER OP LEFT_PAR RIGHT_PAR SEMICOLON EQUAL NEWLINE OTHER

%union{
        char *s;
}


%%

assignment:
            id EQUAL expression SEMICOLON NEWLINE
                ;
expression:
            id OP id '{OP id}'
                | id OP id '{'LEFT_PAR'}' '{'expression'}' '{'RIGHT_PAR'}' NEWLINE
                | id OP id '{'LEFT_PAR expression'}' '{'RIGHT_PAR'}' NEWLINE
                ;
id:
                CHARACTER
                |id CHARACTER
                |id DIGIT
                ;
%%



int yyerror(const char *s)
{
        cout <<"error" << s << endl;
        return -1;
}

main (){
        FILE *yyin  = fopen("ex.txt","r");
        yyparse();
        fclose(yyin);

        printf("hi");
        return 0;
}

这是我的 GRAMMARRULES.L

%{
#include "y.tab.h"
#include <stdio.h>
#define YY_DECL extern "C" int yylex()
using namespace std;
#include <iostream>
void ERROR();
%}


digit [0-9]+
char [a-zA-Z]
op [+\-*/%]


%%
{digit} {return (DIGIT);}
{char}  {return (CHARACTER);}
{op}    {return (OP);}
"("     {return (LEFT_PAR);}
")"     {return (RIGHT_PAR);}
"="     {return (EQUAL);}
";"     {return (SEMICOLON);}
"\n"    {return (NEWLINE);}
.   {return (OTHER);}


%%

void ERROR(){
    cout << OTHER <<endl;
}

我有语法规则,但在 'yyparse()'

中收到对 'yylex' 未定义引用的错误

如果您遇到此问题,yacc 和 lex 文件必须同名。例如 snazzle.l 和 snazzle.y.