libmya 0.1.0
Library to parse Mya language.
Loading...
Searching...
No Matches
parser.c File Reference
#include <stdlib.h>
#include "ast.h"
#include "mya.h"
#include "parser.h"
#include "types/token.h"
Include dependency graph for parser.c:

Go to the source code of this file.

Functions

error_code_t mya_parser (module_t *module)
 Make the syntactical analysis on the given module and construct the AST.
 

Function Documentation

◆ mya_parser()

error_code_t mya_parser ( module_t * module)

Make the syntactical analysis on the given module and construct the AST.

Parameters
moduleThe module for make the syntactical analysis.

Definition at line 9 of file parser.c.

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}
@ ERR_OK
Definition err.h:15
@ ERR_EMPTY
Definition err.h:16
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 token token_t
Struct for a Mya token.
@ TK_KEYWORD
Definition token.h:18