What is the difference between Imperative languages and Functional languages in compiler design?

Compiler DesignProgramming LanguagesComputer Programming

Imperative Languages

Imperative languages are those which facilitate the computation by mean of state changes. By a state, it means the condition of a computer’s random access memory (RAM) or storage. It is helpful to think of computer memory as a sequence of snapshots, each one capturing the values in all memory cells at a particular time. Each snapshot records a state.

When a program is entered, associated data exists in a certain condition, say an unsorted list off-line. It is the programmer’s job to specify a sequence of changes to the store that will produce the desired final state, perhaps a sorted list. The store involves much more than data and a stored program. It includes a symbol table, run-time stack (S), an operating system, and its CPU itself can be viewed as part of the initial state.

Functional Languages

A functional language is a programming language built over and around logical functions or procedures within its programming structure. It is dependent on and is equivalent to mathematical functions in its program flow.

Functional languages change their basic structure from the numerical structure of Lambda calculus and combinatory logic. Erlang, LISP, Haskell, and Scala are the most famous functional languages.

Imperative LanguagesFunctional Languages
Imperative languages are based on Von-Neumann Architecture.
The functional languages are not based on Von-Neumann Architecture.
The programmer is concerned with the management of variables and the assignment of values to them.
The programmer requires not to be concerned with variables because memory cells need not be abstracted into the language.
The imperative languages facilitate the computation using the state changes.
The functional languages facilitate the functions that the program represents, instead of only stating changes as the program executes, statement by statement.
It can increase the efficiency of execution.
It can decrease the efficiency of execution.
It is used for the laborious construction of programs.
Less labor required than programming in an imperative language.
It is a very clean syntactic framework.
It is a much more complex syntactic structure than imperative language.
Concurrent execution is difficult to design and use.
Concurrent execution is easy to design and use.
The semantics are difficult to understand.
The semantics are simple as compared with imperative languages.
The programmer should create a static division of the program into its concurrent elements, which are then written as functions. This can be a complex process.
Programs in functional languages can be broken into concurrent elements dynamically by the execution system, creating the process highly flexible to the hardware on which it is running.
An example of imperative languages includes C, C++, ADA, Pascal, etc.
An example of functional languages includes LISP, ML, scheme, etc.
raja
Published on 23-Oct-2021 11:28:36

Advertisements