Question: Please help I have a project with Lexical analysis I m running Linux environment, WSL , Ubuntu, Flex, Bison, VSC . scanner.l file / *

Please help I have a project with Lexical analysis
Im running Linux environment, WSL, Ubuntu, Flex, Bison, VSC.
scanner.l file
/* This file contains flex input file */
%{
#include
#include
using namespace std;
#include "listing.h"
#include "tokens.h"
%}
%option noyywrap
ws [\t\r]+
comment "//".*
line [
]
id [A-Za-z]([A-Za-z0-9])*
digit [0-9]
dec {digit}+
char '.'
punc [\(\),:;]
%%
{ws}{ ECHO; }
{comment}{ ECHO; nextLine(); }
{line}{ ECHO; nextLine(); }
"+"{ ECHO; return(ADDOP); }
"*"{ ECHO; return(MULOP); }
"&"{ ECHO; return(ANDOP); }
"<"{ ECHO; return(RELOP); }
"=>"{ ECHO; return(ARROW); }
begin { ECHO; return(BEGIN_); }
case { ECHO; return(CASE); }
character { ECHO; return(CHARACTER); }
end { ECHO; return(END); }
endswitch { ECHO; return(ENDSWITCH); }
function { ECHO; return(FUNCTION); }
integer { ECHO; return(INTEGER); }
is { ECHO; return(IS); }
list { ECHO; return(LIST); }
of { ECHO; return(OF); }
others { ECHO; return(OTHERS); }
returns { ECHO; return(RETURNS); }
switch { ECHO; return(SWITCH); }
when { ECHO; return(WHEN); }
{id}{ ECHO; return(IDENTIFIER);}
{dec}{ ECHO; return(INT_LITERAL); }
{char}{ ECHO; return(CHAR_LITERAL); }
{punc}{ ECHO; return(yytext[0]); }
.{ ECHO; appendError(LEXICAL, yytext); }
%%
int main(){
firstLine();
FILE *file = fopen("lexemes.txt","wa");
int token = yylex();
while (token){
fprintf(file,"%d %s
", token, yytext);
token = yylex();
}
lastLine();
fclose(file);
return 0;
}
Makefile
# Makefile for CMSC 430 Project 1
# Compiler and flags
CXX = g++
CXXFLAGS =-std=c++11-Wall -g
# Source files
SOURCES = scanner.l
OBJECTS = lex.yy.o
# Output executable name
TARGET = compile
# Default target
all: $(TARGET)
# Rule to build the executable
$(TARGET): $(OBJECTS)
$(CXX) $(CXXFLAGS)-o $(TARGET) $(OBJECTS)
# Rule for compiling lex.yy.c from scanner.l
lex.yy.c: scanner.l
flex scanner.l
# Rule for compiling .o files from .cc files
%.o: %.cc
$(CXX) $(CXXFLAGS)-c $<
# Clean rule to remove generated files
clean:
rm -f $(TARGET) $(OBJECTS) lex.yy.c
# Phony targets
.PHONY: all clean
Output
jeannetteadorante@LAPTOP-CIB2C03C:~$ flex scanner.l
jeannetteadorante@LAPTOP-CIB2C03C:~$ g++-std=c++11-Wall -g -o compile lex.yy.c
lex.yy.c:1274:17: warning: void yyunput(int, char*) defined but not used [-Wunused-function]
1274| static void yyunput (int c, char * yy_bp )
|^~~~~~~
/usr/bin/ld: /tmp/ccPtvBLB.o: in function `yylex()':
/home/jeannetteadorante/scanner.l:32:(.text+0x341): undefined reference to `nextLine()'
/usr/bin/ld: /home/jeannetteadorante/scanner.l:33:(.text+0x375): undefined reference to `nextLine()'
/usr/bin/ld: /home/jeannetteadorante/scanner.l:58:(.text+0x88d): undefined reference to `appendError(ErrorCategories, std::__cxx11::basic_string, std::allocator >)'
/usr/bin/ld: /tmp/ccPtvBLB.o: in function `main':
/home/jeannetteadorante/scanner.l:62:(.text+0x23fa): undefined reference to `firstLine()'
/usr/bin/ld: /home/jeannetteadorante/scanner.l:70:(.text+0x2456): undefined reference to `lastLine()'
collect2: error: ld returned 1 exit status
jeannetteadorante@LAPTOP-CIB2C03C:~$ flex scanner.l
jeannetteadorante@LAPTOP-CIB2C03C:~$ g++-std=c++11-Wall -g -o compile lex.yy.c
lex.yy.c:1274:17: warning: void yyunput(int, char*) defined but not used [-Wunused-function]
1274| static void yyunput (int c, char * yy_bp )
|^~~~~~~
/usr/bin/ld: /tmp/ccV5zBuq.o: in function `yylex()':
/home/jeannetteadorante/scanner.l:32:(.text+0x341): undefined reference to `nextLine()'
/usr/bin/ld: /home/jeannetteadorante/scanner.l:33:(.text+0x375): undefined reference to `nextLine()'
/usr/bin/ld: /home/jeannetteadorante/scanner.l:58:(.text+0x88d): undefined reference to `appendError(ErrorCategories, std::__cxx11::basic_string, std::allocator >)'
/usr/bin/ld: /tmp/ccV5zBuq.o: in function `main':
/home/jeannetteadorante/scanner.l:62:(.text+0x23fa): undefined reference to `firstLine()'
/usr/bin/ld: /home/jeannetteadorante/scanner.l:70:(.text+0x2456): undefined reference to `lastLine()'
collect2: error: ld returned 1 exit status
jeannetteadorante@LAPTOP-CIB2C03C:~$ --config gcc
--config: command not found

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!