25{
29 bool is_unary = false;
30 unsigned int ntokens = 0;
31
34 }
35
38
39 for (;;) {
40 current_token = &
token[ntokens++];
41
42 switch (current_token->
type) {
45 is_unary = true;
46 break;
50 is_unary = false;
51 break;
53 ntokens = _parse_bitfield_expression(
module, parent, &queue, current_token);
54 goto clean_and_exit;
58 }
59
63 }
64
66 is_unary = true;
67 break;
69 for (;;) {
71 if (! popped) {
77 "Close parentheses here is not matching a open parentheses."
78 );
79
80 goto clean_and_exit;
81 }
82
84 break;
85 }
86
88 }
89
90 is_unary = false;
91 break;
97 ntokens--;
98 goto finish_expression;
99 default:
105 "Unexpected token inside an expression."
106 );
107
108 ntokens++;
109 goto finish_expression;
110 }
111 }
112
113
114finish_expression:
117 }
118
119 _generate_ast(
module, parent, &queue);
120
121clean_and_exit:
124
125 return ntokens;
126}
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_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.
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.
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 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.