Need help printing the identifier lexeme and the integer lexeme. Im trying to print whatver is found is the file with the token like in the picture with other tokens. Can you help me figure out how to print whatever is found that causes the IDENT and INT tokens?
Need help printing the identifier lexeme and the integer lexeme. Im trying to print whatver is found is the file with the token like in the picture with other tokens. Can you help me figure out how to print whatever is found that causes the IDENT and INT tokens?
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
100%
Need help printing the identifier lexeme and the integer lexeme. Im trying to print whatver is found is the file with the token like in the picture with other tokens. Can you help me figure out how to print whatever is found that causes the IDENT and INT tokens?

Transcribed Image Text:The image contains a sequence of programming-related keywords and symbols arranged in a structured format resembling pseudocode or a lexical analysis output. Below is the transcription of the content:
```
read KEY_READ
IDENT
while KEY_WHILE
IDENT
<= LEQUAL_OP
INT_LIT
do KEY_DO
{ LEFT_CBRACE
write KEY_WRITE
IDENT
IDENT
== ASSIGN_OP
IDENT
+ ADD_OP
INT_LIT
} RIGHT_CBRACE
```
### Explanation:
- **Keywords**: `KEY_READ`, `KEY_WHILE`, `KEY_DO`, `KEY_WRITE`, represent commands or actions in the pseudocode.
- **Identifiers**: `IDENT` placeholders likely represent variable names or other identifiers.
- **Operators**:
- `<= LEQUAL_OP` refers to less than or equal to.
- `== ASSIGN_OP` is shown where a value is assigned or checked for equality.
- `+ ADD_OP` represents addition.
- **Braces**: `{ LEFT_CBRACE` and `} RIGHT_CBRACE` indicate the start and end of a block of code.
- **Literal**: `INT_LIT` stands for an integer literal.
The code seems to be a simple loop structure in pseudocode, symbolizing reading, writing, comparing, and performing arithmetic operations within a control structure.
Expert Solution

Step 1: Algorithm of the program:
Algorithm:
- Read tokens from an input file.
- For each token:
- a. Check if it's an identifier (IDENT) by testing if it contains only alphabetic characters.
- b. If it's an identifier, classify it as "IDENT."
- c. Check if it's an integer (INT) by attempting to convert it to an integer.
- d. If it's an integer, classify it as "INT."
- e. Print the type and lexeme of the token.
Step by step
Solved in 4 steps with 3 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education