Professional Documents
Culture Documents
BLOOMS LEVEL
Remember L1 Understand L2 Apply L3
Analyze L4 Evaluate L5 Create L6
PART - A
Q.N Answer All the Questions (10 x 2 = 20M) Marks BL
o
1 Write short note on BNF? 2M L1
Ans:-BNF, or Backus-Naur Form, is a notation used in computer
science and Principles of Programming Languages (PPL) to describe
the syntax of programming languages, context-free grammars, and
formal languages. It was introduced by John Backus and Peter Naur in
the 1960s. BNF is widely used in the specification of programming
languages and serves as the foundation for compiler and parser design.
2 Define Lexeme, Pattern and Token 2M L1
Ans:- Token:- Token is a sequence of characters that are treated as a unit
as it cannot be further broken down.
Lexeme:-it is a sequence of characters in the source code that are
matched by given predefined language rules for every lexeme to
be specified as a valid token.
Pattern:-it specifies a set of rules that a scanner follows to create a token
3 Explain in detail various design issues of character string 2M L2
types.
Ans:- Character string types are essential components in programming
languages, providing a way to represent and manipulate sequences of
characters.
The design issues related to character string types:-
1.Representation:-
Characters are represented in memory is a fundamental design
issue. Common representations include ASCII, Unicode, and UTF-8.
2.Length Representation:-
How the length of a string is stored is a crucial decision. Some
languages use a null-terminated approach, where a special character
(like \0) marks the end of the string. Others use a length prefix,
indicating the number of characters in the string.
2.Case Sensitivity:-
Deciding whether identifiers are case-sensitive or case-insensitive
affects naming conventions. Languages like C and C++ are case-
sensitive, while languages like Python are case-insensitive.
3.Reserved Words:-
Identifying and defining a set of reserved words (keywords) is
critical. These words have predefined meanings in the language and
cannot be used as identifiers.
5 What are the design issues for sub programs 2M L1
Ans:- Subprograms,also known as subroutines, functions, methods, or
procedures, play a vital role in programming languages by allowing
code to be organized into reusable units.
1.Interface Design:
Defining the interface of a subprogram includes specifying the
name, parameters, return type, and visibility. A well-designed interface
promotes clarity and ease of use.
2.Parameter Passing:-
Deciding how parameters are passed to subprograms is a crucial
design decision. Common methods include pass by value, pass by
reference, pass by result, and pass by name. The choice impacts
memory usage, side effects, and efficiency.
6 Write about Generic Subprograms 2M L2
Generic subprograms, also known as generic functions or polymorphic
functions, allow developers to write code that can operate on different
types of data without sacrificing type safety. This feature is particularly
useful in situations where a certain algorithm or operation is
conceptually the same but can be applied to a variety of data types.
Generic subprograms are designed to provide flexibility and reusability
across different data types.
7 Explain how information hiding is provided in an ADA 2M L2
package.
In Ada, information hiding is a key concept supported by the
package construct. Ada's package mechanism allows developers to
encapsulate data and procedures, controlling the visibility and
accessibility of these elements.
Here's how information hiding is provided in an Ada package:
PART - B
Mark
Q.No Question Description (10 x 5 = 50M) BL
s
a)Describe the important factors influencing the
writability of a language
The writability of a programming language refers to how easily and
effectively developers can write code in that language. Several factors
influence the writability of a programming language.
1.Syntax Clarity: The writability of a programming language refers to
how easily and effectively developers can write code in that language.
Several factors influence the writability of a programming language.
2.Abstraction Level:Higher-level abstractions simplify code, making it
more concise and easier to write.
1 3.Error Handling Mechanisms:Effective error handling mechanisms, 5M L2
such as informative error messages and exception handling, can
significantly improve writability by aiding developers in identifying and
fixing issues.
4. Flexibility:A language that offers flexibility in coding styles and
paradigms allows developers to choose approaches that best suit their
problem domain
5. Readability:Readable code is writable code. A language that
encourages clear and readable code, with consistent formatting and
naming conventions, enhances writability by making it easier for
developers to understand and write code.
b) What are the formal methods of describing syntax 5M L2
Formal methods of describing syntax are techniques used to precisely define
the structure of a programming language or any formal language. These
methods aim to provide a clear and unambiguous specification of the syntax,
ensuring that the language's grammar is well-defined. Here are some common
formal methods for describing syntax:
1. Backus-Naur Form (BNF):BNF is one of the earliest and widely
used formal methods for describing the syntax of programming
languages. It uses production rules to define the structure of a language.
BNF is particularly popular for specifying the syntax of context-free
grammars.
Example BNF rule: <expression> ::= <term> "+" <expression> | <term>
2. Extended Backus-Naur Form (EBNF):EBNF is an extension of
BNF that includes additional symbols and constructs for expressing
more complex syntactic structures. It often includes features like
optional elements, repetition, and grouping.
Example EBNF rule: expression = term, { "+", term } ;
3. Abstract Syntax Notation One (ASN.1):ASN.1 is a standard
interface description language used for defining data structures that can
be serialized and deserialized in a cross-platform way. It is often used in
telecommunication protocols.
Example ASN.1 definition: MyType ::= SEQUENCE {
Field1 INTEGER, field2 OCTET STRING }
4. W3C XML Schema Definition (XSD):XSD is a formal specification
language for XML documents. It defines the structure, data types, and
constraints of XML documents. XSD documents are written in XML.
Example XSD definition: <xs:element name="book" type="xs:string"/>
5. Railway Oriented Programming (ROP):ROP is a more recent
approach that uses diagrams resembling railway tracks to describe the
syntax of programming languages. It provides a visual representation of
the language's grammar.
Example ROP diagram: Start -> "if" -> Condition -> "then" ->
Expression -> "else" -> Expression
Advantages:
Easier debugging and development cycle.
Platform independence, as the interpreter can be designed to run on
different systems.
Disadvantages:
Generally slower execution compared to compiled languages.
Interpretation overhead may impact performance.
Examples: Python, JavaScript (in certain environments), Ruby.
2.Compilation:Compilation involves translating the entire source code
of a program into machine code or an intermediate code before
execution. This process is performed by a compiler, which generates an
executable file that can be run independently of the source code.
Advantages:
Generally results in faster execution as the entire program is optimized
during compilation.
Code is not exposed, providing a level of security.
Disadvantages:
Longer development cycles due to the separate compilation step.
Platform-dependent executables unless additional tools (like virtual
machines) are used.
Examples: C, C++, Java (with Java Virtual Machine), C# (with Common
Intermediate Language).
3.Just-In-Time Compilation (JIT):JIT compilation is a hybrid
approach that combines elements of interpretation and compilation. The
source code is initially translated into an intermediate representation, and
this intermediate code is then compiled into machine code at runtime,
just before execution.
Advantages:
Combines the advantages of interpretation (quick development cycle)
and compilation (optimized machine code).
Platform independence for the intermediate code.
Disadvantages:
Initial interpretation step may introduce some overhead.
require additional runtime support.
Examples: Java (with HotSpot JVM), C# (with .NET's Common
Language Runtime).
3 a)What are the design issues for character string types? 5M L2
Discuss.
Ans:- Character string types are essential components in programming
languages, providing a way to represent and manipulate sequences of
characters. The design of character string types involves addressing
various issues to ensure efficiency, flexibility, and compatibility with the
language's overall design.
1.Representation:-
Characters are represented in memory is a fundamental design issue.
Common representations include ASCII, Unicode, and UTF-8. The
choice affects the range of characters that can be supported and the
memory required for each character.
2.Length Representation:-
How the length of a string is stored is a crucial decision. Some
languages use a null-terminated approach, where a special character (like
\0) marks the end of the string. Others use a length prefix, indicating the
number of characters in the string.
5.String Operations:-
The set of operations that can be performed on strings, such as
concatenation, substring extraction, and searching, needs to be well-
defined. The efficiency of these operations can impact the overall
performance of string manipulation.
6.Literal Representation:-
How string literals are represented in source code affects readability
and ease of use. Common approaches include using double or single
quotes, and some languages support multi-line string literals.
7.Escape Sequences:-
The design must specify how escape sequences are handled within
strings. Escape sequences allow the representation of special characters
(e.g., newline, tab) and Unicode characters.
Derived Types:
• Definition:
In Programming Languages:
Derived types refer to new types that are created based on existing types.
This can include types that are derived through operations like arrays,
pointers, or user-defined operations.
In Database Systems:
Derived types can refer to types that are generated based on the data in
the database. For example, a query result or a view can be considered a
derived type.
• Creation:
In Programming Languages:
Derived types in programming languages can be created through
operations like array declarations, pointer declarations, or through user-
defined operations.
Database Systems:
Derived types in databases can be created through queries that combine
or transform existing data.
• Relationship with Base Types:
In Programming Languages:
Derived types in programming languages may have a more direct
relationship with base types. For example, an array is a derived type of
the element type.
In Database Systems:
Derived types in databases may represent transformations or
combinations of existing types.
Relative Advantages:
Example in Java:
public class OverloadedExample {
// Method with two integer parameters
public static int add(int a, int b) {
return a + b;
}
// Method with three double parameters
public static double add(double a, double b, double c) {
return a + b + c;
}
Example in Python:
class OverloadedExample:
# Method with two parameters of any type
def add(self, a, b):
return a + b
import asyncio
import aiohttp
if __name__ == "__main__":
asyncio.run(main())
In this example:
procedure Generic_Swap is
generic
type Element_Type is private;
procedure Swap(A, B : in out Element_Type);
-- Example usage
A, B : Integer := 5;
C, D : Float := 3.14;
begin
Put_Line("Before swapping:");
Put_Line("A = " & Integer'Image(A) & ", B = " & Integer'Image(B));
Swap(A, B);
Put_Line("After swapping:");
Put_Line("A = " & Integer'Image(A) & ", B = " & Integer'Image(B));
Put_Line("Before swapping:");
Put_Line("C = " & Float'Image(C) & ", D = " & Float'Image(D));
Swap(C, D);
Put_Line("After swapping:");
Put_Line("C = " & Float'Image(C) & ", D = " & Float'Image(D));
end Generic_Swap;
In this example:
3. Task Bodies:Tasks in Ada have bodies, which contain the actual code
to be executed concurrently. The body of a task is defined separately
from the task declaration.
4. Task Activation:Tasks can be activated by creating task objects. Task
objects are created using the new keyword. Once a task is created, it
begins executing its body concurrently with other tasks.
Operations on Semaphores:
Semaphores support two fundamental operations: P (Wait) and V
(Signal). These operations are also sometimes referred to as down and
up, or acquire and release. The semaphore maintains a non-negative
integer value, often referred to as the semaphore's count or value.
P(S):
if S > 0:
S=S-1
else:
block the process
2. V (Signal) Operation:
The V operation increments the semaphore count. If there are processes
blocked on the semaphore, one of them is unblocked. If the semaphore
count becomes positive, a blocked process is allowed to continue.The V
operation is often denoted as V(S) or Signal(S).ex:-
V(S):
S=S+1
if there are blocked processes:
unblock one of them
Binary Semaphores and Counting Semaphores:
1.Binary Semaphore:
A binary semaphore, also known as a mutex (mutual exclusion), has a
count that can only be 0 or 1. It is used to control access to a critical
section, allowing only one process to enter at a time.
2.Counting Semaphore:
A counting semaphore can have a count greater than 1. It is used to
control access to a resource with multiple instances, and the count
represents the number of available instances.
Example Usage:
Consider a scenario where two processes need to access a shared
resource protected by a semaphore: from threading import Thread,
Semaphore
import time
shared_resource = 0
def process_one():
global shared_resource
semaphore.acquire()
shared_resource += 1
semaphore.release()
def process_two():
global shared_resource
semaphore.acquire()
shared_resource -= 1
semaphore.release()
thread_one = Thread(target=process_one)
thread_two = Thread(target=process_two)
# Start the threads
thread_one.start()
thread_two.start()
thread_one.join()
thread_two.join()
1. Programming Paradigm:
Imperative:
Focuses on describing how a program operates, step by step.Emphasizes
changing program state through statements that modify variables and
control flow (e.g., loops, conditionals, assignments). Programs are
structured around sequences of commands that are executed in order.
• Functional:
Focuses on what the program should accomplish without specifying how
to achieve it.
Emphasizes the use of functions and expressions that produce values
without changing state.
Programs are structured around the composition of functions and the
application of functions to data.
2. State:
• Imperative:
Programs are stateful, and the emphasis is on changing the state of
variables.
Variables are mutable, and their values can be modified during program
execution.
Side effects (changes to state) are common and expected.
• Functional:
Programs are typically stateless, and the emphasis is on immutable data.
Variables are immutable, and once assigned, their values cannot be
changed.
Side effects are minimized, and functions are designed to be referentially
transparent (producing the same output for the same input).
3. Control Flow:
• Imperative:
Control flow is explicitly managed using statements like loops and
conditionals.
Emphasizes explicit sequencing and iteration.
• Functional:
Control flow is managed through function composition and recursion.
Emphasizes recursion and higher-order functions.
4. Data Mutation:
Imperative:
Supports mutable data structures, and changes to data are done in place.
Assignments and updates to variables are common.
• Functional:
Favors immutable data structures, and new data structures are created
rather than modified in place.
Avoids explicit assignments and updates, promoting a more declarative
style.
5. Side Effects:
• Imperative:
Programs often have side effects, such as modifying global variables,
performing I/O, or interacting with external state.
• Functional:
Minimizes or eliminates side effects to enhance predictability and ease
of reasoning about the code.
6. Concurrency:
• Imperative:
Often relies on locks and shared mutable state for managing
concurrency, which can lead to race conditions and synchronization
issues.
• Functional:
Emphasizes immutability and pure functions, which can simplify
concurrency by avoiding shared mutable state.
7. Examples:
• Imperative:
C, C++, Java, Python (to some extent), and most procedural languages.
• Functional:
Haskell, Lisp, ML, F#, and functional aspects of languages like Scala
and JavaScript.
2. Lists:
Lists are fundamental data structures in LISP. They can contain
atoms or other lists.
; Examples of lists
'(1 2 3) ; List of numbers
'(apple orange) ; List of symbols
'(1 (2 3) 4) ; Nested list
3. Symbols:
Symbols are used to represent names or identifiers. They can be
variables, function names, or other identifiers.
; Examples of symbols
'x
'length
'+
4. Numbers:
Numeric literals represent integers or floating-point numbers.
; Examples of numbers
42
-3.14
5. Functions:
Functions are a key feature of LISP. They can be defined using the
defun special form
; Example of defining a function
(defun square (x)
(* x x))
6. Special Forms:
Special forms are expressions with special evaluation rules.
Examples include if, cond, and defun.
; Example of using if
(if (> 5 3)
'greater
'lesser) ; Returns 'greater
7. Variables:
Variables are used to store values. They are typically introduced
using setq or as function parameters
9. Quoting:
Quoting prevents the evaluation of an expression, treating it as
data.
; Example of quoting
(setq y 5)
(list 'x y) ; Returns (x 5) without evaluating the value of y
10. Cons:
The cons function creates a new cons cell, forming a new pair.
; Example of cons
(cons 'a 'b) ; Returns (a . b)
..*****..