Hardware interview practice
Validate nested protocol delimiters
Consume a framed stream containing two kinds of open and close delimiters. Report whether nesting is balanced and return the first mismatch, underflow, overflow, or unfinished-open error.
Reviewed example
Work through one case
Input
accepted frame=[OPEN_A,OPEN_B,CLOSE_B,CLOSE_A] with one stall between the middle tokensExpected output
balanced=1; error=NONEParser state advances only on accepted tokens, and each close matches the most recent open type in strict stack order.
What to cover
Requirements
- Assume the producer ends each frame within 16 accepted tokens; enforce a nesting depth of at most eight.
- Update parser state only on an accepted token and keep consuming after the first error.
- Each close must match the most recent open of the same type.
- Hold the final result stable until it is accepted.
