CS140 Midterm Exam - October 5, 2004 - Page 7


Relevant things from fields.h, dllist.h, queue.h, stack.h

typedef struct inputstruct {
  char *name;               /* File name */
  FILE *f;                  /* File descriptor */
  int line;                 /* Line number */
  char text1[MAXLEN];       /* The line */
  int NF;                   /* Number of fields */
  char *fields[MAXFIELDS];  /* Pointers to fields */
  ...
} *IS;

extern IS new_inputstruct(/* FILENAME -- NULL for stdin */);
extern int get_line(/* IS */); /* returns NF, or -1 on EOF.  Does not
                                  close the file */

typedef struct dllist { struct dllist *flink; struct dllist *blink; Jval val; } *Dllist; extern Dllist new_dllist(); extern void free_dllist(Dllist); extern void dll_append(Dllist, Jval); extern void dll_prepend(Dllist, Jval); extern void dll_insert_b(Dllist, Jval); extern void dll_insert_a(Dllist, Jval); extern void dll_delete_node(Dllist); extern int dll_empty(Dllist);
typedef void *Stack; Stack new_stack(); /* Create an empty stack */ void stack_push(Stack s, Jval jv); /* Push an element onto the stack */ Jval stack_pop(Stack s); /* Pop an element off the stack. Will exit with an error if the stack is empty */ int stack_empty(Stack s); /* This is a boolean function that returns 1 if there are no elements on the stack, and 0 if there are elements on the stack. */
typedef void *Queue; Queue new_queue(); /* Create an empty queue */ void queue_enqueue(Queue q, Jval jv); Jval queue_dequeue(Queue q); int queue_empty(Queue q); /* This is a boolean function that returns 1 if there are no elements on the queue, and 0 if there are elements on the queue. */
typedef union { int i; long l; ... char *s; ... } Jval; extern Jval new_jval_s(char *);