Files
ivy/lang/ast/expr/expr.c

38 lines
1.0 KiB
C
Raw Normal View History

#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(SEMICOLON, arith_parse_semicolon),
SYM_PARSER(DOT, arith_parse_dot),
},
};