Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Soreland, a software company, is planning on releasing its first C++ compiler with the hopes of putting MiniSoft's Visual C++ out of business (that reminds

Soreland, a software company, is planning on releasing its first C++ compiler with the hopes of putting MiniSoft's Visual C++ out of business (that reminds me of another story). Consequently, Soreland has contracted with the Fruugle Corporation to design and build part of their compiler. Of course, since Fruugle gets all of its labor by exploiting El Camino undergraduate students, you'll be doing all of the programming. For Fruugle, you will write a C++ program to test the "balance" of certain features of C++ programs. This is a task that is done by C++ compilers. The technique you will use is similar to the technique used by a typical C++ compiler. Requirements There are many features in C++ programs that must be ``balanced'' to be syntactically correct. For example, every ( must be balanced by a corresponding ). Similarly for {} and []. There are other (somewhat more complex) situations. Block comments must be balanced. Each /* must be balanced by a */ The complication here is that the tokens being balanced are not composed of single characters. Moreover, the ``closing comment'' */ starts with a character that is used in other ways (pointers, multiplication). Quotes must be balanced. This applies to single quotes and double quotes. The complication here is that all the material between the matching quotes can contain any characters. The characters between the quotes do not require balancing. For example, the string "This is a /* ' * quote" is legal, and the comment and single-quote need not be balanced. Inline comments are not balanced. Anything that comes after a comment is ignored until you get to the end of the line that's read in. There are some balanced C++ programs you need not test. For example, some balanced C++ programs contain character constants such as '\'' or '\"'. These are inherently unbalanced and would require a bit more work to catch. You need not worry about such problems for the compiler (unless you like the modest challenge). The Basic Algorithm Please think and know there are different ways to do this, think of structure. But note that simply counting the number of characters will not work. For example, the expression }abc{ has the correct number of balancing braces (one opening brace and one closing brace), but it is not valid C++ code. A stack provides the mechanism needed for the algorithm. Basically, whenever a closing symbol (such as }) is seen, it must match the nearest opening symbol of the same type (such as {). One important point: do not write a large main file. Your main file should simply get a file name, call a function to print the file with line numbers, and then call a balance-checking function.

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

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

What aspects would it be impossible to capture?

Answered: 1 week ago

Question

Enhance your words with effective presentation aids

Answered: 1 week ago