Craft Devleopment Diary
Craft Devleopment Diary
Craft Devleopment Diary
Daniel McCarthy
Introduction
This is a development diary of the Craft compiler also known previously by the
name Goblin.
The Craft compiler is designed to compile Craft code a language which I have
designed.
Unfortunately, I have only documented the project since 25th July 2016 so there is
months of work undocumented. Anyhow it is titled day 1 and onwards even though
it was not day 1 of the project it was day 1 of the diary.
Throughout this document you will see all the struggles and design choices I have
made to get the Craft compiler completed.
Information
Before continuing it is important that you understand the names used in this
diary, I will help explain the ones an experienced reader may have trouble with.
For anything else such as trouble understanding what a Lexer, Parser, virtual
method, or virtual pure method is. Please research on them to understand this
dairy.
Code generator
The code generator is the base class for all code generators, it parses the abstract
syntax tree from the root and invokes methods in its inheritor/child depending on
the branch it finds in the tree. For example, if it should find an assignment such as
x = 50 then it would invoke a method on its inheritor for handling assignments.
Fig 1.
My system does things a little differently and I need to consider whether or not the
above image would be the best way to go about things. My tree is workable but I do
believe the above image represents a better structure, the parser rules will need to
be thought through carefully and not just the ones for expressions. I partially think
that because I am not doing a similar structure as shown in Fig 1. May be partly
the reason certain expressions cause parsing errors but I cannot be sure as of yet I
am still in a bit of a grey area with this situation.
Another bug was discovered in function calls, a function call cannot have
arguments that are also function calls, this is a parsing error.
In other news I attempted to update the parser to do a look ahead first before
choosing a rule as the fact it does not do a look ahead has already caused me
countless problems and requires rules to be placed in a pacific position to work
correctly. Although today I have failed to implement the look ahead feature as the
previous parser design would loop through all the rules and then apply it to every
branch in the root, so in the first phase for example 3 + 3 + a would become E +
E + E and then as it goes to other rules would be broken down further. A look
5
ahead would not be possible with this design. I changed the design to apply the
rules on a left to right basis without applying it to every branch at once, for
example 3 + 3 + a would become E + 3 + a now because there is no rule for E +
3 only E + E the parser will now fail to generate an abstract syntax tree, more
thinking will need to be done but I plan to make the parser better before continuing
the project as if I do not it may cause me even worse problems later on.
One possible solution that I would rather avoid because it might come across as a
bad design perhaps, is the ability to state that a particular rule can be any of the
following branches. E.g the E branch can be the identifier token or the
number token.