CS 112 - Lab 2
Balancing Symbols via Linked Stacks


Section 1: Introduction

The goal of this lab is to:

If you have not already done so, create a directory for this lab and copy the lab 2 files into it. If you start off in your home directory you can do the following:

	mkdir ~/cs112/lab2
	cd ~/cs112/lab2
	cp ~cs112/lab2/* .

Section 2: Topics for Lecture

This week's lecture will include

Section 3: Balancing Symbols

Compilers check your programs for syntax, but frequently a missing symbol (such as a missing brace or comment starter) will cause the compiler to generate numerous lines of diagnostics without identifying the real error.

A useful tool is a program that checks whether all symbols are balanced. Thus, every right brace, bracket, and parenthesis must correspond to its left counterpart. The sequence [()] is legal, but [(]) is wrong. In this lab, you will only be concerned with the balancing of ()'s and []'s; all other characters are ignored.

You are to implement the algorithm below for symbol balancing based on linked stacks. There are three error conditions which must be appropriately labeled and formatted for screen output.

Section 4: Code Development

You must use the following declarations for all stack functions created:
                typedef char StackEntry;

                typedef struct node {
                        StackEntry      entry;
                        struct node     *next;
                } Node;

                typedef struct stack {
                        Node *top;
                } Stack;

You must use this declaration before your main( ) function:
                typedef enum boolean_tag { FALSE, TRUE } Boolean;
The prototypes for the stack functions you must create are:
                Node *MakeNode(StackEntry item);
                void Pop(StackEntry *item, Stack *s);
                void Push(StackEntry item, Stack *s);
                Boolean StackEmpty(Stack *s);
                Boolean StackFull(void);
                void CreateStack(Stack *s);
Be sure to test your program with a variety of input (provided in datafile). Be sure that each Error Condition is appropriately captured. The TA's will be grading your program with a variety of input files in order to test correctness.

Section 5: Handing in your C code and answers

When you have completed this lab assignment, you should have the following program(s) in your ~/cs112/lab2 directory: Then, to submit your program(s) for grading, issue the command
 ~cs112/submit lab2 
at your UNIX prompt. This utility program will copy your programs for grading and an electronic mail message will be sent to you to acknowledge your submission. You may check the status of your submission at any time by typing the command
 ~cs112/query lab2 
at your UNIX prompt. You will automatically receive an electronic mail message confirming the status of your lab submission.

You should also answer the questions below and submit them in hardcopy to the TAs at the beginning of Lab 3 on February 14 (no late submissions accepted).

This week's questions

For credit on this lab, your software must be received by midnight February 13 and your answers to the lab questions must be received at the beginning of your lab section (8:00am or 11:10am) on Friday, February 14.

Note: Always bring your ID with you to lab.