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.
This commit is contained in:
2024-04-14 17:22:34 +06:30
parent 86e9d51ab0
commit 72ef40e671
3 changed files with 53 additions and 1 deletions

View File

@@ -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)

13
asm/preprocesser.cpp Normal file
View File

@@ -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"

39
asm/preprocesser.hpp Normal file
View File

@@ -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 <tuple>
#include "./lexer.hpp"
enum pp_err_t
{
OK = 0,
EXPECTED_NAME,
EXPECTED_STRING,
EXPECTED_END,
FILE_NONEXISTENT,
FILE_PARSE_ERROR,
UNKNOWN_NAME,
};
std::pair<std::vector<token_t>, pp_err_t>
preprocesser(const std::vector<token_t> &);
std::pair<std::vector<token_t>, pp_err_t>
preprocess_macro_blocks(const std::vector<token_t> &);
std::pair<std::vector<token_t>, pp_err_t>
preprocess_use_blocks(const std::vector<token_t> &);
#endif