blob: 14f659e8f00e8690b289142a82d42292c86490d3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#include "stack.h"
#include <stdlib.h>
struct stack *stack_push(struct stack *s, int e)
{
struct stack *new = malloc(sizeof(struct stack));
new->data = e;
new->next = NULL;
new->next = s;
return new;
}
struct stack *stack_pop(struct stack *s)
{
if (s == NULL)
{
return NULL;
}
struct stack *res = s->next;
free(s);
return res;
}
int stack_peek(struct stack *s)
{
return s->data;
}
struct tstack *tstack_push(struct tstack *s, struct token *e)
{
struct tstack *new = malloc(sizeof(struct tstack));
new->token = e;
new->next = NULL;
new->next = s;
return new;
}
struct tstack *tstack_pop(struct tstack *s)
{
if (s == NULL)
{
return NULL;
}
struct tstack *res = s->next;
free(s);
return res;
}
struct token *tstack_peek(struct tstack *s)
{
return s->token;
}
|