user2507974
user2507974

Reputation: 140

Is compiler common to all programming languages

For different programming languages, is there different compiler or the compiler will be common to all the programming languages? In which language compiler will be written.

Upvotes: 0

Views: 4303

Answers (5)

mig001
mig001

Reputation: 356

Compilation is a multistep process which usually includes the following steps;

  1. Lexical analysis
  2. Parsing
  3. Code generation
  4. Optimisation

Lexical analyzer converts the high level input program into a sequence of tokens. Parser will generate a parse tree. In code generation, the target code (machine code) will be generated. Optimisation is intended to improve the performance and can happen at any level.

Stages upto code generation can be referred to as compiler front-end. Remaining stages comprise compiler backend. Multiple languages can have different front ends to generate the parse tree after which they can use the same compiler backend to generate machine code.

GCC adopts this model. For more information you may refer gcc.gnu.org

Upvotes: 0

Ashesh
Ashesh

Reputation: 3589

Here's the thing:

  • Machines are dumb, they understand the language of binary digits ie. 1's and 0's

  • earlier there existed no translators so programmers were forced to give instructions in the language of the machine, which was difficult as it involved rewiring switches.

  • Then, in 1951, Grace Hopper developed the first compiler, which allowed the computer to be programmed using words and symbols rather than binary ones and zeroes. by "programming" we mean giving instructions. This made writing programs easier and the written instruction were refereed to as "Source Codes"

  • the primary job of any compiler is to perform the act of "compilation" ie. take this source code from the user (once written completely) and turn it into the "machine language" according to certain rules. Thus acting as translators.

  • now since different programming languages have different set of rules there exists different compilers specific to each such programming language These "rules" are basically syntactical and lexical rules, ie. what words and symbols can be used and how they can be combined to make some piece of code.

  • A compiler is heavily dependent on Automata theory to perform it's job of compilation.


  • As the techniques of programming developed other ways of converting source code to machine language came into existence, this gave rise to interpreted languages which involves compillation of each sentence or subroutein directly into machine language instructions. such compilation is performed by an interpreter.example: JavaScript

  • Today compilers and interpreters are used together to get best performance and increase usability on machines. example: Java which is a compiled as well as interpreted language.

**I believe the term "Compiler" is very generic.

Upvotes: 3

user2772849
user2772849

Reputation:

You may be confusing a compiler (e.g. GCC) with an IDE (e.g. Microsoft Visual Studio.) The compiler is language-specific; the IDE can support multiple languages, each of which has a specific compiler.

Upvotes: 2

Nishant Lakhara
Nishant Lakhara

Reputation: 2445

A compiler is a special program that processes statements written in a particular programming language and turns them into machine language or "code" that a computer's processor uses. Typically, a programmer writes language statements in a language such as Pascal or C one line at a time using an editor . The file that is created contains what are called the source statements . The programmer then runs the appropriate language compiler, specifying the name of the file that contains the source statements.

So clearly, every language has its own specific language supported compiler to convert source code into machine code.

refer to this link for more information related to language in which compiler is written : How was the first compiler written?

I agree with above answer that java or other high level programming language's compiler must be written in C etc because it is a language closely related to machine.

Upvotes: 1

drj
drj

Reputation: 27

Different languages have different compilers.Compiler is written in some other language not every time, for java the compiler is written in C.

Upvotes: 0

Related Questions