Program 3 - C++ Program Checker


Write a program that takes a single command line parameter that specifies the name of a C++ source file. The program should then read in that file and check for matching grouping symbols. The grouping symbols to check for are: ( ), [ ], " ", and { }. All grouping symbols can span multiple lines except for double quotes: " ". Grouping symbols within comments or strings can be ignored (// ..., /* ... */, or " ... " ). You do not have to check for escaped characters within strings or do other syntactic checking. Be sure to follow the programming style guidelines.

Name your source file program3.C.

Command Line Parameters

Command line parameters are simply parameters passed to an application when it is executed. You're familiar with this using such applications on cs as 'ls'.

ls -l myfile.C

Here, "-l" and "myfile.C" are both command line parameters to the program "ls."

For C++ to handle command line parameters, two parameters are passed to main. The first of these two parameters is a count of the number of parameters being passed. This variable is commonly named "argc" for "argument count." The second parameter passed to main is an array of C-strings that represent the passed parameters. This variable is commonly named "argv" for "argument vector." The name of the invoked application is always the first of these strings (and therefore, argc is always >= 1).

Let's look at an example:

 1 #include <iostream>
 2 
 3 int main(int argc, char* argv[]) {
 4     std::cout << "argc:  " << argc << std::endl;
 5 
 6     for (int i = 0; i < argc; ++i) {
 7         std::cout << "argv[" << i << "]: "
 8                   << argv[i] << std::endl;
 9     }
10 
11     return 0;
12 }
And a sample of the output of this program:
> example hello there 2440!
argc:  4
argv[0]: example
argv[1]: hello
argv[2]: there
argv[3]: 2440!

You will use command line parameters to pass in the name of the file to read the C++ program from. You'll want to check the argc parameter to insure that the parameter was passed (argc > 1), then use the specified string as a filename.

Output
The output from the program will be an error message indicating the line and the column number where any errors are detected. You can end the program once a single error has been identified or make your program try to identify further errors.

If no errors are detected, there should be no output from your program.

Example:

> program3 sample.C
Unterminated string detected on line 27, column 16.