libmya 0.1.0
Library to parse Mya language.
Loading...
Searching...
No Matches
evaluator.c File Reference
#include "evaluator.h"
#include "mya.h"
#include "types/keywords.h"
Include dependency graph for evaluator.c:

Go to the source code of this file.

Functions

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-memory intermediate representation.
 

Function Documentation

◆ mya_evaluator()

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-memory intermediate representation.

Parameters
mirWhere the intermediate representation will be added.
moduleThe module to be evaluated.
Returns
ERR_INVALID_CODE on evaluator found some errors on module.
ERR_OK on finished successful.

Definition at line 6 of file evaluator.c.

7{
8 ast_node_t* current;
9
10 for (int i = 0; i < module->ast.children_count; i++) {
11 current = &module->ast.children[i];
12
13 switch (current->token->value) {
14 case KEY_INCLUDE:
15 eval_include(mir, module, current);
16 break;
17 case KEY_SET:
18 eval_set(mir, module, current);
19 break;
20 case KEY_BITFIELD:
21 eval_bitfield(mir, module, current);
22 break;
23 case KEY_REGISTER:
24 eval_register(mir, module, current);
25 break;
26 case KEY_INST:
27 break;
28 default:
30 module,
31 current->token->line,
32 current->token->column,
33 current->token->lexeme.length,
34 "It's an invalid statement keyword. Are you sure it's a valid command or declaration?"
35 );
36
37 return ERR_INVALID_CODE;
38 }
39 }
40 return ERR_OK;
41}
@ ERR_INVALID_CODE
Definition err.h:18
@ ERR_OK
Definition err.h:15
void eval_bitfield(mir_t *mir, module_t *module, ast_node_t *ast)
Evaluates a bitfield statement.
void eval_include(mir_t *mir, module_t *module, ast_node_t *ast)
Evaluates an include statement.
Definition eval_include.c:8
void eval_register(mir_t *mir, module_t *module, ast_node_t *ast)
Evaluates a register statement.
void eval_set(mir_t *mir, module_t *module, ast_node_t *ast)
Evaluates a set statement.
Definition eval_set.c:8
@ 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:119
unsigned int children_count
Definition ast.h:32
token_t * token
Definition ast.h:30
unsigned int length
The length of the string.
Definition dstring.h:13
Mya in-memory intermediate representation.
Definition mir.h:117
Struct that represents a Mya module.
Definition module.h:36
ast_node_t ast
AST of the module.
Definition module.h:39
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