Dprince Institute: Cit332 - Survey of Programming Languages
Dprince Institute: Cit332 - Survey of Programming Languages
DPRINCE*INSTITUTE
CIT332 - SURVEY OF PROGRAMMING
LANGUAGES
LEVEL: 300, SEMESTER: 2nd SEMESTER
CLICK >> Whatsapp*Group << CLICK
QUESTION
WHAT IS COMPUTER PROGRAMMING?
SUGGESTED ANSWER
Computer programming is the process that professionals use to write code that instructs how a computer,
application or software program performs.
QUESTION
WHAT ARE THE CLASSIFICATION OF PROGRAMMING LANGUAGE GENERATION?
SUGGESTED ANSWER
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 1
01/01/2022 SUMMARY / Q&A
- Allowed mnemonic abbreviations as symbolic names and the concept of commands and operands was
introduced.
- A programmer's work became much easier, since the symbolic notation and addressing of instructions and
data was now possible.
- Compilation systems, called assemblers, were developed to translate the assembly language/symbolic
programs into machine code.
- Assembly languages still reflect the hardware structure of the target machine - not on the flip-flop level,
but on the register level, i.e. the abstraction has changed from the flip-flop to the register level.
- The instruction set of the target computer directly determines the scope of an assembly language.
- With the introduction of linking mechanisms, assembling of code separately became possible and the first
steps towards program structuring were recognizable, although the term structured programming cannot
be used for programming assembly code.
- The major disadvantage of assembly languages is that programs are still machine dependent and, in
general, only readable by the authors.
- Allow control structures which are based on logical data objects: variables of a specific type.
- They provide a level of abstraction allowing machine-independent specification of data, functions or
processes, and their control.
- A programmer can now focus on the problem to be solved without being concerned with the internal
hardware structure of the target computer.
- When considering high level programming languages, there are four groups of programming languages:
imperative, declarative, object oriented and functional languages.
- 5GL allows computers to have their own ability to think and their own inferences can be worked out by
using the programmed information in large databases.
- 5GL gave birth to the dream of robot with AI and Fuzzy Logic.
- The fifth-generation languages are also called 5GL.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 2
01/01/2022 SUMMARY / Q&A
QUESTION
ENUMERATE CHARACTERISTICS OF EACH GENERATION
SUGGESTED ANSWER
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 3
01/01/2022 SUMMARY / Q&A
On the basis of the programming language level of abstraction, there are two types of programming languages:
Low-level language and High-level language. The first two generations are called low level languages.
The next three generations are called middle level language, very high-level languages and higher level language.
Both of these are types of programming languages that provide a set of instructions to a system for performing
certain tasks. Though both of these have specific purposes, they vary in various ways.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 4
01/01/2022 SUMMARY / Q&A
The primary difference between low and high-level languages is that any programmer can understand, compile,
and interpret a high-level language feasibly as compared to the machine. The machines, on the other hand, are
capable of understanding the low-level language more feasibly compared to human beings. Below is the hierarchy
of level of programming language.
Low-Level Language
A low-level programming language provides little or no abstraction from a computer's instruction set
architecture—commands or functions in the language map that are structurally similar to processor's instructions.
Generally, this refers to either machine code or assembly language.
The starting bits are known as the operator or opcode whose role is to identify the kind of operation that are
required to be performed. The remaining bits are called operand, whose purpose is to show the location of activity.
The programs are written in various programming languages like C, C++. Java python etc. The computer is not
capable of understanding these programming languages therefore, programs are compiled through compiler that
converts into machine language. Below is sample of how machine language is executed.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 5
01/01/2022 SUMMARY / Q&A
• Fast processing: All the computer instructions are directly recognized. Hence, programs run very quickly.
• No need of Translator: The machine code is the natural language directly understood by the computer.
Therefore, translators are not required. Assembly language on the other hand requires assemblers for conversion
from mnemonics to equivalent machine code.
• Error prone: The instructions are written using 0's and 1's. This makes it a herculean task. Hence, there
are more chances of error prone codes in these languages. Errors are reduced in assembly language when
compared to machine language.
• Difficult to use: The binary digits (0 and 1) are used to represent the complete data or instructions, so it
is a tough task to memorize all the machine codes for human beings. Assembly language is easier to use when
compared to machine language.
• Difficulty in debugging: When there is a mistake within the logic of the program then it is difficult to
find out the error (bug) and debug the machine language program.
• Difficult to understand: It is very difficult to understand because it requires a substantial knowledge of
machine code for different system architectures.
• Lack of portability: They are computer dependent such that a program which is written for one computer
cannot be run on different computer because every computer has unique architecture.
• In-depth Knowledge of Computer Architecture: To program in the Assembly languages, the
programmer need to understand the computer architecture as for as the machine languages.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 6
01/01/2022 SUMMARY / Q&A
High-Level Language
The high-level language is a programming language that allows a programmer to write the programs which are
independent of a particular type of computer.
The program of high-level language must be interpreted before the execution. The high-level language deal with
the variables, arrays, objects, complex arithmetic or Boolean expression, subroutines and functions, loops,
threads, locks, etc.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 7
01/01/2022 SUMMARY / Q&A
• Third generation Language: High Level Languages are 3rd Generation Languages that are majorly
refinement to the 2nd generation languages.
• Understandability: programs written in High-level language is easily understood
• Debugging: Errors can be easily located in theses languages because of the presence of standard error
handling features.
• Portability: programs written on one computer architecture can run on another computer. This also means
that they are machine independent.
• Easy to Use: Since they are written in English like statements, they are easy to use.
• Problem-oriented Languages: High level languages are problem oriented such that they can be used for
specific problems to be solved.
• Easy Maintenance: We can easily maintain the programs written in these languages.
• Translator Required: There is always a need to translate the high-level language program to machine
language.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 8
01/01/2022 SUMMARY / Q&A
An Assembler converts program written in Low Level Language (Assembly Lang) to machine code.
High Level Language uses compiler, interpreter or both.
These languages can convert the high-level code into binary code so that the machine can understand as seen in
the diagram below.
The compiler is the translator program software. This software can translate into its equivalent machine language
program. The compiler compiles a set of machine language instructions for every program in a high-level
language. Below is the sample of compiler from high level language to machine language.
The linker is used for the large programs in which we can create some modules for the different task. When we
call the module, the whole job is to link to that module and program is processed.
The high-level language is easy to read, write, and maintain as it is written in English like words.
The languages are designed to overcome the limitation of low-level language, i.e., portability. The high-level
language is portable; i.e., these languages are machine-independent.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 9
01/01/2022 SUMMARY / Q&A
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 10
01/01/2022 SUMMARY / Q&A
LANGUAGE PARADIGM
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 11
01/01/2022 SUMMARY / Q&A
Procedural/Imperative languages
• Variables
• Commands
• Procedures
• Data abstraction.
In the main program each procedure would be invoked on the basis of user’s choice. E.g. FORTRAN Algol,
Pascal, C/C++, C#, Java, Perl, JavaScript, Visual BASIC.NET.
Object-oriented languages
The solution deals with how to store data related to the entities, how the entities behave and how they interact
with each other to give a cohesive solution. Example − If we have to develop a payroll management system, we
will have entities like employees, salary structure, leave rules, etc. around which the solution must be built. The
key concepts of OOP are:
• Objects
• Classes
• Subclasses
• Inheritance
• Inclusion polymorphism.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 12
01/01/2022 SUMMARY / Q&A
Object Oriented Programming has been widely accepted in the computing world because objects give a very
natural way to model both real-world and cyber-world entities. Object oriented programming fits well with object-
oriented analysis and design and
hence supports these development of large software systems. E.g. SIMULA 67, SMALLTALK, C++, Java,
Python, C#, Perl, Lisp or EIFFEL.
Functional/applicative languages
A payroll processing can have functional units like employee data maintenance, basic salary calculation, gross
salary calculation, leave processing, loan repayment processing, etc. The key concepts of functional programming
are:
• Expressions are key concept of functional programming because their purpose is to compute new values
from old ones. This is the very essence of functional programming.
• Functions are key concept of functional programming because functions abstract over expressions.
• Parametric polymorphism is a key concept of functional programming because it enables a function to
operate on values of a family of types. In practice, many useful functions are naturally polymorphic, and
parametric polymorphism greatly magnifies the power and expressiveness of a functional language.
• Data abstraction is a key concept in the more modern functional languages such as ML and HASKELL.
Data abstraction supports separation of important issues, which is essential for the design and implementation of
large programs.
• Lazy evaluation is based on the simple notion that an expression whose value is never used need never be
evaluated. E.g. LISP, Scala, Haskell, Python, Clojure, Erlang. It may also include OO (Object Oriented) concepts.
Facts and rules (the logic) are used to represent information (or knowledge) and a logical inference process is
used to produce results.
In contrast to this, control structures are not explicitly defined in a program, they are part of the programming
language (inference mechanism).
PROLOG, PERL, this may also include OO concepts. The key concepts of logic programming are therefore:
• Assertions
• Horn clauses
• Relations
Scripting Languages
A scripting language or script language is a programming language for a runtime system that automates the
execution of tasks that would otherwise be performed individually by a human operator.
It is highly efficient with the limited number of data structures and variables to use, it helps in adding visualization
interfaces and combinations in web pages.
There are different libraries which are part of different scripting languages. They help in creating new applications
in web browsers and are different from normal programming languages.
Key Concept of Scripting Language
High-level string processing: All scripting languages provide very high-level support for string processing.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 13
01/01/2022 SUMMARY / Q&A
Dynamic typing: Many scripting languages are dynamically typed. Scripts must be able to pass data to and from
subsystem written in different languages when used as glue. Scripts often process heterogeneous data, whether in
forms, databases, spreadsheets, or Web pages.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 14
01/01/2022 SUMMARY / Q&A
• Increased ability to express ideas/algorithms: In Natural language, the depth at which people think is
influenced by the expressive power of the language they use. In programming language, the complexity of the
algorithms that people Implement is influenced by the set of constructs available in the programming language.
• Improved background for choosing appropriate Languages: If these programmers were familiar with
a wider range of languages and language constructs, they would be better able to choose the language with the
features that best address the problem.
• Increased ability to learn new languages: For instance, knowing the concept s of object oriented
programming OOP makes learning Java significantly easier and also, knowing the grammar of one’s native
language makes it easier to learn another language.
• Better Understanding of Significance of implementation: This leads to understanding of why languages
are designed the way they are. This is an ability to use a language more intellectually, as it was designed to be
used. It allows visualization of how a computer executes various language constructs. It provides hints about the
relative efficiency of alternative constructs that may be chosen for a program.
• Better use of languages that are already known: Many contemporary programming languages are large
and complex.
• The overall advancement of computing: The study of programming language concepts should be
justified and the choose languages should be well informed so that better languages would eventually squeeze out
poorer ones.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 15
01/01/2022 SUMMARY / Q&A
• Expressivity: means the ability of a language to clearly reflect the meaning intended by the algorithm
designer (the programmer). Thus an “expressive” language permits an utterance to be compactly stated, and
encourages the use of statement forms associated with structured programming (usually “while “loops and “if –
then – else” statements).
• Well-Definedness: By “well-definiteness”, we mean that the language’s syntax and semantics are free of
ambiguity, are internally consistent and complete.
• Data types and structures: By “Data types and Structures”, we mean the ability of a language to support
a variety of data values (integers, real, strings, pointers etc.) and nonelementary collect ions of these.
• Readability: One of the most important criteria for judging a programming language is the ease with
which programs can be read and understood.
• Overall Simplicity: The overall simplicity of a programming language strongly affects its readability. A
language with a large number of basic constructs is more difficult to learn than one with a smaller number.
• Modularity: Modularity has two aspects: the language’s support for sub-programming and the language’s
extensibility in the sense of allowing programmer – defined operators and data types. By sub programming, we
mean the ability to define independent procedures and functions (subprograms), and communicate via parameters
or global variables with the invoking program.
• Input-Output facilities: In evaluating a language’s “Input-Output facilities” we are looking at its support
for sequential, indexed, and random access files, as well as its support for database and information retrieval
functions.
• Portability: A language which has “portability” is one which is implemented on a variety of computers.
• Efficiency: An “efficient” language is one which permits fast compilation and execution on the machines
where it is implemented. Traditionally, FORTRAN and COBOL have been relatively efficient languages in their
respective application areas.
• Orthogonality: in a programming language means that a relatively small set of primitive constructs can
be combined in a relatively small number of ways to build the control and data structures of the language.
Furthermore, every possible combination of primitives is legal and meaningful.
• Pedagogy: Some languages have better “pedagogy” than others. That is, they are intrinsically easier to
teach and to learn, they have better textbooks; they are implemented in a better program development
environment, they are widely known and used by the best programmers in an application area.
• Generality: Generality: Means that a language is useful in a wide range of programming applications. For
instance, APL has been used in mathematical applications involving matrix algebra and in business applications
as well. The table below show language evaluation criteria and the characteristics that affect them.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 16
01/01/2022 SUMMARY / Q&A
QUESTION
WHAT IS SYNTACTIC ANALYSIS
SUGGESTED ANSWER
Syntax is the set of rules that define what the various combinations of symbols mean.
This tells the computer how to read the code. Syntax refers to a concept in writing code dealing with a very
specific set of words and a very specific order to those words when we give the computer instructions.
• Lexical syntax for defining the rules for basic symbols involving identifiers, literals, punctuators and
operators.
• Concrete syntax specifies the real representation of the programs with the help of lexical symbols like its
alphabet.
• Abstract syntax conveys only the vital program information.
Language Recognizer
The syntax analysis part of a compiler is a recognizer for the language the compiler translates. In this role, the
recognizer need not test all possible strings of characters from some set to determine whether each is in the
language.
QUESTION
WHAT IS Language Generator
SUGGESTED ANSWER
A language generator is a device that can be used to generate the sentences of a language. a generator seems to
be a device of limited usefulness as a language descriptor.
Syntactic Ambiguity
Syntactic ambiguity is a property of sentences which may be reasonably interpreted in more than one way, or
reasonably interpreted to mean more than one thing.
Ambiguity may or may not involve one word having two parts of speech or homonyms.
Parsing
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 17
01/01/2022 SUMMARY / Q&A
Parsing is the process of analyzing a text, made of a sequence of tokens for example, words, to determine its
grammatical structure with respect to a given (more or less) formal grammar.
Parsing can also be used as a linguistic term, especially in reference to how phrases are divided up in garden path
sentences.
Parse Trees
These hierarchical structures are called parse trees. For example, the parse tree in the diagram below showed the
structure of the assignment statement derived. Every internal node of a parse tree is labeled with a nonterminal
symbol; every leaf is labeled with a terminal symbol. Every subtree of a parse tree describes one instance of an
abstraction in the sentence.
A = B * (A + C)
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 18
01/01/2022 SUMMARY / Q&A
Parser
The parser often uses a separate lexical analyzer to create tokens from the sequence of input characters. Parsers
may be programmed by hand or may be (semi-)automatically generated (in some programming languages) by a
tool.
Types of parser
The task of the parser is essentially to determine if and how the input can be derived from the start symbol of the
grammar. This can be done in essentially two ways:
• Top-down parsing: Top-down parsing can be viewed as an attempt to find leftmost derivations of an
input-stream by searching for parse trees using a top-down expansion of the given formal grammar rules.
• Bottom-up parsing: A parser can start with the input and attempt to rewrite it to the start symbol.
Intuitively, the parser attempts to locate the most basic elements, then the elements containing these,
This is the process of recognizing an utterance (a string in natural languages) by breaking it down to a set of
symbols and analyzing each one against the grammar of the language. Most languages have the meanings of their
utterances structured according to their syntax—a practice known as compositional semantics
Expression Notations
An expression may consist of one or more operands, and zero or more operators to produce a value.
Programming languages generally support a set of operators that are similar to operations in mathematics. A
language may contain a fixed number of built-in operators (e.g. + - * = in C and C++), or it may allow the creation
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 19
01/01/2022 SUMMARY / Q&A
Overloaded operators
In languages that support operator overloading by the programmer but have a limited set of operators, operator
overloading is often used to define customized uses for operators.
Short-Circuit Evaluation
Short-circuit evaluation and minimal evaluation, denotes the semantics of some Boolean operators in some
programming languages in which the second argument is only executed or evaluated if the first argument does
not suffice to determine the value of the expression: when the first argument of the AND function evaluates to
false, the overall value must be false; and when the first argument of the OR function evaluates to true, the overall
value must be true. In some programming languages like Lisp, the usual Boolean operators are short-circuit. In
others like Java, Ada; both short-circuit and standard Boolean operators are available.
Categories of Expressions
• Boolean Expression - an expression that returns a Boolean value, either true or false. This kind of
expression can be used only in the IF-THEN-ELSE control structure and the parameter of the display condition
command. A relational expression has two operands and one relational operator.
• Numeric Expression - an expression that returns a number. This kind of expression can be used in
numeric data fields. It can also be used in functions and commands that require numeric parameters.
• Character Expression - an expression that returns an alphanumeric string. This kind of expression can
be used in string data fields (format type Alpha).
• Relational Expression: Relational operator is a programming language construct or operator that test or
define some kind of relation between two entities.
Relational operators are usually written in infix notation, if supported by the programming language, which means
that they appear between their operands (the two expressions being related).
Operator Precedence
When expressions contain operators from more than one category, arithmetic operators are evaluated first,
comparison operators are evaluated next, and logical operators are evaluated last. Comparison operators all have
equal precedence; that is, they are evaluated in the left-to-right order in which they appear. Arithmetic and logical
operators are evaluated in the following order of precedence:
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 20
01/01/2022 SUMMARY / Q&A
The string concatenation operator (&) is not an arithmetic operator, but in precedence it does fall after all
arithmetic operators and before all comparison operators. The Is operator is an object reference comparison
operator. It does not compare objects or their values; it checks only to determine if two object references refer to
the same object.
Program Operators are the foundation of any programming language. Thus, the functionality of C/C++ /Java
programming language is incomplete without the use of operators. We can define operators as symbols that helps
us to perform specific mathematical and logical computations on operands. In other words, we can say that an
operator operates the operands.:
c = a + b;
Here, ‘+’ is the operator known as addition operator and ‘a’ and ‘b’ are operands. The addition operator tells the
compiler to add both of the operands ‘a’ and ‘b’. C/C++ has many built-in operator types and they can be classified
as:
•Arithmetic Operators: These are the operators used to perform arithmetic/mathematical operations on
operands. Examples: (+, -, *, /, %,++,–). Arithmetic operator are of two types:
1. Unary Operators: Operators that operates or works with a single operand are unary operators. For
example: (++ , –)
2. Binary Operators: Operators that operates or works with two operands are binary operators. For example:
(+ , – , * , /)
• Relational Operators: Relational operators are used for comparison of the values of two operands. For
example: checking if one operand is equal to the other operand or not, an operand is greater than the other operand
or not etc. Some of the relational operators are:
(==, > , = , <= ).
• Logical Operators: Logical Operators are used to combine two or more conditions/constraints or to
complement the evaluation of the original condition in consideration. Bitwise Operators: The Bitwise operators
is used to perform bit-level operations on the operands. The operators are first converted to bit-level and then
calculation is performed on the operands.
• Assignment Operators: Assignment operators are used to assign value to a variable. The left side operand
of the assignment operator is a variable and right side operand of the assignment operator is a value.
For example:
a = 10; b = 20;
ch = 'y'; “+=”: This operator is combination of ‘+’ and ‘=’ operators. This operator
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 21
01/01/2022 SUMMARY / Q&A
first adds the current value of the variable on left to the value on right and then assigns the result to the variable
on the left. Example:
“-=”: This operator is combination of ‘-‘ and ‘=’ operators. This operator first subtracts the current value of the
variable on left from the value on right and then assigns the result to the variable on the left.
“*=”: This operator is combination of ‘*’ and ‘=’ operators. This operator first multiplies the current value of the
variable on left to the value on right and then 21 assigns the result to the variable on the left.
“/=”: This operator is combination of ‘/’ and ‘=’ operators. This operator first divides the current value of the
variable on left by the value on right and then assigns the result to the variable on the left.
Lexical Syntax
QUESTION
WHAT ARE THE THREE REASONS WHY LEXICAL ANALYSIS IS SEPARATED FROM SYNTAX
ANALYSIS:
SUGGESTED ANSWER
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 22
01/01/2022 SUMMARY / Q&A
• Simplicity: Techniques for lexical analysis are less complex than those required for syntax analysis, so
the lexical-analysis process can be simpler if it is separate. Also, removing the low-level details of lexical analysis
from the syntax analyzer makes the syntax analyzer both smaller and less complex.
• Efficiency: Although it pays to optimize the lexical analyzer, because lexical analysis requires a
significant portion of total compilation time, it is not fruitful to optimize the syntax analyzer. Separation facilitates
this selective optimization.
• Portability: Because the lexical analyzer reads input program files and often includes buffering of that
input, it is somewhat platform dependent. However, the syntax analyzer can be platform independent. It is always
good to isolate machine-dependent parts of any software system.
Token Lexeme
IDENT result
ASSIGN_OP =
IDENT oldsum
SUB_OP -
IDENT value
DIV_OP /
INT_LIT 100
SEMICOLON ;
Lexical analyzers extract lexemes from a given input string and produce the corresponding tokens. In the early
days of compilers, lexical analyzers often processed an entire source program file and produced a file of tokens
and lexemes.
Lexical units are considered the building blocks of programming languages. The lexical structured of all
programming languages are similar and normally include the following kinds of units:
• Identifiers: Names that can be chosen by programmers to represent objects lie variables, labels,
procedures and functions.
• Keywords: Names reserved by the language designer are used to form the syntactic structure of the
languages.
• Operators: Symbols used to represent the operations. All general-purpose programming languages should
provide certain minimum operators such as mathematical operators like +, -, *, ?, relational operators like <, ≤,
==. >, ≥, and logic operators like
AND, OR, NOT, etc.
• Separators: Symbols used to separate lexical or syntactic units of the language. Space, comma, colon,
semicolon and parentheses are used as separators.
• Literals: Values that can be assigned to variables of different types. For example, integertype literals are
integer numbers, character-type literals are any character from the character set of the language and string-type
literals are any string of characters.
• Comments: Any explanatory text embedded in the program. Comments start with a specific keyword or
separator. When the compiler translates a program into machine code, all comments will be ignored.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 23
01/01/2022 SUMMARY / Q&A
• Write a formal description of the token patterns of the language using a descriptive language related to
regular expressions. These descriptions are used as input to a software tool Design a state transition diagram that
describes the token patterns of the language and write a program that implements the diagram.
• Design a state transition diagram that describes the token patterns of the language and hand-construct a
table-driven implementation of the state diagram.
Finite automata can be designed to recognize members of a class of languages called regular languages. Regular
grammars are generative devices for regular languages. The tokens of a programming language are a regular
language, and a lexical analyzer is a finite automaton.
The rules describe how to form strings from the language's alphabet that are valid according to the language's
syntax.
Therefore, a grammar is usually thought of as a language generator. However, it can also sometimes be used as
the basis for a recognizer.
The production rulesare then applied in any order, until a string that contains neither the start symbol nor
designated nonterminal symbolsis produced..
A grammar is usually thought of as a language generator.One of the interesting results of automata theory is that
it is not possible to design a recognizer for certain formal languages
In the classic formalization of generative grammars, a grammar G consists of the following components:
• a finite set N of non-terminal symbols, none of which appear in strings formed from G.
• a finite set of terminal symbolsthat is disjoint from N.
• a finite set P of production rules, each rule of the form
• where * is the Kleene star operator and denotes set union.
That is, each production rule maps from one string of symbols to another, where the first string
(the "head") contains at least one non-terminal symbol. In the case that the second string (the "body") consists
solely of the empty string – i.e. it contains no symbols at all, it may be denoted with a special notation (often _, e
or _) in order to avoid confusion.
A distinguished symbol, that is, the start symbol. A grammar is formally defined as the tuple (N, _, P, S). Such a
formal grammar is often called a rewriting system or a phrase structure grammar in the literature A grammar can
be formally written as four tuple element i.e. G = {N, ℇ, S, P}
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 24
01/01/2022 SUMMARY / Q&A
Example 1:Assuming the alphabet consists of a and b, the start symbol is S and we have the following production
rules:
1. S→aSb
2. S→ ba
then we start with S, and can choose a rule to apply to it. If we choose rule 1, we obtain the string aSb. If we
choose rule 1 again, we replace S with aSband obtain the string aaSbb. If we now choose rule 2, we replace S
with baand obtain the string aababb, and are done.
We can write this series of choices more briefly, using symbols: S→aSb →aaSbb →aababb. The language of the
grammar is then the infinite set {an babn | n ≥ 0} = {ba, abab, aababb, aaababbb, ------}, where akis a repeated k
times (and n in particular represents the number of times production rule 1 has been applied).
Example 2:Consider the grammar G where N = {S, B} = {a, b, c}, S is the start symbol and P consists of the
following production rules:
1. S→ aBSc 2. S→ abc
3. Ba → aB
4. Bb → bb
This grammar defines the language L(G) = anbncn | n ≥ 1} where an denotes a string of n consecutive a’s. Thus the
language is the set of strings that consist of one or more a’s, followed by the same number of b’s and then by the
same number of c’s.
Solution:
S →2abc
S → 1aBSc →2aBabcc →3aaBbcc →4aabbcc
S →1aBSc →1aBaBScc →2 aBaBabccc →3aaBBabaccc →3aaBaBbccc →3aaaBBbccc →4aaaBbbccc
→4aaabbbccc
Example 3:Consider G = ({S, A, B}, {a, b}, S, P) N = {S, A, B} produce 2 sample strings from the grammar and
a2b4 is contained in the grammar?
1. P: S → AB
2. A → Aa
3. B → Bb
4. A→a
5. B→b
Solution:
S → 1AB
S → 1AB → 2AaB → 3AaBb → 3AaBbb → 3AaBbbb → 4aaBbbb → 5aabbbb
Example 4:Analyze the structure of this grammar G = {V, T, S, P} where V is used in place of N and T is used
in place of ℇ and produce 4 sample strings from the grammar?
G = (V, T, S, P), V = (A, S, B), T = (λ, a, b)
1. P: S → ASB
2. A→a
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 25
01/01/2022 SUMMARY / Q&A
3. B→b
4. S→λ
Solution:
S → 4λ
S → 1ASB → 2aSB → 3aSb → 4ab
S → 1ASB → 4AB S → 1ASB → 2aSB → 4aB
The syntax of whole programming languages, with minor exceptions, can be described by context-free grammars.
It is remarkable that BNF is nearly identical to Chomsky’s generative devices for context-free languages, called
context-free grammar and context-free grammars simply refer to as grammars.
The difference between these types is that they have increasingly strict production rules and can express fewer
formal languages. Two important types are context-free grammars(Type 2) and regular grammars(Type 3)
The following table and diagram summarize each of Chomsky's four types of grammars, the class of language it
generates, the type of automaton that recognizes it, and the form its rules must have.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 26
01/01/2022 SUMMARY / Q&A
Informal Semantic
Semantics term in a programming language is used to figure out the relationship among the syntax and the model
of computation.
An approach known as syntax-directed semantics is used to map syntactical constructs to the computational model
with the help of a function. Semantic analysis is to provide the task acknowledgment and statements of a
semantically correct program.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 27
01/01/2022 SUMMARY / Q&A
Operational Semantics
Determining the meaning of a program in place of the calculation steps which are necessary to idealized execution.
Some definitions used structural operational semantics which intermediate state is described on the basis of the
language itself others use abstract machine to make use of more ad-hoc mathematical constructions.
With an operational semantics of a programming language, one usually understands a set of rules for its
expressions, statements, programs, etc., are evaluated or executed.
These guidelines tell how a possible implementation of a programming language should be working and it is not
difficult to give skills an implementation of an interpreter of a language in any programming languages simply
by monitoring and translating it operational semantics of the language destination deployment.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 28
01/01/2022 SUMMARY / Q&A
Denotational Semantics
Determining the meaning of a program as elements of a number of abstract mathematical structures e.g. with
regard to functions such as programming language specific mathematical functions.
The approach provides rules of inference (the axioms) which show the change of data after the execution of a
certain sentence of the language. The typical situation is that the execution (i.e. the transformation of data) takes
place provided that the data satisfies certain conditions, and the inference rules are used to deduce the results
satisfying also some conditions. Example:
{ P} S {Q }
where S is a program (or a part of a program) written in a certain programming language, and P and a are logical
expressions (assertions, using standard mathematical notations together with logical operators) describing
conditions on the program variables used in S.
A simple example can be given in the following way, where we assume a and b to be integers:
meaning that if b > 10 before executing the assignment a: = 10 + 4 *b, then the value of a will be greater 20 after
the assignment is executed.
Static semantics
The static semantics defines restrictions on the structure of valid texts that are hard or impossible to express in
standard syntactic formalisms. Examples include checking that every identifier is declared before it is used (in
languages that require such declarations) or that the labels on the arms of a case statement are distinct.
Newer programming languages like Java and C# have definite assignment analysis, a form of data flow analysis,
as part of their static semantics.
Dynamic semantics
Language is often used to specify the execution semantics of languages commonly used in practice. A significant
amount of academic research went into formal semantics of programming languages, which allow execution
semantics to be specified in a formal manner. Results from this field of research have seen limited application to
programming language design and implementation outside academia.
It uses syntax tree and symbol table to check whether the given program is semantically consistent with language
definition.
Semantic Errors
Some of the semantics errors that the semantic analyzer is expected to recognize:
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 29
01/01/2022 SUMMARY / Q&A
• Type mismatch
• Undeclared variable
• Reserved identifier misuse.
• Multiple declaration of variable in a scope.
• Accessing an out of scope variable.
• Actual and formal parameter mismatch.
• uages.
3.0 MAIN CONTENT
3.1 Primitive Data type
It is a basic data type which is provided by a programming language as a basic building block. Most languages
allow more complicated composite types to be recursively constructed starting from basic types. It also a built-in
data type for which the programming language provides built-in support.
• Integer: a whole number that can have a positive, negative, or zero value. It cannot be a fraction, nor can
it include decimal places. It is commonly used in programming, especially for increasing values. Addition,
subtraction, and multiplication of two integers results in an integer. However, division of two integers may result
in either an integer or a decimal. The resulting decimal can be rounded off or truncated in order to produce an
integer.
• Character: any number, letter, space, or symbol that can be entered in a computer. Every character
occupies one byte of space.
• String: used to represent text. It is composed of a set of characters that can include spaces and numbers.
Strings are enclosed in quotation marks to identify the data as strings, and not as variable names, nor as numbers.
• Floating Point Number: a number that contains decimals. Numbers that contain fractions are also
considered floating-point numbers.
• Varchar: as the name implies, a varchar is a variable character, on account of the fact that the memory
storage has variable length. Each character occupies one byte of space, plus 2 bytes additional for length
information.
• Array: a kind of a list that contains a group of elements which can be of the same data type as an integer
or string. It is used to organize data for easier sorting and searching of related sets of values. An array is a
collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type
together. This makes it easier to calculate the position of each element by simply adding an offset to a base value,
i.e., the memory location of the first element of the array (generally denoted by the name of the array). The base
value is index 0 and the difference between the two indexes is the offset.
Each variable, called an element, is accessed using a subscript (or index). All arrays consist of contiguous memory
locations. The lowest address corresponds to the first element and the highest address to the last element.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 30
01/01/2022 SUMMARY / Q&A
Some programming languages categorize the kinds of data they handle into: Simple and Composite data. The
simple data types are generally termed primitives. The data types supported by programming languages differ in
different forms.
For instance, C programming language has the following examples of data as being supported: Simple: integer,
long integer, short integer, float, double, character, Boolean and so on. Enumeration, Structure, Array, and String.
The various data types are used to specify and handle the kind of data to be used in programming problem.
Different programming languages supports different kinds of data types. At times in programming, there may be
a need to convert a data from one type to the other. Java and C++ (and some other languages) are good examples
of programming language that support type conversion.
Type Conversion in C
The conversion is done only between those datatypes wherein the conversion is possible ex – char to int and vice
versa.
This type of conversion is usually performed by the compiler when necessary without any commands by the user.
Thus it is also called "Automatic Type Conversion".
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 31
01/01/2022 SUMMARY / Q&A
Explicit type conversion rules out the use of compiler for converting one data type to another instead the user
explicitly defines within the program the datatype of the operands in the expression. The example below illustrates
how explicit conversion is done by the user. Example:
//explicitly defined by user int result = (int)da + (int)db + (int)dc; printf("result = %d", result);
result = 12
find that the output result is 12 because in the result expression the user has explicitly defined the operands
(variables) as integer data type. Hence, there is no implicit conversion of data type by the compiler.
When you assign value of one data type to another, the two types might not be compatible with each other. If the
data types are compatible, then Java will perform the conversion automatically known as Automatic Type
Conversion and if not then they need to be casted or converted explicitly. For example, assigning an int value to
a long variable.
Widening conversion takes place when two data types are automatically converted. This happens when:
• The two data types are compatible.
• When we assign value of a smaller data type to a bigger data type.
class Test
{ public static void main(String[] args)
{ int i = 100;
// automatic type conversion long l = i;
// automatic type conversion float f = l;
System.out.println("Int value "+i);
System.out.println("Long value "+l);
System.out.println("Float value "+f);
}
If we want to assign a value of larger data type to a smaller data type we perform explicit type casting or narrowing.
• This is useful for incompatible data types where automatic conversion cannot be done.
• Here, target-type specifies the desired type to convert the specified value to.
• char and number are not compatible with each other. Let’s see when we try to convert one into other.
• filter_none
• edit
• play_arrow
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 32
01/01/2022 SUMMARY / Q&A
• brightness_4
Example:
filter_none 33 edit play_arrow brightness_4
//Java program to illustrate explicit type conversion class Test { public static void main(String[] args)
{ double d = 100.04;
//explicit type casting
long l = (long)d; //explicit type casting int i = (int)l;
System.out.println("Double value "+d);
//fractional part lost
System.out.println("Long value "+l);
//fractional part lost
System.out.println("Int value "+i);
}
}
/Java program to illustrate Conversion of int and double to byte class Test { public static void main(String
args[])
{ byte b; int i = 257; double d = 323.142;
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 33
01/01/2022 SUMMARY / Q&A
It is a symbolic name given to some known or unknown quantity or information, for the purpose of allowing the
name to be used independently of the information it represents.
• Elementary level: Elementary (sometimes also called basic or simple) types, such as integers, reals, boo
leans, and characters, are supported by nearly every programming language. Data objects of these types can be
manipulated by well-known operators, like +, - , *, or /, on the programming level. It is the task of the compiler
to translate the operators onto the correct machine instructions, e.g. fixed-point and floating-point operations. See
diagram below:
• Structured level: Static structures are arrays, records, and sets, while dynamic structures are a b it more
complicated, since they are recursively defined and may vary in size and shape during the execution of a program.
Lists and trees are dynamic structures.
• Abstract level: Programmer defined abstract data types are a set of data objects with declared operations
on these data objects.
Global variable
A Global variable is the kind of variable that is accessible from other classes outside the program or class in which
it is declared. Different programming languages have various of ways in which global variables are being
declared, when the need arises.
Local Variable
A local variable is the kind of variable that is not accessible from other classes outside the program or class in
which it is declared.
These are variables that are used within the current program unit (or function) in a later section we will looking
at global variables - variables that are available to all the program's functions.
Naming conventions
Unlike their mathematical counterparts, programming variables and constants commonly take multiple-character
names, e.g. COST or total. Single-character names are most commonly used only for auxiliary variables; for
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 34
01/01/2022 SUMMARY / Q&A
instance, i, j, k for array index variables. Some naming conventions are enforced at the language level as part of
the language syntax and involve the format of valid identifiers. In almost all languages, variable names cannot
start with a digit (0-9) and cannot contain whitespace characters.
There are various kinds of programming languages. Some languages do not require that variables are declared in
a program before being used while some require that variables are declared. We can therefore have implicit and
explicit variable declaration. Variables can also be classified as global or local, depending on the level of access
from within the program.
A good example of programming language that supports this variable declaration type is Python. That is, in
Python, a programmer may declare or choose not to declare the variable that he intends using in a programming
language.
Examples of such languages that support explicit variable declaration are: Java, C, C++, PASCAL, FORTRAN,
and many others. It is important for a programmer to always declare variable before using them in languages like
C, C++, VBscript and Java. Depending on the data type to be used in a program, examples of variable declaration
some selected languages are as below:
The Basic data types associated with variables in languages such as C and Java
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 35
01/01/2022 SUMMARY / Q&A
Note: In C++ and Java, the modifiers or specifiers are used to indicate whether a variable is global or local.
It has earlier been pointed out that Java has a wide range of data structures.
Java has It has earlier been pointed out that Java has a wide range of data structures.
The data structures provided by the Java utility package are very powerful and perform a wide range of functions.
These data structures consist of the following interface and classes:
• Enumeration
• BitSet
• Vector
• Stack
• Dictionary
• Hashtable
• Properties
Dynamic Binding allows greater flexibility but at the expense of readability, efficiency and reliability. Binding
describes how a variable is created and used (or "bound") by and within the given program, and, possibly, by
other programs, as well. There are two types of binding; Dynamic, and Static binding.
Dynamic Binding
Also known as Dynamic Dispatch) is the process of mapping a message to a specific sequence of code (method)
at runtime.
Static Binding
It occurs first before run time and remains unchanged throughout program execution
As an example, let us take a look at the program below, implemented in C. In line 1, we have defined three names:
int, i and x. One of them represents a type while the others represent the declaration of two variables. The
specification of the C language defines the meaning of the keyword int. The properties related to this specification
are bound when the language is defined. There are other properties that are left out of the language definition. An
example of this is the range of values for the int type. In this way, the implementation of a compiler can choose a
particular range for the int type that is the most natural for a specific machine. The type of variables i and x in the
first line is bound at compilation time. In line 4, the program calls the function do_something whose definition
can be in another source file.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 36
01/01/2022 SUMMARY / Q&A
The linker tries to find the function definition for generating the executable file. At loading time, just before a
program starts running, the memory location for main, do_something, i and x are bound. Some bindings occur
when the program is running, i.e., at runtime. An example is the possible values attributed to i and x during the
execution of the program.
Static Scope
The static scope of a variable is the most immediately enclosing block, excluding any enclosed blocks where the
variable has been re-declared.
Dynamic Scope
The dynamic scope of a variable extends to all the procedures called thereafter during program execution, until
the first procedure to be called that re-declares the variable.
Referencing
The referencing environment is the collection of variable which can be used. In a static scoped language, one can
only reference the variables in the static reference environment.
Other programming languages like C, PASCAL, DELPHI, Python, FORTRAN, Scala among others have their
syntaxes for handling flow control.
Control Structures are just a way to specify flow of control in programs. Any algorithm or program can be more
clear and understood if they use self-contained modules called as logic or control structures. It basically analyzes
and chooses in which direction a program flows based on certain parameters or conditions. There are three basic
types of logic, or flow of control, known as:
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 37
01/01/2022 SUMMARY / Q&A
Sequential logic as the name suggests follows a serial or sequential flow in which the flow depends on the series
of instructions given to the computer. Unless new instructions are given, the modules are executed in the obvious
sequence.
Selection Logic simply involves a number of conditions or parameters which decides one out of several written
modules. The structures which use these type of logic are known as Conditional Structures.
In this way, the flow of the program depends on the set of conditions that are written. This can be more understood
by the following flow charts:
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 38
01/01/2022 SUMMARY / Q&A
The Iteration logic employs a loop which involves a repeat statement followed by a module known as the body
of a loop. The two types of these structures are:
Repeat for i = A to N by I:
[Module]
[End of loop]
Here, A is the initial value, N is the end value and I is the increment. The loop ends when A>B. K increases or
decreases according to the positive and negative value of I respectively.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 39
01/01/2022 SUMMARY / Q&A
Repeat-For Flow
Repeat-While Structure: It also uses a condition to control the loop. This structure has the form:
In this, there requires a statement that initializes the condition controlling the loop, and there must also be a
statement inside the module that will change this condition leading to the end of the loop.
Runtime of a Program
Run time is also called execution time. It is the time during which a program is running (executing), in contrast
to other program lifecycle phases such as compile time, link time and load time.
Runtime programming is about being able to specify program logic during application execution, without going
through the code-compile-execute cycle.
Type Checking
Type checking is the activity of ensuring that the operands of an operator are of compatible types. A compatible
type is one that either is legal for the operator or is allowed under language rules to be implicitly converted by
compiler-generated code (or the interpreter) to a legal type.
A programming language is strongly typed if type errors are always detected. This requires that the types of all
operands can be determined, either at compile time or at run time. The importance of strong typing lies in its
ability to detect all misuses of variables that result in type errors. A strongly typed language also allows the
detection, at run time, of uses of the incorrect type values in variables that can store values of more than one type.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 40
01/01/2022 SUMMARY / Q&A
A good example of strongly type language is LISP while, weakly typed languages have a weak type-check and
allows expressions between various different types which has looser typing rules and may produce unpredictable
or even erroneous results or may perform implicit type conversion at runtime. C and C++ are weakly typed
languages because both include union types, which are not type checked.
Type Compatibility
In most language a value’s type must be compatible with that of the context in which it appears. In an assignment
statement, the type of the right-hand side must be compatible with that of the left-hand side.
Type checking is the practice of ensuring that data objects which are somehow related are of compatible types.
Two objects are related by forming the left and right side of an operator, by forming the left and right side of an
assignment statement and by being actual and formal parameters. Consistency checks which are made before the
execution of a source program (i.e. by the compiler) are said to be static checks, while those checks performed
during the execution of a source program are called dynamic checks (or run-time checks). Checking the syntax is
an example for static checks, while type checks are an example of checks which often can be done statically, and
which sometimes must be done dynamically.
Garbage Collection
Automatic reclamation (otherwise known as garbage collection) is more-or-less essential for functional
languages: delete is a very imperative sort of operation, and the ability to construct and return arbitrary objects
from functions means that many objects that would be allocated on the stack in an imperative language must be
allocated from the heap in a functional language, to give them unlimited extent.
Garbage collection presents a classic tradeoff between convenience and safety on the one hand and performance
on the other.
An Abstract Data Type is a user-defined data type that satisfies the following two conditions:
• The representation of, and operations on, objects of the type are defined in a single syntactic unit.
• The representation of objects of the type is hidden from the program units that use these objects, so the
only operations possible are those provided in the type's definition
Advantages of Abstraction
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 41
01/01/2022 SUMMARY / Q&A
Helps to increase the security of an application or program as only important details are provided to the user.
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 42
01/01/2022 SUMMARY / Q&A
Procedure Mechanisms
Characteristics
Although procedures might be slightly different in their usage and implementation in different programming
languages, there exist some common characteristics. Among them are:
• Procedures are referred to by a name. They usually have local variable declarations, as well as some
parameters forming the communication interface to other procedures and the main program. In addition to this,
functions are bound to a particular type, i.e. the t~ result they produce.
Code Reduction
Complexity Reduction
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 43
01/01/2022 SUMMARY / Q&A
• A procedure has only one entry point (FORTRAN makes an exception, since it allows the execution of a
subprogram to begin at any desired executable statement using the ENTRY statement; but the overall concept is
the same as for single entry procedures).
• The procedure call mechanism allocates storage for local data structures.
• The procedure call mechanism transfers control to the called instance and suspends the calling instance
during the execution of the procedure (i.e. no form of parallelism or concurrency is allowed).
• The procedure return mechanism deallocates storage for local data structures.
• The procedure return mechanism transfers control back to the calling instance when the procedure
execution terminates.
Procedure Implementation
The principle actions associated with a procedure call/return mechanism are as follows:
Where calls to subroutines cannot be placed in an expression whether it is in the main program where subroutine
is activated by using CALL statement which include the list of inputs and outputs that enclosed in the open and
closed parenthesis and they are called the arguments of the subroutines. There are some of the rules follow by
both to define name like less than six letters and start with the letters. The name should be different that used for
variables and functions.
Subroutine (also called procedure, function, routine, method, or subprogram) is a portion of code within a larger
program that performs a specific task and is relatively independent of the remaining code.
A subroutine may be written so that it expects to obtain one or more data values from the calling program (its
parameters or arguments). It may also return a computed value to its caller (its return value), or provide various
result values or out(put) parameters. Indeed, a common use of subroutines is to implement mathematical
functions, in which the purpose of the subroutine is purely to compute one or more results whose values are
entirely determined by the parameters passed to the subroutine. (Examples might include computing the logarithm
of a number or the determinant of a matrix.)
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 44
01/01/2022 SUMMARY / Q&A
Advantages of Subroutines
• Decomposition of a complex programming task into simpler steps: this is one of the two main tools of
structured programming, along with data structures.
• Reducing the duplication of code within a program,
• Enabling the reuse of code across multiple programs, • Hiding implementation details from users of
the subroutine.
Disadvantages
• The invocation of a subroutine (rather than using in-line code) imposes some computational overhead in
the call mechanism itself.
• The subroutine typically requires standard housekeeping code—both at entry to, and exit from, the
function (function prologue and epilogue—usually saving general purpose registers and return address as a
minimum).
Iterations Mechanisms
Iteration is the technique marking out of a block of statements within a computer program for a defined number
of repetitions. That block of statements is said to be iterated. An iterator is a mechanism for control abstraction
that allows a procedure to be applied iteratively to all members of a collection in some definite order.
a=0
for I from 1 to 3 //loop three times
{
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 45
01/01/2022 SUMMARY / Q&A
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 46
01/01/2022 SUMMARY / Q&A
PLEASE PATRONIZE US FOR MORE COURSE SUMMARY, PAST QUESTIONS AND TMA (30/30)…
Click >> Whatsapp*Group << Click & Click >> Email << Click & Click >> Telegram*Group << Click pg. 47