-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.h
63 lines (50 loc) · 1.85 KB
/
stack.h
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
58
59
60
61
62
63
/**
* @file stack.h
* @project Compiler of language IFJ18. School project from subjects IFJ and IAL.
* @date October 2018
* @author Juraj Holub <[email protected]>
* @brief Stack used in sentactic and semantic analyses.
*/
#ifndef _STACK_H_IFJ_18_
#define _STACK_H_IFJ_18_
#include "scanner.h"
#include "symtable.h"
#include <stdbool.h>
typedef struct syntax_s {
token_t *token;
int mark; ///< Number of mark of this item in stack.
bool is_term; ///< True if this item of stack is term, else its nonterm.
} syntax_t;
typedef struct semantic_s {
string_t value;
} semantic_t;
typedef struct stack_item_s {
struct stack_item_s *prev; ///< Previous item in stack (nearer to bottom).
struct stack_item_s *next; ///< Next item in stack (nearer to top).
void *data;
} stack_item_t;
typedef struct stack_s {
stack_item_t *bot; ///< Bottom of the stack.
stack_item_t *top; ///< Top of the stack.
} stack_t;
/************************ GENERAL OPERATION WITH STACK ***********************/
void stack_init(stack_t *stack);
void stack_push(stack_t *stack, void *item);
void stack_pop(stack_t *stack);
void* stack_top(stack_t *stack);
bool stack_empty(stack_t *stack);
/****************************** SYNTAX STACK *********************************/
stack_item_t* get_marked_part(stack_t *stack);
stack_item_t* get_top_term(stack_t *stack);
void mark_stack_term(stack_t *stack);
void free_mark(stack_t *stack);
syntax_t* alloc_syntax_item(token_t *token, table_item_t *hash_tb);
void free_syntax_stack(stack_t *stack);
void free_syntax_item(syntax_t *item);
stack_t* init_syntax_stack();
void print_stack(stack_t *stack);
/****************************** SEMANTIC STACK *******************************/
stack_t* init_sem_stack();
void free_sem_stack(stack_t *stack);
void print_sem_stack(stack_t *sem_stack);
#endif // _STACK_H_IFJ_18_