diff options
author | Carlos Maniero <carlos@maniero.me> | 2023-05-08 23:53:41 -0300 |
---|---|---|
committer | Johnny Richard <johnny@johnnyrichard.com> | 2023-05-09 08:50:53 +0200 |
commit | aba7302e7e98fd7bca2056d8ad622d9ca81c495f (patch) | |
tree | 59b4de4d4946f622b97ca7b6e1ded4d1e9cebbe5 /src/parser.c | |
parent | ccd5e8585f10488eed72c772cc1804efea6b8fb4 (diff) |
parser: Add the bool type
This commit introduces a new type for booleans. There is no code
generation for this type yet. The intention of this commit is to enable
flow control in the near future.
Signed-off-by: Carlos Maniero <carlos@maniero.me>
Reviewed-by: Johnny Richard <johnny@johnnyrichard.com>
Diffstat (limited to 'src/parser.c')
-rw-r--r-- | src/parser.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/parser.c b/src/parser.c index baa2ef5..22313a6 100644 --- a/src/parser.c +++ b/src/parser.c @@ -84,6 +84,11 @@ parser_parse_type(parser_t *parser, type_t *type) return true; } + if (string_view_eq(token.value, string_view_from_str("bool"))) { + *type = TYPE_BOOL; + return true; + } + parser_error_t error; error.token = token; @@ -102,6 +107,12 @@ parser_literal_integer_node(token_t *token) return ast_node_new_literal_integer(atoi(number_as_str)); } +static ast_node_t * +parser_literal_bool_node(token_t *token) +{ + return ast_node_new_literal_bool(token->kind == TOKEN_TRUE); +} + static ast_binary_operation_kind_t token_to_binary_operation_kind(token_t *token) { @@ -128,6 +139,10 @@ parser_parse_factor(parser_t *parser) switch (token.kind) { case TOKEN_NUMBER: return parser_literal_integer_node(&token); + case TOKEN_TRUE: + return parser_literal_bool_node(&token); + case TOKEN_FALSE: + return parser_literal_bool_node(&token); case TOKEN_OPAREN: { ast_node_t *expression = parser_parse_expression(parser); |