Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use c++ language Even though comments are essential for human readers, the compiler simply ignores them. If you are writing a compiler, you therefore need

image text in transcribed

image text in transcribed

use c++ language

Even though comments are essential for human readers, the compiler simply ignores them. If you are writing a compiler, you therefore need to be able to recognize and eliminate comments that occur in a source file. Write a function void removeComments (istream & is, ostream & os) that copies characters from the input stream is to the output stream os, except for charac- ters that appear inside C + + comments. Your implementation should recognize both comment conventions: Any text beginning with /* and ending with */, possibly many lines later. Any text beginning with // and extending through the end of the line. The real C++ compiler needs to check to make sure that these characters are not contained inside quoted strings, but you should feel free to ignore that detail. The problem is tricky enough as it stands. Requirments & Hints: Please fill in the TODO part of RemoveComments.cpp. You can prepare your test file under the res folder in Stanford Library for testing. The generated results should print in the Stanford console. 1 1 1 /* ...* 4 5 #include 6 #include "console.h" 7 #include "filelib.h" // promptUser For File 8 #include "P3RemoveComments.h" 9 using namespace std; 10 11 /* Function definition */ 12 13 void removeComments (istream& is, ostream& os) { 141 //TODO 15 } 16 17 /* Function definition */ 18 int P3RemoveComments() { 20 ifstream infile; 21 promptUserForFile(infile, "Input file: "); 22 removeComments (infile, cout); 23 infile.close(); 24 return 0; 25 } 26 1 2 2 }

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

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago