Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write code in c++ A compiler begins the compilation process by dividing a program into a set of delimited strings called tokens . This task

Write code in c++

A compiler begins the compilation process by dividing a program into a set of delimited strings

called tokens . This task is referred to as lexical analysis . For instance, given the C++ statement,

if ( j =>

lexical analysis by a C++ compiler produces the following ten tokens:

if ( j =>

Before you can perform lexical analysis, you need operations that support the input and output of

delimited strings. A pair of String ADT input/output operations are described below.

friend istream & operator >> ( istream &input,

String &inputString )

Requirements:

The specified input stream must not be in an error state.

Returns:

Extracts (inputs) a string from the specified input stream, returns it in inputString , and returns

the resulting state of the input stream. Begins the input process by reading whitespace (blanks,

newlines, and tabs) until a non-whitespace character is encountered. This character is returned as

the first character in the string. Continues reading the string character by character until another

whitespace character is encountered.

friend ostream & operator

const String &outputString )

Requirements:

The specified output stream must not be in an error state.

Returns:

Inserts (outputs) outputString in the specified output stream and returns the resulting state of

the output stream.

Note that these operations are not part of the String class. However, they do need to have access to

the data members of this class. Thus, they are named as friends of the String class.

Step 1: The file strio.cpp contains implementations of these string input/output operations. Add

these operations to your implementation of the String ADT in the file stradt.cpp .

Prototypes for these operations are included in the declaration of String class in the file

stradt.h .

Step 2: Create a program (stored in the file lexical.cpp ) that uses the operations in the

String ADT to perform lexical analysis on a text file containing a C++

program. Your program should read the tokens in this file and output each

token to the screen using the following format:

1 : [1stToken]

2 : [2ndToken]

...

This format requires that your program maintain a running count of the number of

tokens that have been read from the text file. Assume that the tokens in the text file

are delimited by whitespacean assumption that is not true for C++ programs in

general.

Step 3: Test your lexical analysis program using the C++ program in the file

progsamp.dat . The contents of this file are shown below.

void main ( )

{

int j ,

total = 0 ;

for ( j = 1 ; j =>

total += j ;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Design Operation And Evaluation Of Mobile Communications

Authors: Gavriel Salvendy ,June Wei

1st Edition

3030770249, 978-3030770242

More Books

Students also viewed these Programming questions

Question

provide a thorough insight into what job crafting really is;

Answered: 1 week ago

Question

11. Give the reliability function of the structure of Exercise 8.

Answered: 1 week ago