diff --git a/lang/ast/atom.c b/lang/ast/atom.c new file mode 100644 index 0000000..a4f9d6d --- /dev/null +++ b/lang/ast/atom.c @@ -0,0 +1,18 @@ +#include "ctx.h" +#include "node.h" + +#include + +static void print(struct ivy_ast_node *node) +{ + struct ivy_ast_atom_node *v = (struct ivy_ast_atom_node *)node; + + printf("%s (%s)\n", ivy_ast_node_type_to_string(node->n_type), + v->n_content->t_str); +} + +struct ast_node_type atom_node_ops = { + .n_print = print, + .n_state_size = sizeof(struct parser_state), + .n_node_size = sizeof(struct ivy_ast_atom_node), +}; diff --git a/lang/ast/expr/arith.c b/lang/ast/expr/arith.c index 91fe4a8..ecc0c28 100644 --- a/lang/ast/expr/arith.c +++ b/lang/ast/expr/arith.c @@ -79,6 +79,14 @@ enum ivy_status arith_push_operand( b_queue_push_back(&state->s_output_queue, &v->n_base.n_entry); break; } + case IVY_TOK_ATOM: { + struct ivy_ast_atom_node *v + = (struct ivy_ast_atom_node *)ast_node_create( + IVY_AST_ATOM); + v->n_content = tok; + b_queue_push_back(&state->s_output_queue, &v->n_base.n_entry); + break; + } case IVY_TOK_STRING: { struct ivy_ast_string_node *v = (struct ivy_ast_string_node *)ast_node_create( diff --git a/lang/ast/expr/expr.c b/lang/ast/expr/expr.c index bce7c6d..78a7698 100644 --- a/lang/ast/expr/expr.c +++ b/lang/ast/expr/expr.c @@ -24,6 +24,7 @@ struct ast_node_type expr_node_ops = { TOK_PARSER(IDENT, arith_parse_ident), TOK_PARSER(INT, arith_parse_operand), TOK_PARSER(DOUBLE, arith_parse_operand), + TOK_PARSER(ATOM, arith_parse_operand), TOK_PARSER(STRING, arith_parse_operand), TOK_PARSER(SYMBOL, arith_parse_operator), TOK_PARSER(LABEL, arith_parse_label), diff --git a/lang/ast/node.c b/lang/ast/node.c index 2584156..483539a 100644 --- a/lang/ast/node.c +++ b/lang/ast/node.c @@ -18,6 +18,7 @@ extern struct ast_node_type op_node_ops; extern struct ast_node_type ident_node_ops; extern struct ast_node_type int_node_ops; extern struct ast_node_type double_node_ops; +extern struct ast_node_type atom_node_ops; extern struct ast_node_type string_node_ops; extern struct ast_node_type cascade_node_ops; extern struct ast_node_type cond_group_node_ops; @@ -42,6 +43,7 @@ static const struct ast_node_type *node_ops[] = { [IVY_AST_IDENT] = &ident_node_ops, [IVY_AST_INT] = &int_node_ops, [IVY_AST_DOUBLE] = &double_node_ops, + [IVY_AST_ATOM] = &atom_node_ops, [IVY_AST_STRING] = &string_node_ops, [IVY_AST_CASCADE] = &cascade_node_ops, [IVY_AST_COND_GROUP] = &cond_group_node_ops,