A reworked preprocesser with focus on stopping recursive errors

Preprocesser requires one function to use: preprocess.  Takes Tokens
and gives back Units.

A unit is a tree of tokens, where each unit is a node in that tree.  A
unit has a "root" token (value of node) and an "expansion" (children
of node) where the root is some preprocesser token (such as a
reference or USE call) and the expansion is the tokens it yields.  In
the case of a USE call this is the tokens of the file it includes, in
the case of a reference it's the tokens of the constant it refers to.
This means that the leaves of the tree of units are the completely
preprocessed/expanded form of the source code.

The function has many working components, which may need to be
extracted.  In particular, the function ensures we don't include a
source twice through a hash map and that constants are not redefined
in inner include scopes if they're already defined in outer
scopes (i.e. if compiling a.asm which defines constant N, then include
b.asm which defines constant N, then N uses the definition of a.asm
rather than b.asm).

I need to make a spec for this.
This commit is contained in:
2024-07-06 17:38:02 +01:00
parent 1145b97c4c
commit a422c7d1dc
3 changed files with 354 additions and 1 deletions

View File

@@ -15,7 +15,7 @@ TERM_RESET:=$(shell echo -e "\e[0;0m")
# Setup variables for source code, output, etc
## ASSEMBLY setup
SRC=src
CODE:=$(addprefix $(SRC)/, base.cpp lexer.cpp)
CODE:=$(addprefix $(SRC)/, base.cpp lexer.cpp preprocesser.cpp)
OBJECTS:=$(CODE:$(SRC)/%.cpp=$(DIST)/%.o)
OUT=$(DIST)/asm.out