SlideShare une entreprise Scribd logo
1  sur  3
Télécharger pour lire hors ligne
Below is a C code that serves as a handwritten lexical analyzer on a very small scale. Please
type it and run it. It does the following:
(a) identifies some key words
(b) Identifies identifiers (variable names) as well as special characters
(c) identifies numbers ( I think there is a little bit of a problem with this part, and maybe you can
fix it.)
(d) counts the number of lines in the input.
When you compile it, you will be asked to enter the input. Please enter a combination of items
that I described above. For example" while acb 78 4+6 sum". Try to input at least 3 lines making
sure you press the enter key to go to the next line AND, at the end of the input after the last
Enter, press CTL-D to signal the end of the input.
1. Modify the code to also take care of the relational mathematical operators (<, >, <=, >=, <>).
You will note that in the same code, the output is written in separate files.
2. Make sure the relational operators to also be written on a special file.
C CODE:
#include
#include
#include
void keyword(char str[10])
{
if(strcmp("for",str)==0||strcmp("while",str)==0||strcmp("do",str)==0||strcmp("int",
str
)==0||strcmp("float",str)==0||strcmp("char",str)==0||strcmp("double",str)==0||strcmp("static",str)
==0||strcmp("switc
h",str)==0||strcmp("case",str)==0)
printf("n%s is a keyword",str);
else
printf("n%s is an identifier",str);
}
main()
{
FILE *f1,*f2,*f3;
char c, str[10], st1[10];
int num[100], lineno=0, tokenvalue=0,i=0,j=0,k=0;
printf("n Enter the input in the program. Input at least 3 lines by pressing Enter at the end of
each line. When done,
press CTRL+D: ");/*gets(st1);*/
f1=fopen("input","w");
while((c=getchar())!=EOF)
putc(c,f1);
fclose(f1);
f1=fopen("input","r");
f2=fopen("identifier","w");
f3=fopen("specialchar","w");
while((c=getc(f1))!=EOF)
{
if(isdigit(c))
{
tokenvalue=c-'0';
c=getc(f1);
while(isdigit(c))
{
tokenvalue*=10+c-'0';
c=getc(f1);
}
num[i++]=tokenvalue;
ungetc(c,f1);
}
else
if(isalpha(c))
{
putc(c,f2);
c=getc(f1);
while(isdigit(c)||isalpha(c)||c=='_'||c=='$')
{
putc(c,f2);
c=getc(f1);
}
putc(' ',f2);
ungetc(c,f1);
}
else
if(c==' '||c=='t')
printf(" ");
else
if(c=='n')
lineno++;
else
putc(c,f3);
}
fclose(f2);
fclose(f3);
fclose(f1);
printf("n The no's in the program are :");
for(j=0; j

Contenu connexe

Similaire à Below is a C code that serves as a handwritten lexical analyzer on a.pdf

Traduccion a ensamblador
Traduccion a ensambladorTraduccion a ensamblador
Traduccion a ensambladortre_na_gil
 
COMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docx
COMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docxCOMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docx
COMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docxdonnajames55
 
A nice 64-bit error in C
A  nice 64-bit error in CA  nice 64-bit error in C
A nice 64-bit error in CPVS-Studio
 
Bsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c languageBsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c languageRai University
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c languageRai University
 
Mca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageMca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageRai University
 
Btech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageBtech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageRai University
 
C PROGRAMMING LANGUAGE.pptx
 C PROGRAMMING LANGUAGE.pptx C PROGRAMMING LANGUAGE.pptx
C PROGRAMMING LANGUAGE.pptxAnshSrivastava48
 
Diploma ii cfpc u-2 datatypes and variables in c language
Diploma ii  cfpc u-2 datatypes and variables in c languageDiploma ii  cfpc u-2 datatypes and variables in c language
Diploma ii cfpc u-2 datatypes and variables in c languageRai University
 
Programming in C - interview questions.pdf
Programming in C - interview questions.pdfProgramming in C - interview questions.pdf
Programming in C - interview questions.pdfSergiuMatei7
 
C presentation book
C presentation bookC presentation book
C presentation bookkrunal1210
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21chinthala Vijaya Kumar
 
C Introduction and bascis of high level programming
C Introduction and bascis of high level programmingC Introduction and bascis of high level programming
C Introduction and bascis of high level programmingvipulkondekar
 

Similaire à Below is a C code that serves as a handwritten lexical analyzer on a.pdf (20)

Traduccion a ensamblador
Traduccion a ensambladorTraduccion a ensamblador
Traduccion a ensamblador
 
COMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docx
COMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docxCOMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docx
COMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docx
 
Getting Started with C++
Getting Started with C++Getting Started with C++
Getting Started with C++
 
1 Revision Tour
1 Revision Tour1 Revision Tour
1 Revision Tour
 
A nice 64-bit error in C
A  nice 64-bit error in CA  nice 64-bit error in C
A nice 64-bit error in C
 
Bsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c languageBsc cs i pic u-2 datatypes and variables in c language
Bsc cs i pic u-2 datatypes and variables in c language
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
Mca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c languageMca i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c language
 
Btech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageBtech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c language
 
C PROGRAMMING LANGUAGE.pptx
 C PROGRAMMING LANGUAGE.pptx C PROGRAMMING LANGUAGE.pptx
C PROGRAMMING LANGUAGE.pptx
 
Getting started with C++
Getting started with C++Getting started with C++
Getting started with C++
 
Diploma ii cfpc u-2 datatypes and variables in c language
Diploma ii  cfpc u-2 datatypes and variables in c languageDiploma ii  cfpc u-2 datatypes and variables in c language
Diploma ii cfpc u-2 datatypes and variables in c language
 
Programming in C - interview questions.pdf
Programming in C - interview questions.pdfProgramming in C - interview questions.pdf
Programming in C - interview questions.pdf
 
C language tutorial
C language tutorialC language tutorial
C language tutorial
 
C Programming
C ProgrammingC Programming
C Programming
 
C presentation book
C presentation bookC presentation book
C presentation book
 
C++
C++C++
C++
 
C programming language
C programming languageC programming language
C programming language
 
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
 
C Introduction and bascis of high level programming
C Introduction and bascis of high level programmingC Introduction and bascis of high level programming
C Introduction and bascis of high level programming
 

Plus de alankarshoe84

Bir proje y�neticisi, paydalarn yeni bir proje i�in farkl beklentile.pdf
Bir proje y�neticisi, paydalarn yeni bir proje i�in farkl beklentile.pdfBir proje y�neticisi, paydalarn yeni bir proje i�in farkl beklentile.pdf
Bir proje y�neticisi, paydalarn yeni bir proje i�in farkl beklentile.pdfalankarshoe84
 
Bir banka dekontu A. irketin hesap bakiyesini artran veya azaltan .pdf
Bir banka dekontu A. irketin hesap bakiyesini artran veya azaltan .pdfBir banka dekontu A. irketin hesap bakiyesini artran veya azaltan .pdf
Bir banka dekontu A. irketin hesap bakiyesini artran veya azaltan .pdfalankarshoe84
 
Bir aratrmac, korku filmleri izlerken insanlarn fizyolojik tepkileri.pdf
Bir aratrmac, korku filmleri izlerken insanlarn fizyolojik tepkileri.pdfBir aratrmac, korku filmleri izlerken insanlarn fizyolojik tepkileri.pdf
Bir aratrmac, korku filmleri izlerken insanlarn fizyolojik tepkileri.pdfalankarshoe84
 
Bilgisayar yerine cep telefonlar, tbbi cihazlar ve t�ketici elektron.pdf
Bilgisayar yerine cep telefonlar, tbbi cihazlar ve t�ketici elektron.pdfBilgisayar yerine cep telefonlar, tbbi cihazlar ve t�ketici elektron.pdf
Bilgisayar yerine cep telefonlar, tbbi cihazlar ve t�ketici elektron.pdfalankarshoe84
 
Beyond the miners, their families, investors and the Peruvian govern.pdf
Beyond the miners, their families, investors and the Peruvian govern.pdfBeyond the miners, their families, investors and the Peruvian govern.pdf
Beyond the miners, their families, investors and the Peruvian govern.pdfalankarshoe84
 
Better technology in one country results in Multiple Choice a countr.pdf
Better technology in one country results in Multiple Choice a countr.pdfBetter technology in one country results in Multiple Choice a countr.pdf
Better technology in one country results in Multiple Choice a countr.pdfalankarshoe84
 
Bernard Lawrence Bernie Madoff was an American financier who execu.pdf
Bernard Lawrence Bernie Madoff was an American financier who execu.pdfBernard Lawrence Bernie Madoff was an American financier who execu.pdf
Bernard Lawrence Bernie Madoff was an American financier who execu.pdfalankarshoe84
 
Berger y Luckmann afirman que nacemos en una estructura social obje.pdf
Berger y Luckmann afirman que nacemos en una estructura social obje.pdfBerger y Luckmann afirman que nacemos en una estructura social obje.pdf
Berger y Luckmann afirman que nacemos en una estructura social obje.pdfalankarshoe84
 
Ben - Satisfy the individuals need for affiliation Analyse-Develop,.pdf
Ben - Satisfy the individuals need for affiliation Analyse-Develop,.pdfBen - Satisfy the individuals need for affiliation Analyse-Develop,.pdf
Ben - Satisfy the individuals need for affiliation Analyse-Develop,.pdfalankarshoe84
 
C Programming LanguageHello can i please get help understanding ho.pdf
C Programming LanguageHello can i please get help understanding ho.pdfC Programming LanguageHello can i please get help understanding ho.pdf
C Programming LanguageHello can i please get help understanding ho.pdfalankarshoe84
 
C Language PLEASE Write a C program that inputs a line of text.pdf
C Language PLEASE Write a C program that inputs a line of text.pdfC Language PLEASE Write a C program that inputs a line of text.pdf
C Language PLEASE Write a C program that inputs a line of text.pdfalankarshoe84
 
C Language PLEASE Write a C program to create a dynamic array. T.pdf
C Language PLEASE Write a C program to create a dynamic array. T.pdfC Language PLEASE Write a C program to create a dynamic array. T.pdf
C Language PLEASE Write a C program to create a dynamic array. T.pdfalankarshoe84
 
B�y�k bir kuruluta, dahili veri kaynaklarnn y�netimine y�nelik polit.pdf
B�y�k bir kuruluta, dahili veri kaynaklarnn y�netimine y�nelik polit.pdfB�y�k bir kuruluta, dahili veri kaynaklarnn y�netimine y�nelik polit.pdf
B�y�k bir kuruluta, dahili veri kaynaklarnn y�netimine y�nelik polit.pdfalankarshoe84
 
C language in visual studios with comments1) use standard inputou.pdf
C language in visual studios with comments1) use standard inputou.pdfC language in visual studios with comments1) use standard inputou.pdf
C language in visual studios with comments1) use standard inputou.pdfalankarshoe84
 
B�t�elerle ilgili olarak aadaki ifadelerden hangisi doru DELDR A..pdf
B�t�elerle ilgili olarak aadaki ifadelerden hangisi doru DELDR A..pdfB�t�elerle ilgili olarak aadaki ifadelerden hangisi doru DELDR A..pdf
B�t�elerle ilgili olarak aadaki ifadelerden hangisi doru DELDR A..pdfalankarshoe84
 
Below is my code for a line editor import java.io.BufferedReader;.pdf
Below is my code for a line editor import java.io.BufferedReader;.pdfBelow is my code for a line editor import java.io.BufferedReader;.pdf
Below is my code for a line editor import java.io.BufferedReader;.pdfalankarshoe84
 
B�l�m B � Nehir Sistemlerine Genel Bak Nehirler ve akarsular bir d.pdf
B�l�m B � Nehir Sistemlerine Genel Bak Nehirler ve akarsular bir d.pdfB�l�m B � Nehir Sistemlerine Genel Bak Nehirler ve akarsular bir d.pdf
B�l�m B � Nehir Sistemlerine Genel Bak Nehirler ve akarsular bir d.pdfalankarshoe84
 
business information systems (a). Explain three opportunities and.pdf
business information systems  (a). Explain three opportunities and.pdfbusiness information systems  (a). Explain three opportunities and.pdf
business information systems (a). Explain three opportunities and.pdfalankarshoe84
 
business information systems 1. Explain the five components of an.pdf
business information systems  1. Explain the five components of an.pdfbusiness information systems  1. Explain the five components of an.pdf
business information systems 1. Explain the five components of an.pdfalankarshoe84
 
Buenaventura B�y�me, Perunun �nde gelen madencilik irketi ve d�ny.pdf
Buenaventura B�y�me, Perunun �nde gelen madencilik irketi ve d�ny.pdfBuenaventura B�y�me, Perunun �nde gelen madencilik irketi ve d�ny.pdf
Buenaventura B�y�me, Perunun �nde gelen madencilik irketi ve d�ny.pdfalankarshoe84
 

Plus de alankarshoe84 (20)

Bir proje y�neticisi, paydalarn yeni bir proje i�in farkl beklentile.pdf
Bir proje y�neticisi, paydalarn yeni bir proje i�in farkl beklentile.pdfBir proje y�neticisi, paydalarn yeni bir proje i�in farkl beklentile.pdf
Bir proje y�neticisi, paydalarn yeni bir proje i�in farkl beklentile.pdf
 
Bir banka dekontu A. irketin hesap bakiyesini artran veya azaltan .pdf
Bir banka dekontu A. irketin hesap bakiyesini artran veya azaltan .pdfBir banka dekontu A. irketin hesap bakiyesini artran veya azaltan .pdf
Bir banka dekontu A. irketin hesap bakiyesini artran veya azaltan .pdf
 
Bir aratrmac, korku filmleri izlerken insanlarn fizyolojik tepkileri.pdf
Bir aratrmac, korku filmleri izlerken insanlarn fizyolojik tepkileri.pdfBir aratrmac, korku filmleri izlerken insanlarn fizyolojik tepkileri.pdf
Bir aratrmac, korku filmleri izlerken insanlarn fizyolojik tepkileri.pdf
 
Bilgisayar yerine cep telefonlar, tbbi cihazlar ve t�ketici elektron.pdf
Bilgisayar yerine cep telefonlar, tbbi cihazlar ve t�ketici elektron.pdfBilgisayar yerine cep telefonlar, tbbi cihazlar ve t�ketici elektron.pdf
Bilgisayar yerine cep telefonlar, tbbi cihazlar ve t�ketici elektron.pdf
 
Beyond the miners, their families, investors and the Peruvian govern.pdf
Beyond the miners, their families, investors and the Peruvian govern.pdfBeyond the miners, their families, investors and the Peruvian govern.pdf
Beyond the miners, their families, investors and the Peruvian govern.pdf
 
Better technology in one country results in Multiple Choice a countr.pdf
Better technology in one country results in Multiple Choice a countr.pdfBetter technology in one country results in Multiple Choice a countr.pdf
Better technology in one country results in Multiple Choice a countr.pdf
 
Bernard Lawrence Bernie Madoff was an American financier who execu.pdf
Bernard Lawrence Bernie Madoff was an American financier who execu.pdfBernard Lawrence Bernie Madoff was an American financier who execu.pdf
Bernard Lawrence Bernie Madoff was an American financier who execu.pdf
 
Berger y Luckmann afirman que nacemos en una estructura social obje.pdf
Berger y Luckmann afirman que nacemos en una estructura social obje.pdfBerger y Luckmann afirman que nacemos en una estructura social obje.pdf
Berger y Luckmann afirman que nacemos en una estructura social obje.pdf
 
Ben - Satisfy the individuals need for affiliation Analyse-Develop,.pdf
Ben - Satisfy the individuals need for affiliation Analyse-Develop,.pdfBen - Satisfy the individuals need for affiliation Analyse-Develop,.pdf
Ben - Satisfy the individuals need for affiliation Analyse-Develop,.pdf
 
C Programming LanguageHello can i please get help understanding ho.pdf
C Programming LanguageHello can i please get help understanding ho.pdfC Programming LanguageHello can i please get help understanding ho.pdf
C Programming LanguageHello can i please get help understanding ho.pdf
 
C Language PLEASE Write a C program that inputs a line of text.pdf
C Language PLEASE Write a C program that inputs a line of text.pdfC Language PLEASE Write a C program that inputs a line of text.pdf
C Language PLEASE Write a C program that inputs a line of text.pdf
 
C Language PLEASE Write a C program to create a dynamic array. T.pdf
C Language PLEASE Write a C program to create a dynamic array. T.pdfC Language PLEASE Write a C program to create a dynamic array. T.pdf
C Language PLEASE Write a C program to create a dynamic array. T.pdf
 
B�y�k bir kuruluta, dahili veri kaynaklarnn y�netimine y�nelik polit.pdf
B�y�k bir kuruluta, dahili veri kaynaklarnn y�netimine y�nelik polit.pdfB�y�k bir kuruluta, dahili veri kaynaklarnn y�netimine y�nelik polit.pdf
B�y�k bir kuruluta, dahili veri kaynaklarnn y�netimine y�nelik polit.pdf
 
C language in visual studios with comments1) use standard inputou.pdf
C language in visual studios with comments1) use standard inputou.pdfC language in visual studios with comments1) use standard inputou.pdf
C language in visual studios with comments1) use standard inputou.pdf
 
B�t�elerle ilgili olarak aadaki ifadelerden hangisi doru DELDR A..pdf
B�t�elerle ilgili olarak aadaki ifadelerden hangisi doru DELDR A..pdfB�t�elerle ilgili olarak aadaki ifadelerden hangisi doru DELDR A..pdf
B�t�elerle ilgili olarak aadaki ifadelerden hangisi doru DELDR A..pdf
 
Below is my code for a line editor import java.io.BufferedReader;.pdf
Below is my code for a line editor import java.io.BufferedReader;.pdfBelow is my code for a line editor import java.io.BufferedReader;.pdf
Below is my code for a line editor import java.io.BufferedReader;.pdf
 
B�l�m B � Nehir Sistemlerine Genel Bak Nehirler ve akarsular bir d.pdf
B�l�m B � Nehir Sistemlerine Genel Bak Nehirler ve akarsular bir d.pdfB�l�m B � Nehir Sistemlerine Genel Bak Nehirler ve akarsular bir d.pdf
B�l�m B � Nehir Sistemlerine Genel Bak Nehirler ve akarsular bir d.pdf
 
business information systems (a). Explain three opportunities and.pdf
business information systems  (a). Explain three opportunities and.pdfbusiness information systems  (a). Explain three opportunities and.pdf
business information systems (a). Explain three opportunities and.pdf
 
business information systems 1. Explain the five components of an.pdf
business information systems  1. Explain the five components of an.pdfbusiness information systems  1. Explain the five components of an.pdf
business information systems 1. Explain the five components of an.pdf
 
Buenaventura B�y�me, Perunun �nde gelen madencilik irketi ve d�ny.pdf
Buenaventura B�y�me, Perunun �nde gelen madencilik irketi ve d�ny.pdfBuenaventura B�y�me, Perunun �nde gelen madencilik irketi ve d�ny.pdf
Buenaventura B�y�me, Perunun �nde gelen madencilik irketi ve d�ny.pdf
 

Dernier

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationNeilDeclaro1
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 

Dernier (20)

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 

Below is a C code that serves as a handwritten lexical analyzer on a.pdf

  • 1. Below is a C code that serves as a handwritten lexical analyzer on a very small scale. Please type it and run it. It does the following: (a) identifies some key words (b) Identifies identifiers (variable names) as well as special characters (c) identifies numbers ( I think there is a little bit of a problem with this part, and maybe you can fix it.) (d) counts the number of lines in the input. When you compile it, you will be asked to enter the input. Please enter a combination of items that I described above. For example" while acb 78 4+6 sum". Try to input at least 3 lines making sure you press the enter key to go to the next line AND, at the end of the input after the last Enter, press CTL-D to signal the end of the input. 1. Modify the code to also take care of the relational mathematical operators (<, >, <=, >=, <>). You will note that in the same code, the output is written in separate files. 2. Make sure the relational operators to also be written on a special file. C CODE: #include #include #include void keyword(char str[10]) { if(strcmp("for",str)==0||strcmp("while",str)==0||strcmp("do",str)==0||strcmp("int", str )==0||strcmp("float",str)==0||strcmp("char",str)==0||strcmp("double",str)==0||strcmp("static",str) ==0||strcmp("switc h",str)==0||strcmp("case",str)==0) printf("n%s is a keyword",str); else printf("n%s is an identifier",str); } main() { FILE *f1,*f2,*f3; char c, str[10], st1[10]; int num[100], lineno=0, tokenvalue=0,i=0,j=0,k=0; printf("n Enter the input in the program. Input at least 3 lines by pressing Enter at the end of
  • 2. each line. When done, press CTRL+D: ");/*gets(st1);*/ f1=fopen("input","w"); while((c=getchar())!=EOF) putc(c,f1); fclose(f1); f1=fopen("input","r"); f2=fopen("identifier","w"); f3=fopen("specialchar","w"); while((c=getc(f1))!=EOF) { if(isdigit(c)) { tokenvalue=c-'0'; c=getc(f1); while(isdigit(c)) { tokenvalue*=10+c-'0'; c=getc(f1); } num[i++]=tokenvalue; ungetc(c,f1); } else if(isalpha(c)) { putc(c,f2); c=getc(f1); while(isdigit(c)||isalpha(c)||c=='_'||c=='$') { putc(c,f2); c=getc(f1); } putc(' ',f2); ungetc(c,f1); }