Every time I try to fix the issue I get this error. I don't know what I'm doing wrong. Here is my yacc file and my lexx file:
HERE IS MY 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;
}
HERE IS MY 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;
}
I have grammar rules and am getting the error undefined reference to 'yylex' in 'yyparse()'
If you're having this issue, both yacc and lex files must be the same name. For example snazzle.l and snazzle.y.