18{
23 unsigned int ntokens = 0;
24
27 }
28
30
31 for (;;) {
32 current_token = &
token[ntokens];
33
34 switch (current_token->
type) {
38
45 "Open parentheses starting here has not a expected close parentheses matching it."
46 );
47
48 return ntokens;
49 }
50
51 ntokens++;
52 break;
56 ntokens++;
57 break;
59 ntokens += _parse_operator(
module, parent, &
stack, current_token);
60 break;
62 ntokens += _parse_binary_operator(
module, parent, &
stack, current_token);
63 break;
70 goto finish_expression;
71 default:
77 "Unexpected token inside an expression."
78 );
79
80 ntokens++;
81 goto finish_expression;
82 }
83 }
84
85
86finish_expression:
87
88
92 return ntokens;
93 }
94
96
99
105 "Unexpected expression starting here."
106 );
107
109 return ntokens;
110 }
111
114 return ntokens;
115}
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.
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 }...
void stack_init(stack_t *stack)
Initializes the given stack.
ast_node_t * stack_push(stack_t *stack, node_type_t type, token_t *token)
Push a new value on the stack.
void stack_close(stack_t *stack)
Closes the given stack.
error_code_t stack_pop(stack_t *stack, ast_node_t *value)
Pop a value from the stack.
bool stack_isempty(stack_t *stack)
Check if the given stack is empty.
unsigned int length
The length of the string.
Struct that represents a Mya module.
A struct representing a dynamic stack.
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.
struct ast_node ast_node_t
struct stack stack_t
A struct representing a dynamic stack.
struct token token_t
Struct for a Mya token.