From 72ef40e6718cbe309a8fe6f32ac31adb1a40dda2 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sun, 14 Apr 2024 17:22:34 +0630 Subject: parser -> preprocesser + parser I've decided to split the module parsing into two modules, one for the preprocessing stage which only deals with tokens and the parsing stage which generates bytecode. --- Makefile | 2 +- asm/preprocesser.cpp | 13 +++++++++++++ asm/preprocesser.hpp | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 asm/preprocesser.cpp create mode 100644 asm/preprocesser.hpp diff --git a/Makefile b/Makefile index e0c076b..609fc40 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ VM_OUT=$(DIST)/ovm.out ## ASSEMBLY setup ASM_DIST=$(DIST)/asm ASM_SRC=asm -ASM_CODE:=$(addprefix $(ASM_SRC)/, lexer.cpp) +ASM_CODE:=$(addprefix $(ASM_SRC)/, lexer.cpp, preprocesser.cpp) ASM_OBJECTS:=$(ASM_CODE:$(ASM_SRC)/%.cpp=$(ASM_DIST)/%.o) ASM_DEPS:=$(ASM_OBJECTS:%.o=%.d) $(ASM_DIST)/main.d ASM_CFLAGS=$(CPPFLAGS) diff --git a/asm/preprocesser.cpp b/asm/preprocesser.cpp new file mode 100644 index 0000000..615cf93 --- /dev/null +++ b/asm/preprocesser.cpp @@ -0,0 +1,13 @@ +/* Copyright (C) 2024 Aryadev Chavali + + * You may distribute and modify this code under the terms of the + * GPLv2 license. You should have received a copy of the GPLv2 + * license with this file. If not, please write to: + * aryadev@aryadevchavali.com. + + * Created: 2024-04-14 + * Author: Aryadev Chavali + * Description: Preprocessor which occurs after lexing before parsing. + */ + +#include "./preprocesser.hpp" diff --git a/asm/preprocesser.hpp b/asm/preprocesser.hpp new file mode 100644 index 0000000..9d733dd --- /dev/null +++ b/asm/preprocesser.hpp @@ -0,0 +1,39 @@ +/* Copyright (C) 2024 Aryadev Chavali + + * You may distribute and modify this code under the terms of the GPLv2 + * license. You should have received a copy of the GPLv2 license with + * this file. If not, please write to: aryadev@aryadevchavali.com. + + * Created: 2024-04-14 + * Author: Aryadev Chavali + * Description: Preprocessor which occurs after lexing before parsing. + */ + +#ifndef PREPROCESSER_HPP +#define PREPROCESSER_HPP + +#include + +#include "./lexer.hpp" + +enum pp_err_t +{ + OK = 0, + EXPECTED_NAME, + EXPECTED_STRING, + EXPECTED_END, + FILE_NONEXISTENT, + FILE_PARSE_ERROR, + UNKNOWN_NAME, +}; + +std::pair, pp_err_t> +preprocesser(const std::vector &); + +std::pair, pp_err_t> +preprocess_macro_blocks(const std::vector &); + +std::pair, pp_err_t> +preprocess_use_blocks(const std::vector &); + +#endif -- cgit v1.2.3-13-gbd6f