So we are approaching the end of this module and I think that you would agree with me that this module has been both long, and challenging. And for me personally, it was also challenging from a physical standpoint. Because you see, I taped something like eight such units in a stretch. So, I end up standing on my feet for several hours in front of the camera. And normally, I'm okay doing it, because I feel more energized when I speak standing rather than sitting. But about two weeks ago, I broke my leg in a biking accident and now I wear this brace and it's kind of aching to stand too many hours. So, I will sit for a while and will do this unit sitting, and then I guess I'll return to standing. So in this unit, we are going to propose an implementation for your VM translator and to remind you the VM translator is a program that starts with some VM code and simply translates it into assembly code. And so, it goes through the first command. Let's say, push constant 17 and it generates code that affects the same semantics in assembly. And then it finds the command goto LOOP and it generates code that implements this goto command does the same with call. Moving along it generates call that implements the function command, then the push, then the return and so on until it hits the end of the input source file. So, that's the nature of the VM translator. You shouldn't be surprised, because you've already written a basic VM translator and this basic translator is going to be extended in this project into what we call the final VM translator. So basically, we are going to take the program that you wrote in the previous project and add more functionality to it. Now to remind you, the source that we are translating is the VM language, obviously and the target that the code that we are generating is written in the Hecht Assembly code. And in doing all this, we have to comply to using the special symbols that I described in the previous unit. And with that, we are ready to describe our proposed implementation. So, here again is a diagram that describes the VM translator in action. And we see that in the previous project if you recall, you were asked to write a VM translator that translates a single given VM file. Well, in this project, one of the things that we want to extend is the ability to handle more than one VM file. So the VM translator that you write should be able to also handle a directory that contains one or more VM files, as we see in this diagram here. And in any event, it always will generate a single assembly file that contains the sort of sequence of all the functions that we are translating. So, the proposed implementation that I outline here is exactly the same as or contains exactly the same modules that we had in the previous project. Parser, code writer and main and let us describe everyone of these modules in turn. The main module receives as input some string that stands either for a single file or for the name of a directory or folder, if you will that contains presumably one or more VM files. So, it's one of the two. And if you use a language like Java or Python, there are capabilities in these languages to decide if a certain string stands for a single file or a directory. The output of the program should be fileName.asn file that contains. The assembly code that we are going to generate. The process that the main program is going to carry out is the following. First of all, it will construct a CodeWriter in order to handle the output file which is still empty at this stage and then it is going to ask itself if the input is a file or a directory. If the input represents a single file, then it will construct a parser to handle this input file and then it will go into a loop that marches through every command in the input file. Process it and hands over the lexical elements to the code writer in order to generate the assembly code. If the input is a directory, it will do what we just described for every VM file in that directory and that's the end of the story. That's what the main module should do. And as you can see, it is not a very complex extension of what we did in the previous project. Moving along the parser as usual handles the processing or the passing of a single VM file. It reads a VM command. Breaks it into its lexical elements and removes all the white space, and comments in the process. This parser is exactly the same as the one that we developed in the previous project. We don't have to touch it. However, we just want to make sure that the parser also handles the commands that we introduced in this module which are the branching and function commands. Now if you followed the requirement that we set in the previous project, your parser should handle these commands as well. But if for some reason you didn't do it, this is the time to include them. So, the parser is done. And finally, we have to extend the CodeWriter. So, the API of the basic CodeWriter that we developed in the previous project is shown here on the screen. To this API, we have to add some additional functionality. First of all, we'll have a method called setFileName which we will use to inform the CodeWriter that the processing of a new VM file has just started and we're going to pass the name of this file as an argument. Then we're going to have another method whose job is to write the booting code that will enable the VM to start working as specified in the standard mapping of the VM on the Hecht platform. So write in it is responsible for writing this code and then there will be three methods called writeLabel, writeGoto and writeIf which produce the assembly code which takes care of the commands label go to an if. And finally, three methods called writeFunction, writeCall and writeReturn which produce the assembly code that knows how to take care of the respective VM commands and that's it. Once you do that, you will have a fully functioning VM translator and you have implemented a virtual machine. Now, the most challenging part in writing this VM translator is writing these six methods. WriteLabel, writeGoto, writeIf. These three methods are relatively simple, because generating assembly called that implements if and go to is not a big deal, but then we have to generate the assembly called for function column return. And in doing this, you have to follow all the logic that we explained. In the previous units in order to build this incredible cathedral, this stack that moves up and down in order to implement the function call and return protocol. So, this has been the end of this module. And in the next one, we will discuss the project materials and some recommendations on how to actually build this VM translator.