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 tr
comment
line
id AZazAZaz
digit
dec digit
char
punc :;
ws ECHO;
comment ECHO; nextLine;
line ECHO; nextLine;
ECHO; returnADDOP;
ECHO; returnMULOP;
& ECHO; returnANDOP;
ECHO; returnRELOP;
ECHO; returnARROW;
begin ECHO; returnBEGIN;
case ECHO; returnCASE;
character ECHO; returnCHARACTER;
end ECHO; returnEND;
endswitch ECHO; returnENDSWITCH;
function ECHO; returnFUNCTION;
integer ECHO; returnINTEGER;
is ECHO; returnIS;
list ECHO; returnLIST;
of ECHO; returnOF;
others ECHO; returnOTHERS;
returns ECHO; returnRETURNS;
switch ECHO; returnSWITCH;
when ECHO; returnWHEN;
id ECHO; returnIDENTIFIER;
dec ECHO; returnINTLITERAL;
char ECHO; returnCHARLITERAL;
punc ECHO; returnyytext;
ECHO; appendErrorLEXICAL yytext;
int main
firstLine;
FILE file fopenlexemestxtwa;
int token yylex;
while token
fprintffiled s
token, yytext;
token yylex;
lastLine;
fclosefile;
return ;
Makefile
# Makefile for CMSC Project
# Compiler and flags
CXX g
CXXFLAGS stdcWall g
# Source files
SOURCES scanner.l
OBJECTS lex.yyo
# Output executable name
TARGET compile
# Default target
all: $TARGET
# Rule to build the executable
$TARGET: $OBJECTS
$CXX $CXXFLAGSo $TARGET $OBJECTS
# Rule for compiling lex.yyc from scanner.l
lex.yyc: scanner.l
flex scanner.l
# Rule for compiling o files from cc files
o: cc
$CXX $CXXFLAGSc $
# Clean rule to remove generated files
clean:
rm f $TARGET $OBJECTS lex.yyc
# Phony targets
PHONY: all clean
Output
jeannetteadorante@LAPTOPCIBCC:~$ flex scanner.l
jeannetteadorante@LAPTOPCIBCC:~$ gstdcWall g o compile lex.yyc
lex.yyc::: warning: void yyunputint char defined but not used Wunusedfunction
static void yyunput int c char yybp
~~~~~~
usrbinld: tmpccPtvBLBo: in function yylex:
homejeannetteadorantescannerl::textx: undefined reference to nextLine
usrbinld: homejeannetteadorantescannerl::textx: undefined reference to nextLine
usrbinld: homejeannetteadorantescannerl::textxd: undefined reference to appendErrorErrorCategories std::cxx::basicstring, std::allocator
usrbinld: tmpccPtvBLBo: in function main:
homejeannetteadorantescannerl::textxfa: undefined reference to firstLine
usrbinld: homejeannetteadorantescannerl::textx: undefined reference to lastLine
collect: error: ld returned exit status
jeannetteadorante@LAPTOPCIBCC:~$ flex scanner.l
jeannetteadorante@LAPTOPCIBCC:~$ gstdcWall g o compile lex.yyc
lex.yyc::: warning: void yyunputint char defined but not used Wunusedfunction
static void yyunput int c char yybp
~~~~~~
usrbinld: tmpccVzBuq.o: in function yylex:
homejeannetteadorantescannerl::textx: undefined reference to nextLine
usrbinld: homejeannetteadorantescannerl::textx: undefined reference to nextLine
usrbinld: homejeannetteadorantescannerl::textxd: undefined reference to appendErrorErrorCategories std::cxx::basicstring, std::allocator
usrbinld: tmpccVzBuq.o: in function main:
homejeannetteadorantescannerl::textxfa: undefined reference to firstLine
usrbinld: homejeannetteadorantescannerl::textx: undefined reference to lastLine
collect: error: ld returned exit status
jeannetteadorante@LAPTOPCIBCC:~$ config gcc
config: command not found
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
