SlideShare una empresa de Scribd logo
1 de 5
Descargar para leer sin conexión
Project description: Modify the Simple lexer program given in the link below to: Add tokens so
that all the tokens in the program from Activity 1 of this module are represented (75 points). The
output of your program should specify the type of token in words (Identifier, Keyword ...etc) not
a number (25 points). Print each token on a separate line.
Code:
main.cpp file
#include <stdio.h>
#include <ctype.h>
/* Global declarations */
/* Variables */
int charClass;
char lexeme [100];
char nextChar;
int lexLen;
int nextToken;
FILE *in_fp;
/* Function declarations */
void addChar();
void getChar();
void getNonBlank();
int lex();
/* Character classes */
#define LETTER 0
#define DIGIT 1
#define UNKNOWN 99
/* Token codes */
#define INT_LIT 10
#define IDENT 11
#define ASSIGN_OP 20
#define ADD_OP 21
#define SUB_OP 22
#define MULT_OP 23
#define DIV_OP 24
#define LEFT_PAREN 25
#define RIGHT_PAREN 26
/******************************************************/
/* main driver */
int main()
{
/* Open the input data file and process its contents */
if ((in_fp = fopen("front.in", "r")) == NULL) {
printf("ERROR - cannot open front.in n");
} else {
getChar();
do {
lex();
} while (nextToken != EOF);
}
return 0;
}
/*****************************************************/
/* lookup - a function to lookup operators and parentheses and return the
* token */
int lookup(char ch) {
switch (ch) {
case '(':
addChar();
nextToken = LEFT_PAREN;
break;
case ')':
addChar();
nextToken = RIGHT_PAREN;
break;
case '+':
addChar();
nextToken = ADD_OP;
break;
case '-':
addChar();
nextToken = SUB_OP;
break;
case '*':
addChar();
nextToken = MULT_OP;
break;
case '/':
addChar();
nextToken = DIV_OP;
break;
default:
addChar();
nextToken = EOF;
break;
}
return nextToken;
}
/*****************************************************/
/* addChar - a function to add nextChar to lexeme */
void addChar() {
if (lexLen <= 98) {
lexeme[lexLen++] = nextChar;
lexeme[lexLen] = 0;
} else {
printf("Error - lexeme is too long n");
}
}
/*****************************************************/
/* getChar - a function to get the next character of input and determine its
* character class */
void getChar() {
if ((nextChar = getc(in_fp)) != EOF) {
if (isalpha(nextChar))
charClass = LETTER;
else if (isdigit(nextChar))
charClass = DIGIT;
else charClass = UNKNOWN;
} else {
charClass = EOF;
}
}
/*****************************************************/
/* getNonBlank - a function to call getChar until it returns a non-whitespace
* character */
void getNonBlank() {
while (isspace(nextChar)) getChar();
}
/*****************************************************/
/* lex - a simple lexical analyzer for arithmetic expressions */
int lex() {
lexLen = 0;
getNonBlank();
switch (charClass) {
/* Parse identifiers */
case LETTER:
addChar();
getChar();
while (charClass == LETTER || charClass == DIGIT) {
addChar();
getChar();
}
nextToken = IDENT;
break;
/* Parse integer literals */
case DIGIT:
addChar();
getChar();
while (charClass == DIGIT) {
addChar();
getChar();
}
nextToken = INT_LIT;
break;
/* Parentheses and operators */
case UNKNOWN:
lookup(nextChar);
getChar();
break;
/* EOF */
case EOF:
nextToken = EOF;
lexeme[0] = 'E';
lexeme[1] = 'O';
lexeme[2] = 'F';
lexeme[3] = 0;
break;
} /* End of switch */
printf("Next token is: %d, Next lexeme is %sn", nextToken, lexeme);
return nextToken;
} /* End of function lex */
front.in file
(sum + 47)/total
Project description- Modify the Simple lexer program given in the link.pdf

Más contenido relacionado

Similar a Project description- Modify the Simple lexer program given in the link.pdf

External Language Stored Procedures for MySQL
External Language Stored Procedures for MySQLExternal Language Stored Procedures for MySQL
External Language Stored Procedures for MySQLAntony T Curtis
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationWei-Ren Chen
 
7-8-1- Modify the program so that the user can specify an encryption k (1).docx
7-8-1- Modify the program so that the user can specify an encryption k (1).docx7-8-1- Modify the program so that the user can specify an encryption k (1).docx
7-8-1- Modify the program so that the user can specify an encryption k (1).docxAlanQHOOliveru
 
7-8-1- Modify the program so that the user can specify an encryption k (1).docx
7-8-1- Modify the program so that the user can specify an encryption k (1).docx7-8-1- Modify the program so that the user can specify an encryption k (1).docx
7-8-1- Modify the program so that the user can specify an encryption k (1).docxGordonyTaMackayk
 
can you fix floating point literals in this code I already highligh.pdf
can you fix floating point literals in this code I already highligh.pdfcan you fix floating point literals in this code I already highligh.pdf
can you fix floating point literals in this code I already highligh.pdfsales88
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bChereCheek752
 
Flex lexer.h -c++-- flexlexer.h -- define interfaces f
Flex lexer.h  -c++-- flexlexer.h -- define interfaces fFlex lexer.h  -c++-- flexlexer.h -- define interfaces f
Flex lexer.h -c++-- flexlexer.h -- define interfaces faman39650
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overviewstn_tkiller
 
Yacc topic beyond syllabus
Yacc   topic beyond syllabusYacc   topic beyond syllabus
Yacc topic beyond syllabusJK Knowledge
 
Recursion to iteration automation.
Recursion to iteration automation.Recursion to iteration automation.
Recursion to iteration automation.Russell Childs
 
Pascal script maxbox_ekon_14_2
Pascal script maxbox_ekon_14_2Pascal script maxbox_ekon_14_2
Pascal script maxbox_ekon_14_2Max Kleiner
 

Similar a Project description- Modify the Simple lexer program given in the link.pdf (20)

Klee introduction
Klee  introductionKlee  introduction
Klee introduction
 
External Language Stored Procedures for MySQL
External Language Stored Procedures for MySQLExternal Language Stored Procedures for MySQL
External Language Stored Procedures for MySQL
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate Representation
 
Base de-datos
Base de-datosBase de-datos
Base de-datos
 
7-8-1- Modify the program so that the user can specify an encryption k (1).docx
7-8-1- Modify the program so that the user can specify an encryption k (1).docx7-8-1- Modify the program so that the user can specify an encryption k (1).docx
7-8-1- Modify the program so that the user can specify an encryption k (1).docx
 
7-8-1- Modify the program so that the user can specify an encryption k (1).docx
7-8-1- Modify the program so that the user can specify an encryption k (1).docx7-8-1- Modify the program so that the user can specify an encryption k (1).docx
7-8-1- Modify the program so that the user can specify an encryption k (1).docx
 
can you fix floating point literals in this code I already highligh.pdf
can you fix floating point literals in this code I already highligh.pdfcan you fix floating point literals in this code I already highligh.pdf
can you fix floating point literals in this code I already highligh.pdf
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
C++ Functions.ppt
C++ Functions.pptC++ Functions.ppt
C++ Functions.ppt
 
14 operator overloading
14 operator overloading14 operator overloading
14 operator overloading
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
 
Flex lexer.h -c++-- flexlexer.h -- define interfaces f
Flex lexer.h  -c++-- flexlexer.h -- define interfaces fFlex lexer.h  -c++-- flexlexer.h -- define interfaces f
Flex lexer.h -c++-- flexlexer.h -- define interfaces f
 
Lex programming
Lex programmingLex programming
Lex programming
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
 
Array Cont
Array ContArray Cont
Array Cont
 
Yacc topic beyond syllabus
Yacc   topic beyond syllabusYacc   topic beyond syllabus
Yacc topic beyond syllabus
 
Recursion to iteration automation.
Recursion to iteration automation.Recursion to iteration automation.
Recursion to iteration automation.
 
Function C++
Function C++ Function C++
Function C++
 
Pascal script maxbox_ekon_14_2
Pascal script maxbox_ekon_14_2Pascal script maxbox_ekon_14_2
Pascal script maxbox_ekon_14_2
 

Más de 3rdeyesolutions

python please The given program reads a list of single-word first nam.pdf
python please  The given program reads a list of single-word first nam.pdfpython please  The given program reads a list of single-word first nam.pdf
python please The given program reads a list of single-word first nam.pdf3rdeyesolutions
 
Python- Thanks- a- Create a file called -YOUR_NAME_CalcBonus-py- i- Ty.pdf
Python- Thanks- a- Create a file called -YOUR_NAME_CalcBonus-py- i- Ty.pdfPython- Thanks- a- Create a file called -YOUR_NAME_CalcBonus-py- i- Ty.pdf
Python- Thanks- a- Create a file called -YOUR_NAME_CalcBonus-py- i- Ty.pdf3rdeyesolutions
 
Python- 1- Which of the following assert functions checks if the value.pdf
Python- 1- Which of the following assert functions checks if the value.pdfPython- 1- Which of the following assert functions checks if the value.pdf
Python- 1- Which of the following assert functions checks if the value.pdf3rdeyesolutions
 
Python Use Request library only- Use the proper widgets - fonts and ba.pdf
Python Use Request library only- Use the proper widgets - fonts and ba.pdfPython Use Request library only- Use the proper widgets - fonts and ba.pdf
Python Use Request library only- Use the proper widgets - fonts and ba.pdf3rdeyesolutions
 
python Write the function isBST2(t) that receives a binary tree t and.pdf
python Write the function isBST2(t) that receives a binary tree t and.pdfpython Write the function isBST2(t) that receives a binary tree t and.pdf
python Write the function isBST2(t) that receives a binary tree t and.pdf3rdeyesolutions
 
Python Questions (pictured) E-1 How can you replace the current proces.pdf
Python Questions (pictured) E-1 How can you replace the current proces.pdfPython Questions (pictured) E-1 How can you replace the current proces.pdf
Python Questions (pictured) E-1 How can you replace the current proces.pdf3rdeyesolutions
 
Python script for plotting and solving the 2D Heat Equation Create a P.pdf
Python script for plotting and solving the 2D Heat Equation Create a P.pdfPython script for plotting and solving the 2D Heat Equation Create a P.pdf
Python script for plotting and solving the 2D Heat Equation Create a P.pdf3rdeyesolutions
 
Pureform- Incorporated- uses the weighted-average method in its proces.pdf
Pureform- Incorporated- uses the weighted-average method in its proces.pdfPureform- Incorporated- uses the weighted-average method in its proces.pdf
Pureform- Incorporated- uses the weighted-average method in its proces.pdf3rdeyesolutions
 
Python Questions (pictured) F-1 Compiling the program in Step 1- how.pdf
Python Questions (pictured)   F-1 Compiling the program in Step 1- how.pdfPython Questions (pictured)   F-1 Compiling the program in Step 1- how.pdf
Python Questions (pictured) F-1 Compiling the program in Step 1- how.pdf3rdeyesolutions
 
Python Questions (pictured) D-1 What happens to the file -etc-zzz when.pdf
Python Questions (pictured) D-1 What happens to the file -etc-zzz when.pdfPython Questions (pictured) D-1 What happens to the file -etc-zzz when.pdf
Python Questions (pictured) D-1 What happens to the file -etc-zzz when.pdf3rdeyesolutions
 
Python is a popular programming language used in a wide range of field.pdf
Python is a popular programming language used in a wide range of field.pdfPython is a popular programming language used in a wide range of field.pdf
Python is a popular programming language used in a wide range of field.pdf3rdeyesolutions
 
python only List the eligible drivers a function listRoadTests that de.pdf
python only List the eligible drivers a function listRoadTests that de.pdfpython only List the eligible drivers a function listRoadTests that de.pdf
python only List the eligible drivers a function listRoadTests that de.pdf3rdeyesolutions
 
Python offers arrays like structure known as lists- True or False- A).pdf
Python offers arrays like structure known as lists- True or False- A).pdfPython offers arrays like structure known as lists- True or False- A).pdf
Python offers arrays like structure known as lists- True or False- A).pdf3rdeyesolutions
 
Python exercise- # Display the in all upper case letters and the in lo.pdf
Python exercise- # Display the in all upper case letters and the in lo.pdfPython exercise- # Display the in all upper case letters and the in lo.pdf
Python exercise- # Display the in all upper case letters and the in lo.pdf3rdeyesolutions
 
PYTHON CODING III- Write a function that takes a list of numbers as in.pdf
PYTHON CODING III- Write a function that takes a list of numbers as in.pdfPYTHON CODING III- Write a function that takes a list of numbers as in.pdf
PYTHON CODING III- Write a function that takes a list of numbers as in.pdf3rdeyesolutions
 
PYTHON CODING I have to create a Red vs Blue game in python with a GUI.pdf
PYTHON CODING I have to create a Red vs Blue game in python with a GUI.pdfPYTHON CODING I have to create a Red vs Blue game in python with a GUI.pdf
PYTHON CODING I have to create a Red vs Blue game in python with a GUI.pdf3rdeyesolutions
 
Python code use a while loop to ask the user to keep going- the start.pdf
Python code  use a while loop to ask the user to keep going- the start.pdfPython code  use a while loop to ask the user to keep going- the start.pdf
Python code use a while loop to ask the user to keep going- the start.pdf3rdeyesolutions
 
python code plz Task 2 1- Create a list with the digits in your studen.pdf
python code plz Task 2 1- Create a list with the digits in your studen.pdfpython code plz Task 2 1- Create a list with the digits in your studen.pdf
python code plz Task 2 1- Create a list with the digits in your studen.pdf3rdeyesolutions
 
PYTHON - time and space complexity for the next function- def some_fun.pdf
PYTHON - time and space complexity for the next function- def some_fun.pdfPYTHON - time and space complexity for the next function- def some_fun.pdf
PYTHON - time and space complexity for the next function- def some_fun.pdf3rdeyesolutions
 
Python - Explain the concept- and why you found it interesting- How w.pdf
Python -  Explain the concept- and why you found it interesting- How w.pdfPython -  Explain the concept- and why you found it interesting- How w.pdf
Python - Explain the concept- and why you found it interesting- How w.pdf3rdeyesolutions
 

Más de 3rdeyesolutions (20)

python please The given program reads a list of single-word first nam.pdf
python please  The given program reads a list of single-word first nam.pdfpython please  The given program reads a list of single-word first nam.pdf
python please The given program reads a list of single-word first nam.pdf
 
Python- Thanks- a- Create a file called -YOUR_NAME_CalcBonus-py- i- Ty.pdf
Python- Thanks- a- Create a file called -YOUR_NAME_CalcBonus-py- i- Ty.pdfPython- Thanks- a- Create a file called -YOUR_NAME_CalcBonus-py- i- Ty.pdf
Python- Thanks- a- Create a file called -YOUR_NAME_CalcBonus-py- i- Ty.pdf
 
Python- 1- Which of the following assert functions checks if the value.pdf
Python- 1- Which of the following assert functions checks if the value.pdfPython- 1- Which of the following assert functions checks if the value.pdf
Python- 1- Which of the following assert functions checks if the value.pdf
 
Python Use Request library only- Use the proper widgets - fonts and ba.pdf
Python Use Request library only- Use the proper widgets - fonts and ba.pdfPython Use Request library only- Use the proper widgets - fonts and ba.pdf
Python Use Request library only- Use the proper widgets - fonts and ba.pdf
 
python Write the function isBST2(t) that receives a binary tree t and.pdf
python Write the function isBST2(t) that receives a binary tree t and.pdfpython Write the function isBST2(t) that receives a binary tree t and.pdf
python Write the function isBST2(t) that receives a binary tree t and.pdf
 
Python Questions (pictured) E-1 How can you replace the current proces.pdf
Python Questions (pictured) E-1 How can you replace the current proces.pdfPython Questions (pictured) E-1 How can you replace the current proces.pdf
Python Questions (pictured) E-1 How can you replace the current proces.pdf
 
Python script for plotting and solving the 2D Heat Equation Create a P.pdf
Python script for plotting and solving the 2D Heat Equation Create a P.pdfPython script for plotting and solving the 2D Heat Equation Create a P.pdf
Python script for plotting and solving the 2D Heat Equation Create a P.pdf
 
Pureform- Incorporated- uses the weighted-average method in its proces.pdf
Pureform- Incorporated- uses the weighted-average method in its proces.pdfPureform- Incorporated- uses the weighted-average method in its proces.pdf
Pureform- Incorporated- uses the weighted-average method in its proces.pdf
 
Python Questions (pictured) F-1 Compiling the program in Step 1- how.pdf
Python Questions (pictured)   F-1 Compiling the program in Step 1- how.pdfPython Questions (pictured)   F-1 Compiling the program in Step 1- how.pdf
Python Questions (pictured) F-1 Compiling the program in Step 1- how.pdf
 
Python Questions (pictured) D-1 What happens to the file -etc-zzz when.pdf
Python Questions (pictured) D-1 What happens to the file -etc-zzz when.pdfPython Questions (pictured) D-1 What happens to the file -etc-zzz when.pdf
Python Questions (pictured) D-1 What happens to the file -etc-zzz when.pdf
 
Python is a popular programming language used in a wide range of field.pdf
Python is a popular programming language used in a wide range of field.pdfPython is a popular programming language used in a wide range of field.pdf
Python is a popular programming language used in a wide range of field.pdf
 
python only List the eligible drivers a function listRoadTests that de.pdf
python only List the eligible drivers a function listRoadTests that de.pdfpython only List the eligible drivers a function listRoadTests that de.pdf
python only List the eligible drivers a function listRoadTests that de.pdf
 
Python offers arrays like structure known as lists- True or False- A).pdf
Python offers arrays like structure known as lists- True or False- A).pdfPython offers arrays like structure known as lists- True or False- A).pdf
Python offers arrays like structure known as lists- True or False- A).pdf
 
Python exercise- # Display the in all upper case letters and the in lo.pdf
Python exercise- # Display the in all upper case letters and the in lo.pdfPython exercise- # Display the in all upper case letters and the in lo.pdf
Python exercise- # Display the in all upper case letters and the in lo.pdf
 
PYTHON CODING III- Write a function that takes a list of numbers as in.pdf
PYTHON CODING III- Write a function that takes a list of numbers as in.pdfPYTHON CODING III- Write a function that takes a list of numbers as in.pdf
PYTHON CODING III- Write a function that takes a list of numbers as in.pdf
 
PYTHON CODING I have to create a Red vs Blue game in python with a GUI.pdf
PYTHON CODING I have to create a Red vs Blue game in python with a GUI.pdfPYTHON CODING I have to create a Red vs Blue game in python with a GUI.pdf
PYTHON CODING I have to create a Red vs Blue game in python with a GUI.pdf
 
Python code use a while loop to ask the user to keep going- the start.pdf
Python code  use a while loop to ask the user to keep going- the start.pdfPython code  use a while loop to ask the user to keep going- the start.pdf
Python code use a while loop to ask the user to keep going- the start.pdf
 
python code plz Task 2 1- Create a list with the digits in your studen.pdf
python code plz Task 2 1- Create a list with the digits in your studen.pdfpython code plz Task 2 1- Create a list with the digits in your studen.pdf
python code plz Task 2 1- Create a list with the digits in your studen.pdf
 
PYTHON - time and space complexity for the next function- def some_fun.pdf
PYTHON - time and space complexity for the next function- def some_fun.pdfPYTHON - time and space complexity for the next function- def some_fun.pdf
PYTHON - time and space complexity for the next function- def some_fun.pdf
 
Python - Explain the concept- and why you found it interesting- How w.pdf
Python -  Explain the concept- and why you found it interesting- How w.pdfPython -  Explain the concept- and why you found it interesting- How w.pdf
Python - Explain the concept- and why you found it interesting- How w.pdf
 

Último

How to Use api.constrains ( ) in Odoo 17
How to Use api.constrains ( ) in Odoo 17How to Use api.constrains ( ) in Odoo 17
How to Use api.constrains ( ) in Odoo 17Celine George
 
5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...CaraSkikne1
 
3.21.24 The Origins of Black Power.pptx
3.21.24  The Origins of Black Power.pptx3.21.24  The Origins of Black Power.pptx
3.21.24 The Origins of Black Power.pptxmary850239
 
Patterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxPatterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxMYDA ANGELICA SUAN
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17Celine George
 
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfP4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfYu Kanazawa / Osaka University
 
CAULIFLOWER BREEDING 1 Parmar pptx
CAULIFLOWER BREEDING 1 Parmar pptxCAULIFLOWER BREEDING 1 Parmar pptx
CAULIFLOWER BREEDING 1 Parmar pptxSaurabhParmar42
 
Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...raviapr7
 
How to Manage Cross-Selling in Odoo 17 Sales
How to Manage Cross-Selling in Odoo 17 SalesHow to Manage Cross-Selling in Odoo 17 Sales
How to Manage Cross-Selling in Odoo 17 SalesCeline George
 
Human-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming ClassesHuman-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming ClassesMohammad Hassany
 
Prescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxPrescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxraviapr7
 
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptxClinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptxraviapr7
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxAditiChauhan701637
 
How to Add a many2many Relational Field in Odoo 17
How to Add a many2many Relational Field in Odoo 17How to Add a many2many Relational Field in Odoo 17
How to Add a many2many Relational Field in Odoo 17Celine George
 
Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphNetziValdelomar1
 
M-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxM-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxDr. Santhosh Kumar. N
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.raviapr7
 
Benefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationBenefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationMJDuyan
 
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRADUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRATanmoy Mishra
 

Último (20)

How to Use api.constrains ( ) in Odoo 17
How to Use api.constrains ( ) in Odoo 17How to Use api.constrains ( ) in Odoo 17
How to Use api.constrains ( ) in Odoo 17
 
5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...
 
3.21.24 The Origins of Black Power.pptx
3.21.24  The Origins of Black Power.pptx3.21.24  The Origins of Black Power.pptx
3.21.24 The Origins of Black Power.pptx
 
Patterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxPatterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptx
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17
 
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfP4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
 
CAULIFLOWER BREEDING 1 Parmar pptx
CAULIFLOWER BREEDING 1 Parmar pptxCAULIFLOWER BREEDING 1 Parmar pptx
CAULIFLOWER BREEDING 1 Parmar pptx
 
Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...
 
How to Manage Cross-Selling in Odoo 17 Sales
How to Manage Cross-Selling in Odoo 17 SalesHow to Manage Cross-Selling in Odoo 17 Sales
How to Manage Cross-Selling in Odoo 17 Sales
 
Human-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming ClassesHuman-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming Classes
 
Prescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxPrescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptx
 
Finals of Kant get Marx 2.0 : a general politics quiz
Finals of Kant get Marx 2.0 : a general politics quizFinals of Kant get Marx 2.0 : a general politics quiz
Finals of Kant get Marx 2.0 : a general politics quiz
 
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptxClinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptx
 
How to Add a many2many Relational Field in Odoo 17
How to Add a many2many Relational Field in Odoo 17How to Add a many2many Relational Field in Odoo 17
How to Add a many2many Relational Field in Odoo 17
 
Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a Paragraph
 
M-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxM-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptx
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.
 
Benefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationBenefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive Education
 
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRADUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
 

Project description- Modify the Simple lexer program given in the link.pdf

  • 1. Project description: Modify the Simple lexer program given in the link below to: Add tokens so that all the tokens in the program from Activity 1 of this module are represented (75 points). The output of your program should specify the type of token in words (Identifier, Keyword ...etc) not a number (25 points). Print each token on a separate line. Code: main.cpp file #include <stdio.h> #include <ctype.h> /* Global declarations */ /* Variables */ int charClass; char lexeme [100]; char nextChar; int lexLen; int nextToken; FILE *in_fp; /* Function declarations */ void addChar(); void getChar(); void getNonBlank(); int lex(); /* Character classes */ #define LETTER 0 #define DIGIT 1 #define UNKNOWN 99 /* Token codes */ #define INT_LIT 10 #define IDENT 11 #define ASSIGN_OP 20 #define ADD_OP 21 #define SUB_OP 22 #define MULT_OP 23 #define DIV_OP 24 #define LEFT_PAREN 25 #define RIGHT_PAREN 26 /******************************************************/ /* main driver */ int main()
  • 2. { /* Open the input data file and process its contents */ if ((in_fp = fopen("front.in", "r")) == NULL) { printf("ERROR - cannot open front.in n"); } else { getChar(); do { lex(); } while (nextToken != EOF); } return 0; } /*****************************************************/ /* lookup - a function to lookup operators and parentheses and return the * token */ int lookup(char ch) { switch (ch) { case '(': addChar(); nextToken = LEFT_PAREN; break; case ')': addChar(); nextToken = RIGHT_PAREN; break; case '+': addChar(); nextToken = ADD_OP; break; case '-': addChar(); nextToken = SUB_OP; break; case '*': addChar(); nextToken = MULT_OP; break; case '/': addChar(); nextToken = DIV_OP; break; default: addChar(); nextToken = EOF;
  • 3. break; } return nextToken; } /*****************************************************/ /* addChar - a function to add nextChar to lexeme */ void addChar() { if (lexLen <= 98) { lexeme[lexLen++] = nextChar; lexeme[lexLen] = 0; } else { printf("Error - lexeme is too long n"); } } /*****************************************************/ /* getChar - a function to get the next character of input and determine its * character class */ void getChar() { if ((nextChar = getc(in_fp)) != EOF) { if (isalpha(nextChar)) charClass = LETTER; else if (isdigit(nextChar)) charClass = DIGIT; else charClass = UNKNOWN; } else { charClass = EOF; } } /*****************************************************/ /* getNonBlank - a function to call getChar until it returns a non-whitespace * character */ void getNonBlank() { while (isspace(nextChar)) getChar(); } /*****************************************************/ /* lex - a simple lexical analyzer for arithmetic expressions */ int lex() { lexLen = 0; getNonBlank(); switch (charClass) { /* Parse identifiers */
  • 4. case LETTER: addChar(); getChar(); while (charClass == LETTER || charClass == DIGIT) { addChar(); getChar(); } nextToken = IDENT; break; /* Parse integer literals */ case DIGIT: addChar(); getChar(); while (charClass == DIGIT) { addChar(); getChar(); } nextToken = INT_LIT; break; /* Parentheses and operators */ case UNKNOWN: lookup(nextChar); getChar(); break; /* EOF */ case EOF: nextToken = EOF; lexeme[0] = 'E'; lexeme[1] = 'O'; lexeme[2] = 'F'; lexeme[3] = 0; break; } /* End of switch */ printf("Next token is: %d, Next lexeme is %sn", nextToken, lexeme); return nextToken; } /* End of function lex */ front.in file (sum + 47)/total