You are on page 1of 5

Imperative programming was the dominant paradigm from the dawn of computing until about 1990,after which it was

overtaken by objectoriented programming. How would you explain this development? Why has functional or logic programming never become dominant?
Programming languages can be roughly classified in two categories: imperative and declarative. Imperative programming puts emphasis on how to do something while declarative programming expresses what the solution to a given problem is. Declarative Languages can be further divided into Functional and Logic languages. Functional Languages treat the computation as the evaluation of mathematical functions whereas Logic Languages treat the computation as axioms and derivation rules.

Imperative Languages
Imperative languages follow the model of computation described in the Turing Machine; hence, they maintain the fundamental notion of a state. The state of a program is given by the configuration of the memory tape, and the pointer in table of rules. In a modern computer, the state is given by the values stored in the memory and in the registers. In particular, a special register, the program counter, defines the next instruction to be executed. Instructions are a very important concept in imperative programming. An imperative program issues to the machines orders that define the next actions to be taken. These actions change the state of the machine. Instructions are combined together to make up commands. There are three main categories of commands: assignments, branches and sequences. Imperative languages are the dominant programming paradigm in the industry. Examples of imperative languages include C, Pascal, Basic, Assembler. There are other multi-paradigm languages that also support partially or even fully the imperative paradigm like C++, JavaScript but as multi-paradigm languages they are not good examples as real utilization of the languages would not fit the description.

Declarative Languages
A program in a declarative language declares one truth. In other words, such a program describes a proof that some truth holds. These programs are much more about "what" is the solution of a problem, than "how" to get that solution. These programs are made up of expressions, not commands. An expression is any valid sentence in the programming language that returns a value. These languages have very important characteristics: referential transparency. This property implies that any expression can be replaced by its value. For instance, a function call that computes the factorial of 5 can be replaced by its result, 120. Declarative languages are further divided into two very important categories: functional languages and logic languages.

There are some a language in which developing imperative programs is more natural. Similarly, there are programming languages in which developing declarative programs, be it functional or logic, is more natural.

Due to following reason the functional and logical programming never dominates. functional programming is a programming paradigm, a style of building the structure and elements of computer programs, that treats computation as the evaluation of mathematical functions and avoids state and mutable data. Functional programming emphasizes functions that produce results that depend only on their inputs and not on the program state - i.e. pure mathematical functions. It is a declarative programming paradigm, which means programming is done with expressions. In functional code, the output value of a function depends only on the arguments that are input to the function, so calling a function f twice with the same value for an argument x will produce the same result f(x) both times. Eliminating side effects, i.e. changes in state that don't depend on the function inputs, can make it much easier to understand and predict the behavior of a program, which is one of the key motivations for the development of functional programming.

Logic programming is a programming paradigm based on formal logic. Programs written in a logical programming language are sets of logical sentences, expressing facts and rules about some problem domain. Together with an inference algorithm, they form a program. Major logic programming languages include Prolog and Data log.

2. Draw a diagram showing a structure of a typical compiler. Briefly discuss each phase of a compiler.
The process of compilation is split up into six phases, each of which interacts with a symbol Table manager and an error handler. This is called the analysis/synthesis model of compilation.

Lexical Analysis: The lexical analyzer is the first phase of compiler. Its main task is to read the input
characters and produces output a sequence of tokens that the parser uses for syntax analysis. Syntax Analysis: A syntax analyzer or parser is a program that groups sequences of tokens from the lexical Semantic Analysis: A semantic analyzer takes its input from the syntax analysis phase in the form of a parse tree and a symbol table. Its purpose is to determine if the input has a well-defined meaning; in practice semantic analyzers are mainly concerned with type checking and type CORECTION based on type rules.

Intermediate Code Generation: After the analysis phases of the compiler have been completed,
a source program has been decomposed into a symbol table and a parse tree both of which may have been modified by the semantic analyzer. Analyzer phase into phrases each with an associated phrase type.

Code Optimization: An optimizer attempts to improve the time and space requirements of a
program. There are many ways in which code can be optimized, but most are expensive in terms of time and space to implement. Code Generation: The final phase of the compiler is to generate code for a specific machine. In this phase we consider: Memory management, Register assignment and Machine-specific optimization. The output from this phase is usually assembly language or relocatable machine code. 3. Construct a parse tree of the expression x = 2*(y + 5) + z * 3 using the following set of BNF grammar rules. <expression> ::= <term> | <term> "+" <expression> <term>::= <factor> | <factor> "*" <term> <factor> ::= <constant> | <variable> | "(" <expression> ")" <variable> ::= "x" | "y" | "z" <constant> ::= <digit> | <digit> <constant> <digit>::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"

<assign>

<id>

<expression>

<term>

<exp>

<term> <term> * <fact>

<fact>

(<exp>)

Fact

term

<term> <const> fact

<exp>

<var>

<fact>

term

<const>

<var>

<fact>

<const>

You might also like