Answered step by step
Verified Expert Solution
Link Copied!

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

image

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

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_2

Step: 3

blur-text-image_3

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

Management Accounting Information for Decision-Making and Strategy Execution

Authors: Anthony A. Atkinson, Robert S. Kaplan, Ella Mae Matsumura, S. Mark Young

6th Edition

137024975, 978-0137024971

More Books

Students also viewed these Computer Network questions

Question

What is a cognitive bias in AI ?

Answered: 1 week ago

Question

What is a stock option plan?

Answered: 1 week ago