libmya 0.1.0
Library to parse Mya language.
Loading...
Searching...
No Matches
tkstack.c
Go to the documentation of this file.
1#include <stdlib.h>
2
3#include "ast.h"
4#include "tkstack.h"
5#include "types/err.h"
6
7void
9
10void
18
19void
21{
22 free(stack->values);
23 stack->values = NULL;
24}
25
26void
33
36{
38 return NULL;
39 }
40
41 return stack->values[--stack->length];
42}
43
46{
48 return NULL;
49 }
50
51 return stack->values[stack->length - 1];
52}
53
54bool
56{
57 return stack->length == 0;
58}
59
60void
62{
63 if (stack->length < stack->_size) {
64 return;
65 }
66
68 stack->values = realloc(stack->values, sizeof(token_t*) * stack->_size);
69}
A struct representing a dynamic stack.
Definition aststack.h:12
unsigned int length
Number of elements on the stack.
Definition aststack.h:14
ast_node_t * values
Array of values on the stack.
Definition aststack.h:13
unsigned int _size
Current number of elements that fits on the stack.
Definition aststack.h:15
Struct for a Mya token.
Definition token.h:34
token_t * tkstack_peek(tkstack_t *stack)
Peeks the value on top of the stack without removing it.
Definition tkstack.c:45
void _tkstack_ensure_size(tkstack_t *stack)
Definition tkstack.c:61
bool tkstack_isempty(tkstack_t *stack)
Check if the given stack is empty.
Definition tkstack.c:55
token_t * tkstack_pop(tkstack_t *stack)
Pop a value from the stack.
Definition tkstack.c:35
void tkstack_close(tkstack_t *stack)
Closes the given stack.
Definition tkstack.c:20
void tkstack_init(tkstack_t *stack)
Initializes the given stack.
Definition tkstack.c:11
void tkstack_push(tkstack_t *stack, token_t *token)
Push a new value on the stack.
Definition tkstack.c:27
#define TKSTACK_LENGTH_INCREMENT
Definition tkstack.h:6
#define TKSTACK_INITIAL_LENGTH
Definition tkstack.h:5
struct tkstack tkstack_t
A struct representing a dynamic stack of token_t pointers.
struct token token_t
Struct for a Mya token.