PPL Assignment 1
PPL Assignment 1
JIWAJI UNIVERSITY
PRINCIPLES OF
PROGRAMMING
LANGUAGE
CS-602 ASSIGNMENT 1
Priyanka Pawar
3RD Year (CSE)
171489954
Ques1: Explain language evaluation criteria?
Answer:
1. Readability:
• Overall simplicity
• Orthogonality
Example: a language has 4 primitive data types, and 2 operators (array and
pointer), a large number of data structures can be defined.
• Data types
• Syntax considerations
• Expressivity
3. Reliability:
• Type checking
• Exception handling
• Aliasing
– Having two or more distinct names that can be used to access the
same memory cell.
4. Cost:
• Compiling programs
• Executing programs
• Maintaining program.
Others:
• Portability:
• Generality:
• Well-defined ness:
Answer:
Simplicity: A good programming language must be simple and easy to learn and
use. It should provide a programmer with a clear, simple and unified set of
concepts, which can be easily grasped. The overall simplicity of a programming
language strongly affects the readability of the programs written in that language,
and programs, which are easier to read and understand, are also easier to
maintain. It is also easy to develop and implement a compiler or an interpreter for
a programming language, which is simple. However, the power needed for the
language should not be sacrificed for simplicity.
Naturalness: A good language should be natural for the application area, for
which it has been designed. That is, it should provide appropriate operators, data
structures, control structures, and a natural syntax to facilitate the users to code
their problem easily and efficiently.
Abstraction: Abstraction means the ability to define and then use complicated
structures or operations in ways that allow many of the details to be ignored. The
degree of abstraction allowed by a programming language directly effects its writ
ability. Object oriented language support high degree of abstraction. Hence,
writing programs in object oriented language is much easier. Object oriented
language also support re usability of program segments due to this features.
Efficiency: Programs written in a good programming language are efficiently
translated into machine code, are efficiently executed, and acquire as little space
in the memory as possible. That is a good programming language is supported
with a good language translator which gives due consideration to space and time
efficiency.
Structured: Structured means that the language should have necessary features
to allow its users to write their programs based on the concepts of structured
programming. This property of a moreover, it forces a programmer to look at a
problem in a logical way, so that fewer errors are created while writing a program
for the problem.
Compactness: In a good programming language, programmers should be able
to express intended operations concisely. A verbose language is generally not
liked by programmers, because they need to write too much.
Locality: A good programming language should be such that while writing a
programmer concentrate almost solely on the part of the program around the
statement currently being worked with.
Ques3: What are the different programming language categories?
Answer:
Scripting:
The most basic need of for scripting languages is one which is simple to use because it
will be used by those with a minimum of programming knowledge or in situations where
cranking out code which does the job is all the matters. An example of where this
language might be used by people with more of a programming background is in web
scripting. Examples of languages that might fall into this category are PHP, JavaScript,
Perl, and Python. VB could also be considered in this family but it is too frequently used
for application development today.
There is currently no outstanding candidate language for this category. When one
is chosen I believe it should bare resemblance to the Application development language
but with more bells and whistles to let one crank things out and make it easier.
Programmer's scripting:
Real programmers also often have a need for scripting capabilities. However, they need
a language which is simple and complete. It must never stand in there way as is all to
often the case with standard scripting languages. It must be able to easily integrate into
other languages.
Application Development:
To develop applications a language is needed which is complete and powerful but very
safe. The complexity of large application mandates a compile time safe language. It
should also be fairly high level and object oriented. The only languages which I believe
comes close to this today are Eiffel and Java.
Low-level:
For the purpose of operating systems and other low level code we need a language
that operates fast and just above the machine level. Of course there will always be
occasion to slip into assembly but that is by its nature machine specific and so not
considered here.
Both C and C++ can be used for this. They provide the low level power needed
while giving a reasonable level of safety and abstraction.
Pure Functional:
Certain tasks can best be done working in a purely function environment. And
these languages while not as widely used today are in many ways so distinct from
others that it is important to keep there legacy alive in the hopes that they may positively
influence more common languages. The only real example of this today is Haskell since
languages like ML are not purely functional..
Complete Core:
This language may never be used for real programming but I still think it would be
important to have in mind. It would be a core language which the application, scripting
and pure functional languages could build on and modify. It would have everything truly
necessary and little more. One might think that the lambda calculus would be a minimal
example of this. However, it makes no provision for mutability which is clearly a key
concept to many languages. In addition the lambda calculus has no concept of types,
another important feature of modern languages. The are no examples of a complete
core language today.
Answer:
Structure of Compiler:
Phases of Compilation:
1. First Phase: lexical analyzer or scanner separate character of source language into a
group of logically belongs to each other. This group is called as tokens. The usual tokens
are keywords such as do or if, identifiers such as a or b, operator symbol as = + < > and
punctuation symbol as () and comma. The output is a stream of tokens pass to the rest
of phases.
2. Second Phase: the syntax analyzer or parser group tokens together into syntactic
structure for example 3 tokens as A+B group together into syntactic structure as
expression. Expression might further be combined into statement. We form a tree who's
leaf are tokens, an interior node represent string of token that logically belong together.
for example : the statement - if(5 equ max) goto 100 has 8 tokens.
3.Third Phase: intermediate code generator use the structure produced by syntax
analyzer to create a stream of simple instructions. Different style we are using like
MACROS.
5. Fifth Phase: the final phase at code generation produce the object code by deciding
on memory location for data, selecting code and selecting register in which each
computation done.
The table management or book keeping keeps track of the name and record and all the
essential information about each of the data type. The data structure which is used to
record the information called the symbol table.