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 Chaga Lite 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".

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 20RQ
icon
Related questions
Question

The programming assignment is called "Ignoring Comments"

Provide the full C++ code

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 Chaga Lite 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".
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 Chaga Lite 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
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
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
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning