summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/parser.c49
-rw-r--r--src/pipac.c20
-rw-r--r--src/vector.c2
3 files changed, 29 insertions, 42 deletions
diff --git a/src/parser.c b/src/parser.c
index e02d1fe..6b954c2 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -91,7 +91,7 @@ parser_parse_type(type_t *type, parser_t *parser)
return false;
}
-bool
+static bool
parser_literal_integer_node(ast_node_t *node, token_t *token)
{
char number_as_str[token->value.size];
@@ -118,35 +118,36 @@ token_to_binary_operation_kind(token_t *token)
}
}
-bool
+static bool
parser_parse_factor(parser_t *parser, ast_node_t *node)
{
token_t token;
lexer_next_token(parser->lexer, &token);
- if (token.kind == TOKEN_NUMBER) {
- return parser_literal_integer_node(node, &token);
- } else if (token.kind == TOKEN_OPAREN) {
- parser_parse_expression(parser, node);
- if (!drop_expected_token(parser, TOKEN_CPAREN))
+ switch (token.kind) {
+ case TOKEN_NUMBER:
+ return parser_literal_integer_node(node, &token);
+ case TOKEN_OPAREN:
+ if (!parser_parse_expression(parser, node))
+ return false;
+ if (!drop_expected_token(parser, TOKEN_CPAREN))
+ return false;
+ return true;
+ case TOKEN_NAME:
+ /// FIXME: Check if the identifier is defined
+ ast_node_init_identifier(node, token.value);
+ return true;
+ default: {
+ parser_error_t error;
+ error.token = token;
+ sprintf(error.message, "unexpected '%s (" SVFMT ")' token", token_kind_to_str(token.kind), SVARG(&token.value));
+ parser->errors[parser->errors_len++] = error;
return false;
- return true;
- } else if (token.kind == TOKEN_NAME) {
- /// FIXME: Check if the identifier is defined
- ast_node_init_identifier(node, token.value);
- return true;
+ }
}
-
- // FIXME: Extract this erros logic to a function
- parser_error_t error;
- error.token = token;
- sprintf(error.message, "unexpected '%s (" SVFMT ")' token", token_kind_to_str(token.kind), SVARG(&token.value));
- parser->errors[parser->errors_len++] = error;
-
- return false;
}
-bool
+static bool
parser_parse_term(parser_t *parser, ast_node_t *node)
{
if (!parser_parse_factor(parser, node))
@@ -207,7 +208,7 @@ parser_parse_expression(parser_t *parser, ast_node_t *node)
return true;
}
-bool
+static bool
parser_parse_return_stmt(parser_t *parser, ast_node_t *node)
{
ast_node_t *argument_token = ast_node_new();
@@ -221,7 +222,7 @@ parser_parse_return_stmt(parser_t *parser, ast_node_t *node)
return true;
}
-bool
+static bool
parser_parse_variable_definition(parser_t *parser, string_view_t variable_name, ast_node_t *node)
{
if (!drop_expected_token(parser, TOKEN_COLON))
@@ -250,7 +251,7 @@ parser_parse_variable_definition(parser_t *parser, string_view_t variable_name,
return true;
}
-bool
+static bool
parser_parse_block_declarations(parser_t *parser, vector_t *body)
{
token_t current_token;
diff --git a/src/pipac.c b/src/pipac.c
index d5781a5..a0031a5 100644
--- a/src/pipac.c
+++ b/src/pipac.c
@@ -24,7 +24,7 @@
#include "parser.h"
#include "string_view.h"
-void
+static void
generate_gas_x86_64_linux(ast_node_t *func)
{
gas_assembly_generator_t gen;
@@ -32,27 +32,13 @@ generate_gas_x86_64_linux(ast_node_t *func)
gas_assembly_generator_compile(&gen, func);
}
-void
+static void
print_usage()
{
fputs("pipac <filename.pipa>\n", stderr);
}
-void
-print_tokens(lexer_t *lexer)
-{
- token_t token;
- for (lexer_next_token(lexer, &token); token.kind != TOKEN_EOF; lexer_next_token(lexer, &token)) {
- printf("%s:%d:%d: [kind=%d, value='" SVFMT "']\n",
- lexer->filepath,
- token.row + 1,
- token.col + 1,
- token.kind,
- SVARG(&token.value));
- }
-}
-
-void
+static void
parser_print_errors(parser_t *parser)
{
for (int i = 0; i < parser->errors_len; i++) {
diff --git a/src/vector.c b/src/vector.c
index 1d018ef..85368f6 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -44,7 +44,7 @@ vector_new()
return vector;
}
-void
+static void
vector_resize(vector_t *vector)
{
vector->capacity = vector->capacity * 2;