Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Compilers check your program for syntax errors, but a missing brace, parenthesis, or bracket may cause the compiler to output many errors without identifying
Compilers check your program for syntax errors, but a missing brace, parenthesis, or bracket may cause the compiler to output many errors without identifying the instruction that caused the malformed instruction. The goal of this assignment is for you to write a program that checks a string of symbols to determine whether the symbols are balanced. For simplicity, your program will only need to consider the brackets'[', ']', curly brackets '{', '}', and parentheses '(',')'. Examples of legal and illegal sequences are below: ()()-legal ([)]-illegal ([]) - legal ([()]) - legal {[()]} - legal The following algorithm uses a stack data structure for its solution. Make an empty stack Read characters to end of line If the character is an opening symbol, push it onto the stack If the character is a closing symbol and the stack is empty, print an error message Otherwise, pop the stack If the symbol is not the corresponding opening symbol then report an error If you have reached the end of line and the stack is not empty, then report an error, else print legal Repeat until you reach the end file. The requirements of the assignment are: Your program should be implemented in either C or C++. You are to implement your own stack functions, including push() and pop(). You must use a linked list to implement your stack. Do not use pre-defined lists classes or modules. You can use a basic struct to create a node for your linked list data structure: Please see the example below: struct Node { } char symbol; Node *next; Your program should read its input from a file. You should specify the filename on the command line when running your program. This will require the use of argc and argv. Do not hardcode the filename. You may assume that each line of the file will contain a string of symbols.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started