Objective: Write a program in C or C++ that will identify and remove comments from an input test file. Your program should utilize a procedurally-driven deterministic finite state automoton (DFA) to identify comments. Table-driven DFA solutions will have reduced scores (per the grading rubric) since such solutions are typically automatically generated by compiler tools such as Yacc, Lex, Bison, etc. Please note: • The input test files (below) conform to the ChagaLite programming language defined in Backus-Naur Form (BNF) with two exceptions: programming assignment_1-test_file_5.c✓ and programming_assignment_1-test_file_6.c ✓ contain partial C block-style comments that are unterminated. Therefore, I expect your program to output an error message along with the correct line number where the offending comment is. For example, "ERROR: Program contains C-style, unterminated comment on line 3". There are two types of comments your program should remove: • C block-style comments: /* Everything inside this space is a comment! */ C++ style line comments: // This comment will be ignored until a newline (\n) is reached. Tips and Hints: • . . When replacing C++ style line comments, replace the slash-slash characters, "//" and all characters up-to (but not including) the newline character, "\n" with whitespace. By doing so, you preserve the line numbering of the original input program. When replacing C block style comments, replace the slash-asterisk characters, "/*" and all characters up-to asterisk-slash characters, "*/" inclusive with whitespace. This too preserves the line numbering of the original input program. One of the subtle advantages of replacing comments with whitespace: line counts are unchanged compared to the original input file. This becomes important when displaying error messages. If you completely delete a comment rather than substituting whitespace, the resulting program's line numbering may change. It is much more desireable to output the correct line number from the original input file when syntax errors occur. Displaying the correct line number where syntax errors occur will be important in later programming assignments when parsing is involved. I will be using the following files as input to test your program's ability to remove comments: • programming_assignment 1-test_file_1.c✓ programming assignment 1-test_file_2.c✓↓ programming assignment_1-test_file_3.c✓ • programming assignment 1-test_file_4.c✓ programming assignment 1-test_file_5.c✓ programming assignment 1-test_file_6.c✓ If you replace comments with whitespace, your program's output should look like this: Input file programming_assignment 1-test_file_1.c✓ should output programming_assignment 1-test_file_1- comments replaced_with_whitespace.c✓ • Input file programming_assignment_1-test_file_2.c✓ should output programming_assignment_1-test_file_2- • • • comments_replaced_with_whitespace.c✓ Input file programming_assignment_1-test_file_3.c ✓should output programming_assignment_1-test_file_3- comments replaced_with_whitespace.c✓ Input file programming_assignment_1-test_file_4.c ✓ should output programming_assignment_1-test_file_4- comments_replaced_with_whitespace.c✓ Input file programming_assignment 1-test_file_5.c ✓ contains an incomplete C block-style comment. Therefore, your program should output "ERROR: Program contains C-style, unterminated comment on line 7". Input file programming_assignment_1-test_file_6.c ✓ contains an incomplete C block-style comment. Therefore, your program should output "ERROR: Program contains C-style, unterminated comment on line 7".
Objective: Write a program in C or C++ that will identify and remove comments from an input test file. Your program should utilize a procedurally-driven deterministic finite state automoton (DFA) to identify comments. Table-driven DFA solutions will have reduced scores (per the grading rubric) since such solutions are typically automatically generated by compiler tools such as Yacc, Lex, Bison, etc. Please note: • The input test files (below) conform to the ChagaLite programming language defined in Backus-Naur Form (BNF) with two exceptions: programming assignment_1-test_file_5.c✓ and programming_assignment_1-test_file_6.c ✓ contain partial C block-style comments that are unterminated. Therefore, I expect your program to output an error message along with the correct line number where the offending comment is. For example, "ERROR: Program contains C-style, unterminated comment on line 3". There are two types of comments your program should remove: • C block-style comments: /* Everything inside this space is a comment! */ C++ style line comments: // This comment will be ignored until a newline (\n) is reached. Tips and Hints: • . . When replacing C++ style line comments, replace the slash-slash characters, "//" and all characters up-to (but not including) the newline character, "\n" with whitespace. By doing so, you preserve the line numbering of the original input program. When replacing C block style comments, replace the slash-asterisk characters, "/*" and all characters up-to asterisk-slash characters, "*/" inclusive with whitespace. This too preserves the line numbering of the original input program. One of the subtle advantages of replacing comments with whitespace: line counts are unchanged compared to the original input file. This becomes important when displaying error messages. If you completely delete a comment rather than substituting whitespace, the resulting program's line numbering may change. It is much more desireable to output the correct line number from the original input file when syntax errors occur. Displaying the correct line number where syntax errors occur will be important in later programming assignments when parsing is involved. I will be using the following files as input to test your program's ability to remove comments: • programming_assignment 1-test_file_1.c✓ programming assignment 1-test_file_2.c✓↓ programming assignment_1-test_file_3.c✓ • programming assignment 1-test_file_4.c✓ programming assignment 1-test_file_5.c✓ programming assignment 1-test_file_6.c✓ If you replace comments with whitespace, your program's output should look like this: Input file programming_assignment 1-test_file_1.c✓ should output programming_assignment 1-test_file_1- comments replaced_with_whitespace.c✓ • Input file programming_assignment_1-test_file_2.c✓ should output programming_assignment_1-test_file_2- • • • comments_replaced_with_whitespace.c✓ Input file programming_assignment_1-test_file_3.c ✓should output programming_assignment_1-test_file_3- comments replaced_with_whitespace.c✓ Input file programming_assignment_1-test_file_4.c ✓ should output programming_assignment_1-test_file_4- comments_replaced_with_whitespace.c✓ Input file programming_assignment 1-test_file_5.c ✓ contains an incomplete C block-style comment. Therefore, your program should output "ERROR: Program contains C-style, unterminated comment on line 7". Input file programming_assignment_1-test_file_6.c ✓ contains an incomplete C block-style comment. Therefore, your program should output "ERROR: Program contains C-style, unterminated comment on line 7".
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 20RQ
Related questions
Question
Provide the full C++ code that fulfills the directions. Below I have provided all 6 test files contents
programming_assignment_1-test_file_1.c:
// ***************************************************
// * CS460:Programming Assignment 1: Test Program 1 *
// ***************************************************
procedure main (void)
{
int counter;
counter = 2;
/*
counter = 100;
*/
printf ("counter = %d\n", counter);
}
// * CS460:
// ***************************************************
procedure main (void)
{
int counter;
counter = 2;
/*
counter = 100;
*/
printf ("counter = %d\n", counter);
}
programming_assignment_1-test_file_2.c:
// ***************************************************
// * CS460: Programming Assignment 1: Test Program 2 *
// ***************************************************
procedure main (void)
{
int /* hidden; int */ counter;
counter = /*2*/ 100;
/* hidden = */ /*5;*/
printf ("counter = %d\n", counter);
}
// * CS460: Programming Assignment 1: Test Program 2 *
// ***************************************************
procedure main (void)
{
int /* hidden; int */ counter;
counter = /*2*/ 100;
/* hidden = */ /*5;*/
printf ("counter = %d\n", counter);
}
programming_assignment_1-test_file_3.c:
// ***************************************************
// * CS460: Programming Assignment 1: Test Program 3 *
// ***************************************************
//procedure main (/*avoid*/void)
procedure main (/*avoid*/void)
{
int /* hidden; char */ counter;
counter = /*2*/ 101;
/* hidden = */ /*5;*/
printf ("counter = %d\n", counter);
printf ("/* Will this string be displayed? */\n");
/*
}
*/
}
// * CS460: Programming Assignment 1: Test Program 3 *
// ***************************************************
//procedure main (/*avoid*/void)
procedure main (/*avoid*/void)
{
int /* hidden; char */ counter;
counter = /*2*/ 101;
/* hidden = */ /*5;*/
printf ("counter = %d\n", counter);
printf ("/* Will this string be displayed? */\n");
/*
}
*/
}
programming_assignment_1-test_file_4.c:
// ***************************************************
// * CS460: Programming Assignment 1: Test Program 4 *
// ***************************************************
procedure main (void)//)
{
/**/int counter;
/**/counter = 100 / 2;
/**/printf ("counter = %d\n", counter);
/**/printf ("/* Will this string be displayed? */\n");
/**/printf ("// Will this string be displayed?\n");
}
// * CS460: Programming Assignment 1: Test Program 4 *
// ***************************************************
procedure main (void)//)
{
/**/int counter;
/**/counter = 100 / 2;
/**/printf ("counter = %d\n", counter);
/**/printf ("/* Will this string be displayed? */\n");
/**/printf ("// Will this string be displayed?\n");
}
programming_assignment_1-test_file_5.c:
/****************************************************
* CS460: Programming Assignment 1: Test Program 5 *
****************************************************/
procedure main (void)
{
int counter;
/*
counter = 100 / 2;
}
* CS460: Programming Assignment 1: Test Program 5 *
****************************************************/
procedure main (void)
{
int counter;
/*
counter = 100 / 2;
}
programming_assignment_1-test_file_6.c:
/****************************************************
* CS460: Programming Assignment 1: Test Program 5 *
****************************************************/
procedure main (void)
{
int counter;
*/
counter = 100 / 2;
}
* CS460: Programming Assignment 1: Test Program 5 *
****************************************************/
procedure main (void)
{
int counter;
*/
counter = 100 / 2;
}

Transcribed Image Text:Objective:
Write a program in C or C++ that will identify and remove comments from an input test file.
Your program should utilize a procedurally-driven deterministic finite state automoton (DFA) to identify comments. Table-driven DFA solutions
will have reduced scores (per the grading rubric) since such solutions are typically automatically generated by compiler tools such as Yacc, Lex,
Bison, etc.
Please note:
•
The input test files (below) conform to the ChagaLite programming language defined in Backus-Naur Form (BNF) with two exceptions:
programming assignment_1-test_file_5.c✓ and programming_assignment_1-test_file_6.c ✓ contain partial C block-style comments that
are unterminated. Therefore, I expect your program to output an error message along with the correct line number where the offending
comment is. For example, "ERROR: Program contains C-style, unterminated comment on line 3".
There are two types of comments your program should remove:
•
C block-style comments: /* Everything inside this space is a comment! */
C++ style line comments: // This comment will be ignored until a newline (\n) is reached.
Tips and Hints:
•
.
.
When replacing C++ style line comments, replace the slash-slash characters, "//" and all characters up-to (but not including) the newline
character, "\n" with whitespace. By doing so, you preserve the line numbering of the original input program.
When replacing C block style comments, replace the slash-asterisk characters, "/*" and all characters up-to asterisk-slash characters, "*/"
inclusive with whitespace. This too preserves the line numbering of the original input program.
One of the subtle advantages of replacing comments with whitespace: line counts are unchanged compared to the original input file. This
becomes important when displaying error messages. If you completely delete a comment rather than substituting whitespace, the resulting
program's line numbering may change. It is much more desireable to output the correct line number from the original input file when syntax
errors occur. Displaying the correct line number where syntax errors occur will be important in later programming assignments when
parsing is involved.
I will be using the following files as input to test your program's ability to remove comments:
• programming_assignment 1-test_file_1.c✓
programming assignment 1-test_file_2.c✓↓
programming assignment_1-test_file_3.c✓
•
programming assignment 1-test_file_4.c✓
programming assignment 1-test_file_5.c✓
programming assignment 1-test_file_6.c✓
If you replace comments with whitespace, your program's output should look like this:
Input file programming_assignment 1-test_file_1.c✓ should output programming_assignment 1-test_file_1-
comments replaced_with_whitespace.c✓
• Input file programming_assignment_1-test_file_2.c✓ should output programming_assignment_1-test_file_2-
•
•
•
comments_replaced_with_whitespace.c✓
Input file programming_assignment_1-test_file_3.c ✓should output programming_assignment_1-test_file_3-
comments replaced_with_whitespace.c✓
Input file programming_assignment_1-test_file_4.c ✓ should output programming_assignment_1-test_file_4-
comments_replaced_with_whitespace.c✓
Input file programming_assignment 1-test_file_5.c ✓ contains an incomplete C block-style comment. Therefore, your program should
output "ERROR: Program contains C-style, unterminated comment on line 7".
Input file programming_assignment_1-test_file_6.c ✓ contains an incomplete C block-style comment. Therefore, your program should
output "ERROR: Program contains C-style, unterminated comment on line 7".
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Recommended textbooks for you

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning