libmya 0.1.0
Library to parse Mya language.
Loading...
Searching...
No Matches
parse_statement_set.c File Reference
#include "ast.h"
#include "module.h"
#include "parser.h"
Include dependency graph for parse_statement_set.c:

Go to the source code of this file.

Functions

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.
 

Function Documentation

◆ parse_statement_set()

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.

Parameters
moduleThe module where the AST is.
parentThe AST node parent for the statement.
tokenThe token where to start parsing the statement.
Returns
The number of tokens used on the statement.

Definition at line 6 of file parse_statement_set.c.

7{
8 ast_node_t* node_statement = ast_add_children(parent, NT_STATEMENT, token);
9 token_t* tkid = token + 1;
10 token_t* tkequal = token + 2;
11 token_t* tkexpr = token + 3;
12
13 if (tkid->type != TK_IDENTIFIER) {
15 module,
16 tkid->line,
17 tkid->column,
18 tkid->lexeme.length,
19 "Expected an identifier here. Example: set NAME = value;"
20 );
21
22 return 1;
23 }
24
25 if (tkequal->type != TK_EQUAL) {
27 module,
28 tkequal->line,
29 tkequal->column,
30 tkequal->lexeme.length,
31 "Expected an equal operator here. Example: set NAME = value;"
32 );
33 }
34
35 ast_add_children(node_statement, NT_IDENTIFIER, tkid);
36 parse_expression(module, node_statement, tkexpr);
37
38 return 3;
39}
ast_node_t * ast_add_children(ast_node_t *parent, node_type_t type, token_t *token)
Add a new children for the given AST node.
Definition ast.c:40
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:92
unsigned int parse_expression(module_t *module, ast_node_t *parent, token_t *token)
Parse a mathematical expression 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:32
token_type_t type
Token type.
Definition token.h:33
dstring_t lexeme
Lexeme of the token.
Definition token.h:37
unsigned int line
Token line inside the module.
Definition token.h:34
unsigned int column
Column of the token position on the line.
Definition token.h:35
struct ast_node ast_node_t
@ NT_IDENTIFIER
Definition ast.h:13
@ NT_STATEMENT
Definition ast.h:17
struct token token_t
Struct for a Mya token.
@ TK_IDENTIFIER
Definition token.h:17
@ TK_EQUAL
Definition token.h:16