diff --git a/lang/ast/const.c b/lang/ast/const.c new file mode 100644 index 0000000..2215e91 --- /dev/null +++ b/lang/ast/const.c @@ -0,0 +1,19 @@ +#include "ctx.h" +#include "node.h" + +#include + +struct ast_node_type c_true_node_ops = { + .n_state_size = sizeof(struct parser_state), + .n_node_size = sizeof(struct ivy_ast_node), +}; + +struct ast_node_type c_false_node_ops = { + .n_state_size = sizeof(struct parser_state), + .n_node_size = sizeof(struct ivy_ast_node), +}; + +struct ast_node_type c_null_node_ops = { + .n_state_size = sizeof(struct parser_state), + .n_node_size = sizeof(struct ivy_ast_node), +}; diff --git a/lang/ast/expr/arith.c b/lang/ast/expr/arith.c index 8511de8..3a88436 100644 --- a/lang/ast/expr/arith.c +++ b/lang/ast/expr/arith.c @@ -119,6 +119,15 @@ enum ivy_status arith_push_operand( case IVY_KW_CONTINUE: v = ast_node_create(IVY_AST_LOOP_REPEAT); break; + case IVY_KW_TRUE: + v = ast_node_create(IVY_AST_C_TRUE); + break; + case IVY_KW_FALSE: + v = ast_node_create(IVY_AST_C_FALSE); + break; + case IVY_KW_NULL: + v = ast_node_create(IVY_AST_C_NULL); + break; default: return IVY_ERR_BAD_SYNTAX; } diff --git a/lang/ast/expr/expr.c b/lang/ast/expr/expr.c index 7730258..82ccfee 100644 --- a/lang/ast/expr/expr.c +++ b/lang/ast/expr/expr.c @@ -91,6 +91,11 @@ struct ast_node_type expr_node_ops = { KW_PARSER(FINALLY, stmt_parse_end), KW_PARSER(END, stmt_parse_end), + /* keyword constants */ + KW_PARSER(TRUE, arith_parse_operand), + KW_PARSER(FALSE, arith_parse_operand), + KW_PARSER(NULL, arith_parse_operand), + /* operator/block keywords */ KW_PARSER(IN, arith_parse_in), KW_PARSER(IS, arith_parse_operator), diff --git a/lang/ast/expr/expr.h b/lang/ast/expr/expr.h index d62162c..99160d2 100644 --- a/lang/ast/expr/expr.h +++ b/lang/ast/expr/expr.h @@ -44,6 +44,7 @@ enum expr_component { EXPR_CMP_OPERATOR, EXPR_CMP_OPERAND, EXPR_CMP_MSG, + EXPR_CMP_KEYWORD, }; struct expr_parser_state { diff --git a/lang/ast/node.c b/lang/ast/node.c index b07aedb..e451693 100644 --- a/lang/ast/node.c +++ b/lang/ast/node.c @@ -42,6 +42,9 @@ extern struct ast_node_type pkg_dynamic_node_ops; extern struct ast_node_type discard_node_ops; extern struct ast_node_type try_node_ops; extern struct ast_node_type try_catch_node_ops; +extern struct ast_node_type c_true_node_ops; +extern struct ast_node_type c_false_node_ops; +extern struct ast_node_type c_null_node_ops; static const struct ast_node_type *node_ops[] = { [IVY_AST_UNIT] = &unit_node_ops, @@ -80,6 +83,9 @@ static const struct ast_node_type *node_ops[] = { [IVY_AST_DISCARD] = &discard_node_ops, [IVY_AST_TRY] = &try_node_ops, [IVY_AST_TRY_CATCH] = &try_catch_node_ops, + [IVY_AST_C_TRUE] = &c_true_node_ops, + [IVY_AST_C_FALSE] = &c_false_node_ops, + [IVY_AST_C_NULL] = &c_null_node_ops, }; static const size_t nr_node_ops = sizeof node_ops / sizeof node_ops[0]; @@ -129,6 +135,9 @@ enum token_expr_type get_token_expr_type(struct ivy_token *tok) case IVY_KW_CONTINUE: case IVY_KW_TRY: case IVY_KW_THROW: + case IVY_KW_TRUE: + case IVY_KW_FALSE: + case IVY_KW_NULL: return TOK_EXPR_BEGIN; default: op = ivy_operator_get_by_token(tok->t_keyword); @@ -379,6 +388,9 @@ const char *ivy_ast_node_type_to_string(enum ivy_ast_node_type v) ENUM_STR(IVY_AST_TRY); ENUM_STR(IVY_AST_TRY_CATCH); ENUM_STR(IVY_AST_TYPE_COUNT); + ENUM_STR(IVY_AST_C_TRUE); + ENUM_STR(IVY_AST_C_FALSE); + ENUM_STR(IVY_AST_C_NULL); default: return ""; }