libmya 0.1.0
Library to parse Mya language.
Loading...
Searching...
No Matches
parser.c
Go to the documentation of this file.
1#include <stdlib.h>
2
3#include "ast.h"
4#include "mya.h"
5#include "parser.h"
6#include "types/token.h"
7
10{
12
13 for (unsigned int tk_index = 0; tk_index < module->tokens_count; tk_index++) {
14 token = &module->tokens[tk_index];
15
16 switch (token->type) {
17 case TK_KEYWORD:
18 tk_index += parse_statement(module, &module->ast, token) - 1;
19 break;
20 default:
21 return ERR_EMPTY;
22 }
23 }
24
25 return ERR_OK;
26}
enum error_code error_code_t
Enumeration of error codes.
@ ERR_OK
Definition err.h:15
@ ERR_EMPTY
Definition err.h:16
error_code_t mya_parser(module_t *module)
Make the syntactical analysis on the given module and construct the AST.
Definition parser.c:9
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.
Struct that represents a Mya module.
Definition module.h:34
ast_node_t ast
AST of the module.
Definition module.h:37
unsigned int tokens_count
Number of tokens on tokens list.
Definition module.h:39
Struct for a Mya token.
Definition token.h:32
token_type_t type
Token type.
Definition token.h:33
struct module module_t
Struct that represents a Mya module.
struct token token_t
Struct for a Mya token.
@ TK_KEYWORD
Definition token.h:18