lang: ast: re-factor expression parser into multiple files
This commit is contained in:
36
lang/ast/expr/expr.c
Normal file
36
lang/ast/expr/expr.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "expr.h"
|
||||
|
||||
#include "../node.h"
|
||||
|
||||
static enum ivy_status add_child(
|
||||
struct parser_state *parent, struct ivy_ast_node *child)
|
||||
{
|
||||
struct expr_parser_state *state = (struct expr_parser_state *)parent;
|
||||
switch (state->s_type) {
|
||||
case EXPR_TYPE_STMT:
|
||||
return IVY_ERR_NOT_SUPPORTED;
|
||||
case EXPR_TYPE_ARITH:
|
||||
return arith_add_child(parent, child);
|
||||
default:
|
||||
return IVY_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
struct ast_node_type expr_node_ops = {
|
||||
.n_add_child = add_child,
|
||||
.n_state_size = sizeof(struct expr_parser_state),
|
||||
.n_node_size = sizeof(struct ivy_ast_expr_node),
|
||||
.n_token_parsers = {
|
||||
TOK_PARSER(IDENT, arith_parse_ident),
|
||||
TOK_PARSER(INT, arith_parse_operand),
|
||||
TOK_PARSER(DOUBLE, arith_parse_operand),
|
||||
TOK_PARSER(STRING, arith_parse_operand),
|
||||
TOK_PARSER(SYMBOL, arith_parse_operator),
|
||||
TOK_PARSER(LABEL, arith_parse_label),
|
||||
},
|
||||
.n_symbol_parsers = {
|
||||
SYM_PARSER(LEFT_PAREN, arith_parse_left_paren),
|
||||
SYM_PARSER(RIGHT_PAREN, arith_parse_right_paren),
|
||||
SYM_PARSER(DOT, arith_parse_dot),
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user