-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsymtab_stack_2.c
More file actions
53 lines (45 loc) · 1.04 KB
/
symtab_stack_2.c
File metadata and controls
53 lines (45 loc) · 1.04 KB
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
#include "symtab.h"
/**
* symtab_stack_add - Add a symbol table to the stack
* @symtab: The symbol table
*
*/
void symtab_stack_add(ST_strc *symtab)
{
symtab_stack.symtab_list[symtab_stack.symtab_count++] = symtab;
symtab_stack.local_symtab = symtab;
}
/**
* symtab_stack_push - Push a new symbol table onto the stack
* Return: The new symbol table
*/
ST_strc *symtab_stack_push(void)
{
ST_strc *st = new_symtab(++symtab_level);
symtab_stack_add(st);
return (st);
}
/**
* symtab_stack_pop - Pop the top symbol table from the stack
* Return: The popped symbol table
*/
ST_strc *symtab_stack_pop(void)
{
ST_strc *st;
if (symtab_stack.symtab_count == 0)
return (NULL);
st = symtab_stack.symtab_list[symtab_stack.symtab_count - 1];
symtab_stack.symtab_list[--symtab_stack.symtab_count] = NULL;
symtab_level--;
if (symtab_stack.symtab_count == 0)
{
symtab_stack.local_symtab = NULL;
symtab_stack.global_symtab = NULL;
}
else
{
symtab_stack.local_symtab =
symtab_stack.symtab_list[symtab_stack.symtab_count - 1];
}
return (st);
}