Reputation: 21
I want to make code scanner and parser but I don't know why this error happens just by looking at the error log. The scanner takes the sample code and divides it into tokens, then returns what each of the tokens in the code is doing.The parser receives the values returned from the scanner and parses the code according to the rules. It checks validity of grammar of sample code.
and finally this my error
lex.yy.o: In function main:
lex.yy.c:(.text+0x1d2a): multiple definition of main
y.tab.o:y.tab.c:(.text+0x861): first defined here
collect2: error: ld returned 1 exit status
Upvotes: 2
Views: 2130
Reputation: 241921
You have defined main
in both your files, but C only allows a single definition of main
in a program, which is what the linker error is telling you.
The main
in your scanner file has an invalid prototype (C hasn't allowed function definitions without a return type for almost 20 years) and also calls yylex
only once, which is not going to do much. So it seems pretty well pointless. If you want to debug your scanner without using the parser,byou can link the scanner with -lfl
; that library includes a definition of main
which repeatedly calls yylex
until end of file is signalled.
Instead of scattering printf
calls through your scanner, you can just build a debugging version of the scanner using the --debug
flag when you generate the scanner. That will print out a trace of all scanner actions.
Upvotes: 2