Don't understand the use of Compilation Engine

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Don't understand the use of Compilation Engine

sarthak
In this chapter we are asked to divide compiler into four modules:
Jack Tokenizer (which I assume is also including the Jack Parser)
Symbol Table
VM Writer
Compilation Engine
If we have VM Writer to emit virtual machine code, what does compilation Engine do?
Reply | Threaded
Open this post in threaded view
|

Re: Don't understand the use of Compilation Engine

ybakos
This is a matter of design. Each "module" has a particular task:

Tokenizer: break Jack code into tokens
Symbol Table: keep track of class names, function names, variable names, etc.
Parser: transform tokens into a tree
VM Writer: transform the tree (the program) into VM instructions (push, pop, etc)

Keep in mind that you certainly can depart from the suggested design in your own implementation. (That said, this architecture, in general, is one you will see in the real world.)
Reply | Threaded
Open this post in threaded view
|

Re: Don't understand the use of Compilation Engine

sarthak
But you still did not tell me the use of Compilation Engine...
Reply | Threaded
Open this post in threaded view
|

Re: Don't understand the use of Compilation Engine

cadet1620
Administrator
CompilationEngine translates one .jack file to a .vm file. Your main (JackAnalyzer) needs to do something like:

function void Main.main()
    // parse the command line arguments
    // builds a list of .jack files that need to be compiled
    for each file in the list
        compileEngine = CompileEngine.new(file.jack, file.vm)
        compileEngine.CompileClass()
        compileEngine.destroy()

CompileClass will use the JackTokenizer to parse the .jack file. CompileClass will, for example, call CompileClassVarDec when it encounters a 'static' or 'field' token.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Don't understand the use of Compilation Engine

ybakos
In reply to this post by sarthak
My CompilationEngine class receives a list of tokens in its constructor. I then ask it to conduct the parsing of the tokens, resulting in a syntax tree for the program.
Reply | Threaded
Open this post in threaded view
|

Re: Don't understand the use of Compilation Engine

redemptionc
In reply to this post by ybakos
I'm confused,did symbol table keep track of class name or subroutine name? Or just variable info?