summaryrefslogtreecommitdiff
path: root/src/lexer.c
diff options
context:
space:
mode:
authorJohnny Richard <johnny@johnnyrichard.com>2023-04-21 15:11:17 +0200
committerCarlos Maniero <carlosmaniero@gmail.com>2023-04-21 10:29:41 -0300
commitd86d70fc7c6751713a6b9f02d9f77814e2f75718 (patch)
tree15340e4f421628fa79461374c39407997f928d93 /src/lexer.c
parent562fa8785f9bc3074e8b2acf524f4120add22752 (diff)
parser: Parse integers arithmetic expression
This patch implements the AST creation for arithmetic expressions. NOTE: The implementation works only for integer numbers. Signed-off-by: Johnny Richard <johnny@johnnyrichard.com> Reviewed-by: Carlos Maniero <carlosmaniero@gmail.com>
Diffstat (limited to 'src/lexer.c')
-rw-r--r--src/lexer.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/lexer.c b/src/lexer.c
index 2c8ffb9..b641752 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -44,6 +44,7 @@ lexer_define_literal_token_props(lexer_t *lexer, token_t *token, token_kind_t ki
token->filepath = lexer->filepath;
token->row = lexer->row;
token->col = lexer->cur - lexer->bol;
+ token->bol = lexer->bol;
}
static void
@@ -73,6 +74,7 @@ lexer_tokenize_number(lexer_t *lexer, token_t *token)
token->filepath = lexer->filepath;
token->row = lexer->row;
token->col = begin - lexer->bol;
+ token->bol = lexer->bol;
}
static void
@@ -88,6 +90,7 @@ lexer_tokenize_name(lexer_t *lexer, token_t *token)
token->filepath = lexer->filepath;
token->row = lexer->row;
token->col = begin - lexer->bol;
+ token->bol = lexer->bol;
}
void
@@ -197,6 +200,14 @@ lexer_load_file_contents(lexer_t *lexer)
}
void
+lexer_step_back_to(lexer_t *lexer, token_t *token)
+{
+ lexer->cur = token->bol + token->col;
+ lexer->row = token->row;
+ lexer->bol = token->bol;
+}
+
+void
lexer_drop_char(lexer_t *lexer)
{
lexer->cur++;