2024-12-03 13:26:55 +00:00
|
|
|
#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),
|
2024-12-06 13:46:41 +00:00
|
|
|
TOK_PARSER(ATOM, arith_parse_operand),
|
2024-12-03 13:26:55 +00:00
|
|
|
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),
|
2024-12-03 21:57:44 +00:00
|
|
|
SYM_PARSER(SEMICOLON, arith_parse_semicolon),
|
2024-12-04 22:22:25 +00:00
|
|
|
SYM_PARSER(UNDERSCORE, arith_parse_operand),
|
2024-12-06 10:01:56 +00:00
|
|
|
SYM_PARSER(CARET, arith_parse_caret),
|
2024-12-04 22:22:25 +00:00
|
|
|
SYM_PARSER(COMMA, arith_parse_comma),
|
2024-12-03 13:26:55 +00:00
|
|
|
SYM_PARSER(DOT, arith_parse_dot),
|
2024-12-06 13:22:33 +00:00
|
|
|
SYM_PARSER(BANG, arith_parse_bang),
|
2024-12-04 22:22:25 +00:00
|
|
|
SYM_PARSER(EQUAL_RIGHT_ANGLE, arith_parse_equal_right_angle),
|
2024-12-03 13:26:55 +00:00
|
|
|
},
|
2024-12-04 16:35:19 +00:00
|
|
|
.n_keyword_parsers = {
|
2024-12-04 22:22:25 +00:00
|
|
|
/* statement keywords */
|
2024-12-06 10:02:31 +00:00
|
|
|
KW_PARSER(FOR, stmt_parse_for),
|
2024-12-05 19:29:21 +00:00
|
|
|
KW_PARSER(WHILE, stmt_parse_while),
|
2024-12-04 22:22:25 +00:00
|
|
|
KW_PARSER(MATCH, stmt_parse_match),
|
2024-12-04 16:35:19 +00:00
|
|
|
KW_PARSER(IF, stmt_parse_if),
|
2024-12-05 19:29:21 +00:00
|
|
|
KW_PARSER(THEN, stmt_parse_end),
|
|
|
|
|
KW_PARSER(ELSE, stmt_parse_end),
|
2024-12-04 16:35:19 +00:00
|
|
|
KW_PARSER(END, stmt_parse_end),
|
2024-12-04 22:22:25 +00:00
|
|
|
|
2024-12-06 10:02:31 +00:00
|
|
|
/* operator/block keywords */
|
2024-12-04 22:22:25 +00:00
|
|
|
KW_PARSER(IN, arith_parse_in),
|
2024-12-06 10:02:31 +00:00
|
|
|
KW_PARSER(DO, arith_parse_do),
|
2024-12-04 16:35:19 +00:00
|
|
|
}
|
2024-12-03 13:26:55 +00:00
|
|
|
};
|