Creating a bytecode based programming language, part 3
Third and last post about creating a compiler and an interpreter.
We convert each expression identified during the token reduction to an instruction (each expression kind is mapped to an instruction class).
The set of instruction objects obtained after having converted all expressions is the bytecode.
Now, how to we use it?
An instruction class is quite simple, it defines two methods: an init and a process one.
The init method has a single parameter: a token (or a complex token as it extends the token class). This token, or it's sub-tokens, is used to initialized the attributes of the instruction object.
The process method takes two parameters, firstly an execution output and then the execution context.
The execution output is mostly a StringBuffer.
The execution context is more complex. It contains access to information like the
Creating a bytecode based programming language, part 2
This is the long, or not, awaited second post about creating a compiler.
In this post we will talk about parsing a source code.
Creating a bytecode based programming language, part 1
This is the first of a series of short posts about a subject I am currently working on as a personal side project: creating a compiler to create bytecode based programming languages.
Read more…Delegation
As I am writing from my phone, today's article will be short.
When creating your cocoa's application, you will often be asked to set a delegate object. This is not specific to objective-c development.
I will take a simple example : a table. There exists two ways two create cells in a table. The first one is active, we tell the table to add a cell, and we do so for each cell. The second one is passive. When the table want to be draw or updated, he ask our code what it should do.
How many rows should I have? What cell should I display there? What should I do when my cell is selected?
That is delegation. The answers are given by an instance of a class implementing an interface. This object is the delegate.
As a matter of fact, in iOS development, a UITableView use a double delegation. The delegate defines the behavior while the datasource defines the content.