04a readme and corrections
This commit is contained in:
parent
3922fc11cd
commit
17cf6b6fa0
6 changed files with 44 additions and 13 deletions
|
@ -165,4 +165,4 @@ you need to make sure you store away any information you'll need after the funct
|
|||
And the language definitely won't be as nice to use as something with real variables. But overall,
|
||||
I'm very happy with this compiler, especially considering it's written in a language with 2-letter label
|
||||
names.
|
||||
|
||||
With that, let's move on to the [next stage](../04a/README.md).
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
all: out03
|
||||
all: out03 out04a README.html
|
||||
out03: in03 ../03/out02
|
||||
../03/out02
|
||||
out04a: out03 in04a
|
||||
./out03 in04a out04a
|
||||
%.html: %.md ../markdown
|
||||
../markdown $<
|
||||
clean:
|
||||
|
|
23
04a/README.md
Normal file
23
04a/README.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
# stage 04a
|
||||
|
||||
Rather than a compiler, this stage only consists of a simple [preprocessor](https://en.wikipedia.org/wiki/Preprocessor).
|
||||
In the future, we'll run our code through this program, then run its output
|
||||
through a compiler.
|
||||
|
||||
It take lines like:
|
||||
```
|
||||
#define THREE d3
|
||||
```
|
||||
and then replaces `THREE` anywhere in the rest of the code with `d3`.
|
||||
I've provided `in04a` as a little example.
|
||||
Unlike previous programs, you can control the input and output file names
|
||||
without recompiling it. So to compile the example program:
|
||||
```
|
||||
make out03
|
||||
./out03 in04a out04a
|
||||
```
|
||||
|
||||
Although it seems simple, this program will be very useful:
|
||||
it'll let us define constants and it'll work in any language.
|
||||
There really isn't much else to say about this program. With that,
|
||||
we can move on to [the next stage](../04b/README.md) which should be more exciting.
|
2
04a/in03
2
04a/in03
|
@ -68,7 +68,7 @@ R=:line
|
|||
; check if we reached the end of the line
|
||||
C=1R
|
||||
D=xa
|
||||
?C=A:read_line
|
||||
?C=D:read_line
|
||||
; increment R, keep looping
|
||||
R+=d1
|
||||
!:process_line_loop
|
||||
|
|
10
04a/in04a
10
04a/in04a
|
@ -1,7 +1,3 @@
|
|||
A+B=hello A adfhsakjfhjksah+B
|
||||
#define COLON d1
|
||||
#define SEMICOLON d2
|
||||
#define COMMA d3
|
||||
|
||||
A=COLON
|
||||
1B=A
|
||||
#define H Hello,
|
||||
#define W world
|
||||
H W!
|
||||
|
|
16
bootstrap.sh
16
bootstrap.sh
|
@ -39,7 +39,7 @@ cd ..
|
|||
|
||||
echo 'Processing stage 01...'
|
||||
cd 01
|
||||
rm -f out0[01]
|
||||
rm -f out*
|
||||
make -s out01
|
||||
if [ "$(./out01)" != 'Hello, world!' ]; then
|
||||
echo_red 'Stage 01 failed.'
|
||||
|
@ -50,7 +50,7 @@ cd ..
|
|||
|
||||
echo 'Processing stage 02...'
|
||||
cd 02
|
||||
rm -rf out0[12]
|
||||
rm -f out*
|
||||
make -s out02
|
||||
if [ "$(./out02)" != 'Hello, world!' ]; then
|
||||
echo_red 'Stage 02 failed.'
|
||||
|
@ -60,7 +60,7 @@ cd ..
|
|||
|
||||
echo 'Processing stage 03...'
|
||||
cd 03
|
||||
rm -rf out0[23]
|
||||
rm -f out*
|
||||
make -s out03
|
||||
if [ "$(./out03)" != 'Hello, world!' ]; then
|
||||
echo_red 'Stage 03 failed.'
|
||||
|
@ -68,5 +68,15 @@ if [ "$(./out03)" != 'Hello, world!' ]; then
|
|||
fi
|
||||
cd ..
|
||||
|
||||
echo 'Processing stage 04a...'
|
||||
cd 04a
|
||||
rm -f out*
|
||||
make -s out04a
|
||||
if [ "$(cat out04a)" != "$(printf '\n\nHello, world!')" ]; then
|
||||
echo_red 'Stage 04a failed.'
|
||||
exit 1
|
||||
fi
|
||||
cd ..
|
||||
|
||||
|
||||
echo_green 'all stages completed successfully!'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue