From 5bcc016246c6706f2a5f1cd06ac8c1e5408a1713 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Fri, 23 Feb 2018 09:07:12 -0800 Subject: [PATCH] misc/kforth: Starting work on the parser. --- Makefile | 1 + kforth.cc | 1 + linux/defs.h | 2 +- parser.cc | 17 +++++++++++++++++ parser.h | 14 ++++++++++++++ 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 parser.cc create mode 100644 parser.h diff --git a/Makefile b/Makefile index 9eb07c9..6c72769 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ CXXSTD := c++11 CXXFLAGS := -std=$(CXXSTD) -Wall -Werror -g -O0 OBJS := linux/io.o \ + parser.o \ kforth.o TARGET := kforth diff --git a/kforth.cc b/kforth.cc index 218b599..0c0eab2 100644 --- a/kforth.cc +++ b/kforth.cc @@ -1,4 +1,5 @@ #include "io.h" +#include "parser.h" #ifdef __linux__ #include "linux.h" diff --git a/linux/defs.h b/linux/defs.h index 78228d9..57cdaeb 100644 --- a/linux/defs.h +++ b/linux/defs.h @@ -2,6 +2,6 @@ #define __KF_LINUX_DEFS_H__ #include - +#include #endif \ No newline at end of file diff --git a/parser.cc b/parser.cc new file mode 100644 index 0000000..08ee351 --- /dev/null +++ b/parser.cc @@ -0,0 +1,17 @@ +#include "defs.h" +#include "parser.h" + +int +parse_next(const char *buf, const size_t length, size_t *offset, + struct Token *token) +{ + size_t start = *offset; + bool ok = false; + + // TODO(skip past whitespace) + // TODO(find next EOC) + if (!ok) { + *offset = start; + } + return -1; +} \ No newline at end of file diff --git a/parser.h b/parser.h new file mode 100644 index 0000000..dfb7e21 --- /dev/null +++ b/parser.h @@ -0,0 +1,14 @@ +#ifndef __KF_PARSER_H__ +#define __KF_PARSER_H__ + +#include "defs.h" + +struct Token { + char *token; + uint8_t length; +}; + +int parse_next(const char *, const size_t, size_t *, struct Token *); + + +#endif // __KF_PARSER_H__