40 lines
774 B
C
40 lines
774 B
C
#ifndef STACK_H
|
|
#define STACK_H
|
|
|
|
#include <stdlib.h>
|
|
|
|
union element_type
|
|
{
|
|
int operand;
|
|
char operator;
|
|
};
|
|
|
|
enum element_tag {
|
|
TOKEN_OPERAND,
|
|
TOKEN_OPERATOR
|
|
};
|
|
|
|
struct expression_element {
|
|
enum element_tag tag;
|
|
union element_type data;
|
|
};
|
|
|
|
struct stack {
|
|
struct expression_element data;
|
|
struct stack *next;
|
|
};
|
|
|
|
/* Push a new element to the stack and returns the new top */
|
|
struct stack *stack_push(struct stack *s, struct expression_element element);
|
|
|
|
/* Pop from the stack and returns its new top */
|
|
struct stack *stack_pop(struct stack *s);
|
|
|
|
/* Empty and frees the whole stack */
|
|
void stack_destroy(struct stack **s);
|
|
|
|
/* Returns the current top of the stack */
|
|
struct expression_element stack_peek(struct stack *s);
|
|
|
|
|
|
#endif /* ! STACK_H */ |