You are on page 1of 44

1) Defination Alphabet, strings, empty string, length of string, power of an alphabet,

concatenation of string, language. 4-6M ??


2) Difference between NFA and DFA and epsilon-NFA .

3) Define DFA
4)Define NFA

4) Difference between compiler and Interpreter


5) Language processing system. Explain ?
6) Structure of a compiler / phases of compiler ?
7) Write down the output of each phase for the expression “position = initial +rate*60”
8) Differentiate between distinguishable and indistinguishable states with examples.

9) What is language processor ?


Module -2

1) Define Regular Expression. (3M)


2) Kleen theorem ?
3) Define token,pattern,lexeme

4) Two – way buffering techinugue..


5) Lexical errors
6) Input buffering.

7) Define tokens,,
8)Role of lexical analyzer ?
9 QUESTION..
10_INPUT BUFFERING EXPLAIN ??
11 question-error recovery technique for parser
MODULE 3
1) DEFINE CFG
2) DEFINE AMIGUITY?

3) CONSIDER THE GRAMMAR –


4) Question

5) Define left recursion grammar.


6) Role of Parser and error recovery strategies.
Module 4

1 Define PDA.

2) sslr parsing solve problems …


3) differentiate
4) question
5) question..
6 question

7 question
8 turning machine
9)short notes
10 issues of code generator
11 recursive language
12) short notes -

a) Multitape Turing machine:


A multitape Turing machine is a variant of the traditional Turing machine with
multiple tapes instead of a single tape. Each tape has its own read/write head
and can move independently. This model allows for parallel processing and
can be more efficient for certain computations. For example, a multitape
Turing machine can easily perform tasks like copying information from one
tape to another simultaneously.
b) Halting problem in TM:
The halting problem in Turing machines refers to the question of whether a
given Turing machine will halt (stop) or run indefinitely on a specific input.
Alan Turing proved that there is no algorithm that can determine, for all
possible inputs and Turing machines, whether a given Turing machine will halt
or not. For example, consider a Turing machine that loops infinitely if a specific
condition is met; determining whether this machine will halt is undecidable.
c) Post correspondence problem:
The Post correspondence problem is a classic undecidable problem in
computer science. Given a set of tiles with strings on the top and bottom, the
objective is to arrange these tiles in a sequence such that the concatenation of
the strings on the top matches the concatenation of the strings on the bottom.
For instance, given tiles {ab, a} and {b, ba}, solving the Post correspondence
problem involves finding a sequence that matches the top and bottom strings.
d) Recursive languages:
Recursive languages, also known as decidable languages, are languages for
which there exists a Turing machine that can determine whether a given input
string belongs to the language or not. These languages have algorithms that
always halt and provide a definitive answer. An example of a recursive
language is the set of even-length strings over the alphabet {0, 1}.
e) Universal Turing machine:
A universal Turing machine is a theoretical machine that can simulate any
other Turing machine given the appropriate input. It serves as a fundamental
concept in computability theory by demonstrating that a single machine can
execute the functions of any other Turing machine. For example, a universal
Turing machine can simulate a Turing machine that computes the Fibonacci
sequence or any other algorithm.
f) Non-deterministic TM:
A non-deterministic Turing machine is a theoretical model of computation
where at each step, the machine can have multiple possible transitions based
on the current state and input symbol. This model allows for branching paths
and can explore multiple possibilities simultaneously. An example is a non-
deterministic Turing machine that guesses the correct path to reach the
accepting state.
g) Decidable language:
A decidable language, also known as a recursive language, is a language for
which there exists an algorithm that can determine whether a given input
string belongs to the language or not. Decidable languages have Turing
machines that always halt and provide a definitive answer. An example of a
decidable language is the set of all binary strings with an equal number of 0s
and 1s.
13) What is Syntax Directed Definition?
Write a note on universal TM and show that it simulates a computer.
15TH QUESTION
Explain extended TM(Multi-tape TM and Non-deterministic TM)
Extended Turing Machines are variations of the traditional Turing Machine that introduce
additional features to enhance computational capabilities. Two common types of extended
Turing Machines are Multi-tape Turing Machines and Non-deterministic Turing Machines.

1. Multi-tape Turing Machine (MTM):


o Description: In a Multi-tape Turing Machine, instead of a single tape, the
machine has multiple tapes that run in parallel. Each tape has its own read/write
head and can move independently.
o Advantages:
▪ Parallel Processing: MTMs can perform multiple operations
simultaneously on different tapes, potentially speeding up computations.
▪ Simplified Tasks: Certain tasks, such as copying information between
tapes, can be more efficiently handled by MTMs compared to single-tape
machines.
o Operations:
▪ Each tape head can read, write, or move independently based on the
machine's state and input symbols.
▪ The machine transitions between states based on the combined input
from all tape heads.

2.Non-deterministic Turing Machine (NTM):

o Description: In a Non-deterministic Turing Machine, at each step, the machine


can have multiple possible transitions based on the current state and input
symbol. It can explore multiple paths simultaneously.
o Advantages:
▪ Exploration of Possibilities: NTMs can explore different computation paths
in parallel, potentially leading to more efficient solutions.
▪ Problem Solving: NTMs are useful for solving problems that involve
guessing or exploring multiple solutions.
o Operations:
▪ At each step, the machine can choose from multiple possible transitions
based on the current state and input symbol.
▪ If there are multiple paths, the machine can split into multiple branches
and explore each possibility concurrently.

Comparison:

• Multi-tape TM vs. Non-deterministic TM:


o Multi-tape TM: Focuses on parallel processing by using multiple tapes to
perform operations simultaneously.
o Non-deterministic TM: Focuses on exploring multiple computation paths
concurrently to potentially find more efficient solutions.
Overall, Multi-tape Turing Machines and Non-deterministic Turing Machines are
extensions of the traditional Turing Machine that introduce additional features to enhance
computational capabilities, such as parallel processing and exploration of multiple
computation paths. These extended Turing Machines play a significant role in theoretical
computer science and computability theory by expanding the scope of problems that can
be efficiently solved.

16TH QUESTION
.Explain synthesized attribute, inherited attribute, S-attributed definition and L-attributed
definition with example for each.
Attribute Grammars: Attribute Grammars are formalisms used to define attributes associated
with the nodes of a syntax tree in a programming language compiler. These attributes can be
classified into two main categories: synthesized attributes and inherited attributes. Additionally,
S-attributed and L-attributed definitions are special cases of attribute grammars that impose
restrictions on how attributes are computed and propagated.
1. Synthesized Attribute:
o Definition: Synthesized attributes are attributes associated with a node in the
syntax tree that are computed solely from attributes of its children nodes.
o Example: In a simple arithmetic expression syntax tree, the attribute value of a
node representing an arithmetic operation can be a synthesized attribute
computed from the value attributes of its child nodes representing operands.
2. Inherited Attribute:
o Definition: Inherited attributes are attributes associated with a node in the syntax
tree that are passed down from its parent node or other ancestor nodes.
o Example: Consider a syntax tree representing a programming language function.
The attribute returnType of a function node can be an inherited attribute
passed down from the parent node representing the function declaration.
3. S-Attributed Definition:
o Definition: An attribute grammar is said to be S-attributed if every attribute is
synthesized and can be evaluated in a single depth-first traversal of the syntax
tree.
o Example: In an S-attributed grammar for a simple arithmetic expression, the
attribute type of a node representing an expression can be synthesized from
the type attributes of its child nodes representing operands.
4. L-Attributed Definition:
o Definition: An attribute grammar is said to be L-attributed if it is S-attributed and
allows inherited attributes to be used in the definition of synthesized attributes.
o Example: In an L-attributed grammar for a programming language, the
attribute scope of a node representing a block can be inherited from the parent
node representing the enclosing scope and used to synthesize attributes such
as variableType within the block.

Summary:

• Synthesized attributes are computed from child nodes, while inherited attributes are
passed down from parent or ancestor nodes.
• S-attributed grammars allow only synthesized attributes and can be evaluated in a single
traversal.
• L-attributed grammars extend S-attributed grammars by allowing inherited attributes to
influence synthesized attributes, enabling more complex attribute computations.

These concepts play a crucial role in the design and implementation of compilers and language
processors, facilitating the analysis and transformation of programs during compilation.

17TH QUESTION
What is three address code? Explain different ways of representing three
address codes with examples.
Three Address Code (TAC): Three Address Code is an intermediate representation used in
compilers to break down complex expressions into simpler operations with at most three
operands. Each instruction in TAC typically contains three addresses: two for operands and one
for the result. TAC simplifies code generation and optimization by providing a structured format
for expressing computations.
Different Ways of Representing Three Address Codes:
1. Quadruples:
o In quadruples representation, each TAC instruction is represented by a tuple of
four fields: operator, operand1, operand2, and result.
o Example:
o 1. ADD, A, B, T1
o 2. SUB, T1, C, T2
o 3. MUL, T2, D, T3
2. Triples:
o Triples representation extends quadruples by grouping related instructions into
triples, where each instruction has three fields: operator, operand1, and operand2.
o Example:
o 1. ADD, A, B
o 2. SUB, T1, C
o 3. MUL, T2, D
3. Indirect Triples:
o Indirect triples representation uses pointers to operands instead of actual
operand values, reducing redundancy in the code.
o Example:
o 1. ADD, &A, &B
o 2. SUB, &T1, &C
o 3. MUL, &T2, &D
4. DAG (Directed Acyclic Graph):
o DAG representation optimizes common subexpressions by creating a directed
acyclic graph where nodes represent expressions and edges represent
dependencies.
o Example:
o +
o / \
o A B
In this DAG, the expression "A + B" is represented with nodes for A, B, and the
addition operation.

5. Syntax Trees:
o Syntax trees represent TAC as a tree structure where internal nodes represent
operators and leaf nodes represent operands.
o Example:
o +
o / \
o A *
o / \
o B C

In this syntax tree, the expression "A + (B * C)" is represented hierarchically.

Each representation of TAC has its advantages and use cases in compiler design and
optimization. The choice of representation depends on the specific requirements of the compiler
and the optimizations to be applied during code generation.

You might also like