29 bool is_unary =
false;
30 unsigned int ntokens = 0;
40 current_token = &
token[ntokens++];
42 switch (current_token->
type) {
53 ntokens = _parse_bitfield_expression(
module, parent, &queue, current_token);
77 "Close parentheses here is not matching a open parentheses."
98 goto finish_expression;
105 "Unexpected token inside an expression."
109 goto finish_expression;
119 _generate_ast(
module, parent, &queue);
145 if (_op_is_unary(
token)) {
183 "Bitfield expression expects a valid identifier before the `=`, like in: `some_identifier = Field { ... }`."
ast_node_t * ast_insert_children(ast_node_t *parent, ast_node_t *child)
Insert a exitent AST node as children of the given parent node.
ast_node_t * ast_add_children(ast_node_t *parent, node_type_t type, token_t *token)
Add a new children for the given AST node.
void aststack_close(aststack_t *stack)
Closes the given stack.
void aststack_init(aststack_t *stack)
Initializes the given stack.
error_code_t aststack_pop(aststack_t *stack, ast_node_t *value)
Pop a value from the stack.
ast_node_t * aststack_push(aststack_t *stack, node_type_t type, token_t *token)
Push a new value on the stack.
void module_add_error(module_t *module, unsigned int line, unsigned int column, unsigned int length, const char *message)
Add error for the given module.
unsigned int parse_expression(module_t *module, ast_node_t *parent, token_t *token)
Parse a mathematical expression adding it as a children on parent AST node.
unsigned int parse_bitfield_spec(module_t *module, ast_node_t *parent, token_t *token)
Parse a bitfield specification in the format Bitfield { FIELD_LIST } or Bitfield { EXPRESSION }...
unsigned int length
The length of the string.
Struct that represents a Mya module.
A struct representing a dynamic stack.
unsigned int length
Number of elements on the stack.
long long int value
Integer value of the token.
token_type_t type
Token type.
dstring_t lexeme
Lexeme of the token.
unsigned int line
Token line inside the module.
unsigned int column
Column of the token position on the line.
void tkqueue_add(tkqueue_t *queue, token_t *token)
Add a value to the token queue.
token_t * tkqueue_get(tkqueue_t *queue)
Get the current value from the queue and increment the position for the next value.
void tkqueue_init(tkqueue_t *queue, unsigned int initial_size)
Initializes the token queue.
void tkqueue_close(tkqueue_t *queue)
Close the given queue.
token_t * tkstack_peek(tkstack_t *stack)
Peeks the value on top of the stack without removing it.
bool tkstack_isempty(tkstack_t *stack)
Check if the given stack is empty.
token_t * tkstack_pop(tkstack_t *stack)
Pop a value from the stack.
void tkstack_close(tkstack_t *stack)
Closes the given stack.
void tkstack_init(tkstack_t *stack)
Initializes the given stack.
void tkstack_push(tkstack_t *stack, token_t *token)
Push a new value on the stack.
struct ast_node ast_node_t
struct stack aststack_t
A struct representing a dynamic stack.
struct module module_t
Struct that represents a Mya module.
struct tkqueue tkqueue_t
Queue of tokens.
struct tkstack tkstack_t
A struct representing a dynamic stack of token_t pointers.
struct token token_t
Struct for a Mya token.