Question: Can you help me solve problem 1 and 2 by coding Homework Overview In string ( ( I am balanced ) ) the parentheses are
Can you help me solve problem and by coding
Homework Overview
In string I am balanced the parentheses are balanced, but in Not balanced they are not because a closing parenthesis is missing and so an opening parenthesis is unmatched. The modules in this assignment examine a string containing parentheses and report the number of unmatched closing, and opening, parentheses. Both modules put these numbers on outputs leftoutnunmatclose and rightoutnunmatopen. The parentheses in ab c and a are correctly matched. The parentheses in and are not. For inputs like and both outputs should be zero. For and the number of unmatched closing parentheses is one and so output leftoutnunmatclose should be and output rightoutnunmatopen should be See the testbench output for more examples.
In both modules, pmatchbase Problem and pmatchmark Problem the string appears on input str In pmatchmark there is an additional output, strmarked, which should be set to a version of the string in which the correctly matched parentheses are replaced by angle brackets. For example, for input str the output shold be strmarked See the testbench output for more examples.
The modules each have parameter n Input str and output strmarked are nelement unpacked ordinary arrays of bit quantities. For convenience enumeration constants are defined for the characters used in this assignment:
typedef enum logic :
CharBlank, CharDot,
CharOpen, CharClose,
CharOpenOkay, CharCloseOkay Char;
The input str can consist of any of the first four values. There is no distinction between CharBlank and CharDot, they are standins for arbitrary characters and neither affects paren
thesis matching. The last two, CharOpenOkay and CharCloseOkay are to be used in Problem for replacing properly matched parenthesis.
Those who are unsure of how to work with str or of just what the modules are supposed to do should examine modules pmatchcombbase and pmatchcombmark. Module pmatchcombbase will pass the testbench for Problem if it were renamed pmatchbase and pmatchcombmark would pass the testbench for Problem if renamed
These comb modules compute their results by scanning the string from left to right. In their synthesized hardware the critical path appears to be proportional to n the string length. That's too long a critical path for our purposes. In Problems and this is to be overcome by using a recursive module structure that describes treelike hardware. In a correct solution the critical path will be closer to log n and the cost will be lower too.
The synthesis output below shows the result of synthesizing the comb base module and a correct solution to Problem at exponentially increasing string lengths n Notice that in the comb version the delay too increases exponentially in proportion to n while the delay in the Problem solution increases more linearly. Absolute costs are lower too.
pmatchbasen
pmatchbasen
pmatchbasen
pmatchbasen
Testbench
To compile your code and run the testbench press F in an Emacs buffer in a properly set up
account. The testbench will apply inputs to several instantiations of modules pmatchbase and
pmatchmark. The instantiations differ in the length of the string. At the end of execution the
number of errors for each module at each size are shown. The output below is from a correctly
solved assignment:
Total pmatchbase n: Errors: clopmk
Total pmatchbase n: Errors: clopmk
Total pmatchbase n: Errors: clopmk
Total pmatchbase n: Errors: clopmk
Total pmatchbase n: Errors: clopmk
Total pmatchbase n: Errors: clopmk
Total pmatchmark n: Errors: clopmk
Total pmatchmark n: Errors: clopmk
Total pmatchmark n: Errors: clopmk
Total pmatchmark n: Errors: clopmk
Total pmatchmark n: Errors: clopmk
Total pmatchmark n: Errors: clopmk
Each line starting with Total shows a tally of results. After Total the line shows the module name,
either pmatchbase or pmatchmark, and n the length of the string. A tally of each output's error
is shown after Errors:, cl is the number of incorrect closingparentheses values, op is the number
of openingparenthesis values, and mk is the number of incorrectly marked strings.
Further up the testbench shows sample output and error details. For each instantiation the
first nerrorsshow incorrect outputs are shown on lines starting with Error. If it would
help to see more then feel free to search for nerrorsshow and increase the value. In addition the
details of the first nsamplesshow correct outputs are shown on lines starting with Sample.
The output below shows correct outputs:
Starting pmat
The testbench starts applying patterns found
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
