-3

I'm attempting to parse one input file .l file with flex, but I'm having trouble constructing my program. I've included my flex code as well as the problem I'm getting.

.l file:

%{
#include "main.tab.h"
%}

%%
[ \t\n]          /* ignore whitespace */
"MATCH"          { return MATCH; }
"RETURN"         { return RETURN; }
"-"              { return DASH; }
"("              { return LPAREN; }
")"              { return RPAREN; }
"["              { return LBRACKET; }
"]"              { return RBRACKET; }
[uv]             { return VARIABLE; }
%%
int yywrap(void) {
    return 1;
}

Error:

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
collect2: error: ld returned 1 exit status

Error Message on terminal

Piotr Siupa
  • 3,929
  • 2
  • 29
  • 65
  • 2
    `gcc -c lex.yy.c` unless you want it to be the only source file for your program, in which case it needs a `main()`. – Shawn Apr 17 '23 at 21:02
  • i tried using command using mentioned but it gives error saying " fatal error: main.tab.h no such file or directory " – fatima raza Apr 17 '23 at 21:33
  • Did you generate the `main.tab.h` header with `bison -d filename.y` ? – Carla Apr 25 '23 at 00:25

1 Answers1

-1

It seems the error is the main.tab.h file. You could try to create it with the code:

bison -d blah.y

Then try gcc -c lex.yy.c. You should provide more context so that I can assist you further.

Wendel
  • 763
  • 1
  • 12