Tuesday, August 23, 2011

Brief History of Compilers

A compiler is a computer program that transforms source code written in one programming language (the source language), into another programming language (the target language, often having a binary form known as object code).

The first compiler was written by Grace Hopper, in 1952, for the A-0 System language. The A-0 System was a set of instructions that could translate symbolic mathematical code into machine language. The term compiler was coined by Hopper.

In 1960, the COBOL compiler for the UNIVAC II was the first to be written in a high level language, namely FLOW-MATIC. This again came from a team led by Grace Hopper.

Assembly instructions are a direct mapping to opcodes, which are byte values of machine code that can be directly interpreted by the processor. A very primitive program can be written in opcodes directly by looking them up from a table(which are different for different microprocessors) that lists them with the matching assembly instructions, and hand-determining memory addresses/offsets for things like jumps.

The first assemblers were written in this fashion - hand-written opcodes. Now these assemblers automated opcode lookups, as well as computing addresses/offsets for named jump labels.

These primitive assemblers could then be used to assemble more sophisticated assemblers which in turn could be used to assemble complex compilers written for higher-level languages(that would contain all the complex logic for lexical analysis, parsing, optimization basically written in assembly-language to be directly interpreted).

This process of iteratively writing the tools to simplify the creation of the next set of tools is called bootstrapping. And this bootstrapping process of writing a compiler (or assembler) in the programming language which it is intended to compile, creates a self-hosting compiler. Most of the modern-day programming languages have self-hosting compilers.

Monday, August 1, 2011

Explaining Systems Architecture


I was having a nap, squeezing some time out of our busy schedule when the phone rang! It was my cousin-sis in Kolkata. She had been given some assignment from her college on Systems architecture concepts and she was not having a clue to it because she had bunked her class the day those ideas were taught in class. I had to be her saviour once more!


"Just explain to me the basic idea right from the beginning, assume that I dont know anything!" she seemed nervous.

"Ok, you know what data is and you might also know that an application is one or more modules of business logic packed into a bundle that does some processing on these data to achieve some objective.
Now there can be different forms of architecture designed, depending on situations:
1) Single-tier
2) Two-tier
3) Three-tier
4) Multi-tier"

"And what are these?"

"The one-tier, or single-tier, architecture is a system in which the database, application, and presentation services (the graphical user interface) all reside on one system. This type of system does no processing external to the platform on which it is running."

"Can you give an example?"

"Yes, a Microsoft Access database with local presentation services is a common example. You can also think of a simple C Program which does some basic work without calling any other network interface as another example.
"2-tier architecture is also called client-server architecture. Here data is kept in a remote server and there are individual machines that connect to this data server to access data. These individual machines have business logic within them alongwith GUI and are the clients. The client connects to the server via the network and requests for resources which the server provides. This logical separation between application code and data eases maintainability"

"Ok, this much is clear, then?"

"Then there is the three-tier architecture. Its difference with 2-tier is that here the business logic is separated from the GUI or view aspect. Data as well as business logic resides in the remote server while the client only has the GUI-related code. Thus less data need to be transmitted through the network. Also any change in the core business logic will necessitate changes in only 1 place rather than individual client machines. SAP or any other commonly used ERP makes use of this architecture."

"Cool! And what is multi-tier?"

"It is only a logical extension of 3-tier. As you find, the tendency has always been to shift the bulk of data or code to the remote server from client machine. Here even the application-GUI is moved to the server. This is called a web-server. This server can only understand static contents as required for GUI. For dynamic content as in application logic, it requests the Application Server which in turn interacts with the Database . Requested information is then passed all the way back to the web-browser or client-browser which had initiated the request from the client machine. When we deploy a web application and then use a client browser to access the application, we are using multi-tier architecture!"

"Great!", she now seemed much relieved, "I have now more or less got the basics. I guess I shall understand more once I actually start working on these things!"