libmya 0.1.0
Library to parse Mya language.
Loading...
Searching...
No Matches
parse_statement.c
Go to the documentation of this file.
1#include <string.h>
2
3#include "module.h"
4#include "parser.h"
5#include "types/keywords.h"
6
7unsigned int
9{
10 if (token->type != TK_KEYWORD) {
12 module,
13 token->line,
16 "This token is unexpected here. It's expected to be a valid statement keyword."
17 );
18
19 return 1;
20 }
21
22 switch (token->value) {
23 case KEY_INCLUDE:
24 return parse_statement_include(module, parent, token);
25 case KEY_SET:
26 return parse_statement_set(module, parent, token);
27 case KEY_BITFIELD:
28 return parse_statement_bitfield(module, parent, token);
29 case KEY_REGISTER:
30 return parse_statement_register(module, parent, token);
31 case KEY_INST:
32 return parse_statement_inst(module, parent, token);
33 default:
35 module,
36 token->line,
39 "It's an invalid statement keyword. Are you sure it's a valid command or declaration?"
40 );
41
42 return 1;
43 }
44}
@ KEY_INST
Definition keywords.h:8
@ KEY_SET
Definition keywords.h:10
@ KEY_BITFIELD
Definition keywords.h:5
@ KEY_REGISTER
Definition keywords.h:9
@ KEY_INCLUDE
Definition keywords.h:7
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.
Definition module.c:97
unsigned int parse_statement(module_t *module, ast_node_t *parent, token_t *token)
Parse a statement adding it as a children on parent AST node.
unsigned int parse_statement_inst(module_t *module, ast_node_t *parent, token_t *token)
Parse a inst statement adding it as a children on parent AST node.
unsigned int parse_statement_include(module_t *module, ast_node_t *parent, token_t *token)
Parse a include statement adding it as a children on parent AST node.
unsigned int parse_statement_register(module_t *module, ast_node_t *parent, token_t *token)
Parse a register statement adding it as a children on parent AST node.
unsigned int parse_statement_set(module_t *module, ast_node_t *parent, token_t *token)
Parse a set statement adding it as a children on parent AST node.
unsigned int parse_statement_bitfield(module_t *module, ast_node_t *parent, token_t *token)
Parse a bitfield statement adding it as a children on parent AST node.
unsigned int length
The length of the string.
Definition dstring.h:13
Struct that represents a Mya module.
Definition module.h:34
Struct for a Mya token.
Definition token.h:34
long long int value
Integer value of the token.
Definition token.h:38
token_type_t type
Token type.
Definition token.h:35
dstring_t lexeme
Lexeme of the token.
Definition token.h:41
unsigned int line
Token line inside the module.
Definition token.h:36
unsigned int column
Column of the token position on the line.
Definition token.h:37
struct ast_node ast_node_t
struct module module_t
Struct that represents a Mya module.
struct token token_t
Struct for a Mya token.
@ TK_KEYWORD
Definition token.h:20