18{
23 unsigned int ntokens = 0;
24
26
27 for (;;) {
28 current_token = &
token[ntokens];
29
30 switch (current_token->
type) {
34
41 "Open parentheses starting here has not a expected close parentheses matching it."
42 );
43
44 return ntokens;
45 }
46
47 ntokens++;
48 break;
52 ntokens++;
53 break;
55 ntokens += _parse_operator(
module, parent, &
stack, current_token);
56 break;
58 ntokens++;
62 goto finish_expression;
63 default:
69 "Unexpected token inside an expression."
70 );
71
72 ntokens++;
73 goto finish_expression;
74 }
75 }
76
77
78finish_expression:
79
80
83 return ntokens;
84 }
85
87
90
96 "Unexpected expression starting here."
97 );
98
99 return ntokens + 1;
100 }
101
103
104 return ntokens + 1;
105}
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.
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.
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.