|
This post was updated on .
I have finished the assembler in Python in 170 codelines using only the basic stringprocessing methods of Python.
I conformed strictly to the three module API's and i have made a nice main function definition to drive the 2 passes.
I would like to share some experiences on my endavour.
1. At start i thought it was a waste of time to conform to the API's and i made a quick prototype that passed the Maxl.asm test the first time.
But then i realized that when i would work in a team it is more natural that there are agreements between the team members in some form. And the API's look like agreements to me. So i gave it a try. One result was that i got more "overview" over the entire problem. The second was that, when i finished a certain module and checked it, i did not have to think about it anymore and could think "bigger".
2. In Python you can nearly literally copy , ad verbatim, the text of the algorithm explaining the 2 passes of the Tecs book.
3. I first thought i could define a grammar for the asm language. but after quite some time i realized that that was not practically possible. For instance "D" is a symbol for a destination but also for a command , so it is not straight forward to define the grammar rules for this situation.
So i decided to work with the basic Python string processing methods. All the right marker symbols, like ';' and '=' , are there in the Tecs asm language definition and make it very easy to use the Python string partitioning ,splitting and concatenation operations. When writing this code you can already feel the limitations of such a language definition approach which relies exclusively on the use of markers.
I enjoy working on the projects very much and i am curious about the grammar defining the Jack language.
|