Question: Tokenize 1 . Start the program 2 . Include the header files. 3 . Allocate memory for the variable by dynamic memory allocation function. 4
Tokenize
Start the program
Include the header files.
Allocate memory for the variable by dynamic memory allocation function.
Use the file accessing functions to read the file.
Get the input file from the user.
Separate all the file contents as tokens and match it with the functions.
Define all the keywords in a separate file and name it as key.c
Define all the operators in a separate file and name it as open.c
Give the input program in a file and name it as input.c
Finally print the output after recognizing all the tokens.
Stop the program.
Program:
#include
#include
#include
#include
int main
FILE fifofopfk;
int flagi;
char ctachfile;
printf
Enter the File Name:";
scanfs&file;
fifopenfiler;
fofopenintercw;
fopfopenopercr;
fkfopenkeycr;
cgetcfi;
whilefeoffi
ifisalphacisdigitcccc
fputccfo;
else
ifc
fprintffot$t;
else fprintffotctc;
cgetcfi;
fclosefi;
fclosefo;
fifopenintercr;
printf
Lexical Analysis";
fscanffisa;
printf
Line: d
i;
whilefeoffi
ifstrcmpa$
printf
Line: d
i;
fscanffisa;
fscanffopsch;
whilefeoffop
ifstrcmpcha
fscanffopsch;
printfttst:ts
ach;
flag;
fscanffopsch;
rewindfop;
fscanffksch;
whilefeoffk
ifstrcmpcha
fscanffkkch;
printfttst:tKeyword
a;
flag;
fscanffksch;
rewindfk;
ifflag
ifisdigita
printfttst:tConstant
a;
else
printfttst:tIdentifier
a;
flag;
fscanffisa;
getch;
Input Files:
Oper.c
openpara
closepara
openbrace
closebrace
lesser
greater
doublequote
singlequote
: colon
; semicolon
# preprocessor
equal
asign
percentage
bitwise
& reference
star
add
sub
backslash
slash
Key.C
int
void
main
char
if
for
while
else
printf
scanf
FILE
Include
stdio.h
conio.h
iostream.h
Input.c
#include
#include
void main
int ab c;
abc;
getch;
Lab Assignment:
Find and fix the Lexical analysis errors in the code.
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
