JNTU
JNTU B.Tech II PRINCIPLES OF PROGRAMMING LANGUAGES Previous Question Paper (July/August - 2021 - R13)
Answer any five questions
All questions carry equal marks
Main
Explain about formal methods of describing syntax.
Answer
Formal methods of describing syntax are essential in programming language design to provide a precise, unambiguous definition of the language's structure. These methods allow for the systematic generation and recognition of valid programs.
The primary formal methods include:
- Backus-Naur Form (BNF): Developed by John Backus and Peter Naur, this is the most widely used notation for context-free grammars. It uses a set of production rules where a non-terminal symbol is defined by a sequence of terminals and non-terminals. The symbol
::=represents 'is defined as', and|denotes an alternative. - Extended Backus-Naur Form (EBNF): This is an enhancement of BNF that introduces shorthand notations to improve readability and conciseness. It includes brackets
[]for optional items, braces{}for repetition (zero or more times), and parentheses()for grouping alternatives. - Syntax Graphs (Syntax Diagrams): These provide a visual representation of syntax rules. They use directed graphs where rectangles represent non-terminals, circles or ovals represent terminals, and arrows indicate the flow of valid sequences. They are often used in language manuals for easier human comprehension.
- Attribute Grammars: These extend context-free grammars by adding attributes to the symbols of the grammar. These attributes are used to describe context-sensitive aspects of a language, such as type checking, scope rules, and declaration requirements, which cannot be captured by standard BNF.
- Regular Expressions: Used primarily for defining the lexical structure (tokens) of a language. They describe patterns using operators like concatenation, union (
|), and the Kleene star (*) for repetition.
These formal methods ensure that language processors, such as compilers and interpreters, can reliably parse source code by validating it against the defined grammatical rules.
Mention and explain about various control structures with a suitable example for each.
Answer
Control structures are fundamental constructs in programming languages that dictate the flow of execution of statements. They are broadly categorized into three types: selection (conditional), iteration (looping), and unconditional branching.
1. Selection Control Structures: These allow a program to choose between different paths of execution based on a condition.
- if-else: Executes a block of code if a condition is true, and an optional block if false. Example:
if (x > 0) { print("Positive"); } else { print("Non-positive"); } - switch/case: Selects one block of code to execute from multiple options based on the value of an expression. Example:
switch(day) { case 1: print("Monday"); break; default: print("Other"); }
2. Iteration Control Structures (Loops): These enable the repeated execution of a block of code as long as a specified condition remains true.
- while loop: Checks the condition before executing the loop body. Example:
while (i < 5) { print(i); i++; } - for loop: Combines initialization, condition, and increment/decrement in a single line for controlled iteration. Example:
for (int i = 0; i < 5; i++) { print(i); } - do-while loop: Executes the body at least once before checking the condition. Example:
do { print(i); } while (i < 0);
3. Unconditional Branching: These structures alter the flow of control without requiring a condition.
- goto: Transfers control directly to a labeled statement within the same function. While powerful, its use is generally discouraged as it can lead to "spaghetti code" that is difficult to maintain. Example:
goto label1; ... label1: print("Jumped here"); - break and continue: Used within loops to exit the loop prematurely (break) or skip the current iteration and proceed to the next (continue). Example:
for (int i = 0; i < 10; i++) { if (i == 5) break; print(i); }
Explain about design issues of subprograms.
Answer
Sign in to view the complete answer paper.
Explain about scope and lifetime of variable.
Answer
Sign in to view the complete answer paper.
Explain about Java threads with a suitable example.
Answer
Sign in to view the complete answer paper.
Write short notes on LISP.
Answer
Sign in to view the complete answer paper.
Distinguish between procedural and data abstraction giving examples.
Answer
Sign in to view the complete answer paper.
Mention and explain about programming paradigms.
Answer
Sign in to view the complete answer paper.
Explain: a) type checking and b) type compatibility with an example each.
Answer
Sign in to view the complete answer paper.
Explain about parameter passing methods with an example.
Answer
Sign in to view the complete answer paper.