Author: paulmoore100
-
Working Through WACC – Chapter 10
WACC is this book and I am blogging my way through it. This is the last chapter in part 1. A quick skim shows its not too hard. Adding extern and static keywords non stack data The last point means I need to identify the syntax for this in NASM, the book uses gas syntax,…
-
Working through ‘WACC’ – Chapter 9 – Functions
WACC means this book And this is my journey through it. Parsing This is a complicated chapter, and I haven’t even got to the code generation part yet Significant rewrite of the declaration and definition parsing. Added a new symbol table, I thought this would replace the variable renaming tables but it is an adjunct…
-
Working through WACC – Chapter 8, Loops
All part of the series about this book: Time to add while, do {} while, for, break and continue. And just because all text is boring here’s a picture: This is where I started to doubt my single phase parse direct to TACKY. Particularly in the extra credit. For Loops A for loop like this:…
-
Working Through WACC – Chapter 7, Compound statements
Because we haven’t had it for a while here’s the front cover. If you are not sure what this post is about check out episode 1 https://jollygoodsw.wordpress.com/2025/03/13/working-through-writing-a-c-compiler/ This is a short chapter, the only real change is that the variable name / scope resolution gets fancier. This is beacuse we can now have Ie we…
-
Working through WACC – chapter 6, if and ternary
Just because all text is boring 🙂 The only really tricky thing in this chapter is dealing with the ternary , conditional expression ‘operator’. ie but the book walks through the recommended way of parsing this, and it works well. Backend Generation One really cool thing about this compiler design is how often things in…
-
Working through ‘WACC’ – chapter 5, Local Variables
This is a post in a long series about the book .Writing A C Compiler’. The first post that explains the project is here Working through ‘Writing A C Compiler’ – Jolly Interesting Stuff In this chapter we get variables. This means declarations parsing ‘=’ scopes name resolution Guilty Admission You will see why I…
-
Working through ‘WACC’ – chapter 4 Logical and relational operators
Because I like the cover here it is again The big step here is that we add jumps, conditional and unconditional, because && and || can cause us to skip executing some code . Ignoring Nora is a bad idea This is where we start generating labels for jumps. The book says generate meaningful label…
-
Working through WACC – chapter 3 , binary operators
Now we get down to some serious parsing. We have to care about operator associativity (left or right) and operator precedence. Again I wont go into details here because the book does an excellent job. There are choices presented however and I will say what I did. Page 51 talks about ‘The adequate solution’. This…
-
Working through ‘WACC’ – Chapter 2, Unary operators
There is a big change in this chapter. A new intermediate form called tacky is introduced Structure of the compiler The compiler now looks like this. One very important point here is that there are now two distinct phases Generate Tacky. Tacky is Nora’s target platform neutral representation of the c code. This phase doesnt…
-
Working through ‘WACC’ – Chapter 1, A minimal compiler
Ok, some real meat now. The compiler we are building (I will call it ‘mycc’ from now on) works like this The flow is: launch (and wait for completion of) the installed c preprocessor, writing to a temporary file mycc then reads that temporay file and compiles it to assembly code and writes that to…