Implement decimal integer reading

This commit is contained in:
2024-10-24 13:36:08 +01:00
parent 077245b3c7
commit f251fd04cc
4 changed files with 63 additions and 0 deletions

9
lib/include/reader.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef READER_H
#define READER_H
#include "memory_pool.h"
const expression_t *
read_expression(memory_pool_t *pool, const char *input, int len);
#endif

21
lib/reader.c Normal file
View File

@@ -0,0 +1,21 @@
#include "reader.h"
#include <ctype.h>
#include <stddef.h>
const expression_t *
read_expression(memory_pool_t *pool, const char *input, int len)
{
expression_t *result = allocate_expression(pool);
if (NULL == result)
return NULL;
result->is_number = true;
result->number = 0;
while (isdigit(*input)) {
result->number *= 10;
result->number += *input - '0';
++input;
++len;
}
return result;
}