Implement decimal integer reading
This commit is contained in:
21
lib/reader.c
Normal file
21
lib/reader.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user