Create read module

This commit is contained in:
2025-08-10 16:39:13 +01:00
parent d90f91cda0
commit e25975e29d
5 changed files with 131 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ add_library(imp
parse.c
prim.c
print.c
read.c
store.c
token.c
)

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

@@ -0,0 +1,9 @@
#ifndef READ_H
#define READ_H
#include "am.h"
#include "stream.h"
void read(am_t *am, stream_t *stream);
#endif

22
lib/read.c Normal file
View File

@@ -0,0 +1,22 @@
#include "read.h"
#include "parse.h"
#include "token.h"
#include <assert.h>
void read(am_t *am, stream_t *stream)
{
parse_ctx_t ctx;
token_t token;
parse_init(am, &ctx);
while (ctx.state != PARSE_STATE_DONE) {
const token_status_t token_status = token_read(stream, &token);
assert(token_status == TOKEN_OK);
parse_proc(&ctx, &token);
assert(ctx.state != PARSE_STATE_ERROR);
}
}