libmya 0.1.0
Library to parse Mya language.
Loading...
Searching...
No Matches
eval_include.c
Go to the documentation of this file.
1#include "evaluator.h"
2#include "mir.h"
3#include "module.h"
4#include "mya.h"
5#include "types/keywords.h"
6
7void
9{
10 if (ast->type != NT_STATEMENT || ast->token->value != KEY_INCLUDE) {
12 module,
13 ast->token->line,
14 ast->token->column,
15 ast->token->lexeme.length,
16 "Unexpected token where is expected an include statement."
17 );
18
19 return;
20 }
21
22 token_t* token_path = ast->children[0].token;
24 if (module_init(submodule, token_path->lexeme.data) != ERR_OK) {
26 module,
27 token_path->line,
28 token_path->column,
29 token_path->lexeme.length,
30 "File not found. You should use an absolute path or a relative path from the current working directory."
31 );
32
33 return;
34 }
35
36 if (mya_lexer(submodule) != ERR_OK) {
37 return;
38 }
39
40 if (mya_parser(submodule) != ERR_OK) {
41 return;
42 }
43
44 mya_evaluator(mir, submodule);
45}
@ ERR_OK
Definition err.h:15
void eval_include(mir_t *mir, module_t *module, ast_node_t *ast)
Evaluates an include statement.
Definition eval_include.c:8
error_code_t mya_evaluator(mir_t *mir, module_t *module)
Make the semantic analysis on the given module and evaluates the statements, constructing the in-memo...
Definition evaluator.c:6
@ 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:119
error_code_t module_init(module_t *module, const char *filepath)
Initialize a module struct.
Definition module.c:18
module_t * module_add_submodule(module_t *module)
Add submodule for the given module.
Definition module.c:108
error_code_t mya_parser(module_t *module)
Make the syntactical analysis on the given module and construct the AST.
Definition parser.c:12
error_code_t mya_lexer(module_t *module)
Make the lexical analysis on the given module.
Definition lexer.c:53
token_t * token
Definition ast.h:30
struct ast_node * children
Definition ast.h:31
node_type_t type
Definition ast.h:29
unsigned int length
The length of the string.
Definition dstring.h:13
char * data
Pointer for the raw string content (a normal C string).
Definition dstring.h:12
Mya in-memory intermediate representation.
Definition mir.h:117
Struct that represents a Mya module.
Definition module.h:36
long long int value
Integer value of the token.
Definition token.h:38
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
@ NT_STATEMENT
Definition ast.h:21
struct mir mir_t
Mya in-memory intermediate representation.
struct module module_t
Struct that represents a Mya module.
struct token token_t
Struct for a Mya token.