Final Flashcards
The primary purpose of the symbol table during lexical analysis is to store information about identifiers such as variable names
True of False
True
Regular grammars are a type of formal grammar that generate regular languages. They have production rules of the form A → αB or A → α, where A and B are non-terminal symbols, and α is a string of terminal symbols.
True of False
True
Strength reduction is a compiler optimization technique that involves replacing less expensive operations with expensive ones.
True or False
False
A deterministic finite automaton M is a 5-tuple, (Q, Σ, δ, q0, F).
True or False
True
In short, the parse tree is generated by the syntax analyzer.
True or False
True
True or False
In Python structure, a statement indentation does not matter
False
def calculate_sum(a, b=5, c=10):
return a + b + c
result = calculate_sum(2)
The value of result after executing the above code is _______
22
What does the socket.AF_INET parameter represent in the socket.socket() constructor?
Socket address family for IPv4
try:
num = int(“abc”)
except ValueError:
num = 0
finally:
num += 1
print(num)
What is the output of this code?
2
Which module is used for network programming in Python?
socket
All variables in Python must be explicitly declared with a data type
False
Convert all characters to upper case
str.upper()
Add an element to the end of the list
list.append()
Opens a file for reading or writing
open()
Reading data from a file in python
readline()
Set the maximum number of queued connections
socket.listen()
In a DFA state diagram, circles represent states, and arrows (transitions) indicate the transitions between states based on input symbols.
True or false
True
Optimization of a program that works within a single basic block of code is called .
local transformation
Which gcc compiler optimization flag optimizes the generated code for both size and speed?
-O2
The grammar of the programming (i.e., grammatical errors) is checked at phase of the compiler
syntax analysis
Which of the following is the correct extension of the Python file?
.py
What is the order of precedence in python?
Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
What will be the output of the following Python function?
max(max(True,-3,-4), 2 ,0 )
2
What will be the output of the following Python code snippet?
def foo(x):
x[0] = [‘def’]
x[1] = [‘abc’]
return id(x)
q = [‘abc’, ‘def’]
print(id(q) == foo(q))
Error
What will be the output of the following Python code?
> > > list1 = [1, 3]
list2 = list1
list1[0] = 4
print(list2)
[4,3]
What will be the output of the following Python code?
x = ‘abcd’
for i in range(len(x)):
print(i)
0 1 2 3
What will be the output of the following Python expression?
> > > from math import *
ceil(4.576)
5
What will be the output of the following Python code?
> > > example = “snow world”
example[3] = ‘s’
print(example)
Error
Which one of the following languages over the alphabet {0,1} is described by the regular expression?
(0+1)0(0+1)0(0+1)*
String containing at least two 0’s
Regular expressions are closed under ____________
Intersection
Union
Kleene Star
All the above
All the above
The context free grammar S → SS | 0S1 | 1S0 | ɛ generates _________
Equal number of 0s and 1s
Which of these does not belong to CFG (Context free grammar)?
End symbol
Which among the following is the root of the parse tree?
Starting variable / Starting symbol S
This parse tree corresponds to the production rule:
P
0 P 0
1 P 1 E
P->0110 over {0,1}*
A grammar with more than one parse tree is called unambiguous grammar.
False
A digit, when used in the CFG notation, will always be used as a terminal.
True or false
true
A lexical analyzer reads the source code character by character.
True of False
True
A programmer, writes a program to multiply two numbers instead of dividing them by mistake, this error can be detected by ____________
Compiler only
Compiler and Interpreter
Interpreter only
None of the above
None of the above
A compiler accepts a program written in a high-level language and produces an object program.
True or false
True
Intermediate code generator receives input from its predecessor phase, semantic analyzer, in the form of an annotated syntax tree.
True
Syntax Analyser takes groups of tokens of the source program into grammatical production.
True
What is the purpose of the symbol table in a compiler?
Tracking variable information
In a compiler, transforming from
for (int i = 0; i < 4; ++i) {
array[i] = array[i] * 2;
}
to
for (int i = 0; i < 4; i += 2) {
array[i] = array[i] * 2;
array[i + 1] = array[i + 1] * 2;
}
is a form of ___________________________ optimization.
Loop unrolling
Compilers translate code to machine language, while interpreters execute code directly.
True or false
True
Let’s consider a simple grammar and generate parse trees for a sample sentence. The grammar is:
Unknown node type: br
S→ if E then S else S
Unknown node type: br
S→identifier := E
E→identifier
E→number
E→E+E
Now, parsing the sentence “if x then y := 2 else y := 3”: should yield a unambiguous parse tree. Choose the unambiguous PT from the options.
A)
S \_\_\_|\_\_\_\_\_ | | | if S S | | E E | | x y / \ := := / \ E E / \ 2 3
B)
S \_\_\_\_|\_\_\_\_ | | | if S S | / \ E := := | | | x E E | / \ \+ 2 3 / \ E E | | y y
C)
S \_\_\_|\_\_\_\_\_\_ | | | if S S | | \ E E E | | | x := := / \ E E / \ 2 3
D)
S \_\_\_|\_\_\_\_\_\_ | | | if S S | | \ E E E | | | x := := / \ E E \ 3
A
Consider the regular expression (a | b)b+b
What is the simplest regular expression that denotes the same language?
(a|b)*b
A state of the finite automaton in which the input string is accepted as being a member of the language recognized by the automaton is called the accepted state.
True or False
True
A set of symbols used in the definition of a language is called…………….
alphabet
A grammar that allows some sentence or string to be generated or parsed in more than one way i.e. with distinct parse trees) is called _____________
unambiguous grammar
A specification of the order in which operations should be performed when two operators of the same precedence are adjacent.
Associativity
The phase of a compiler in which executable output code is generated from intermediate code.
code generation
A grammar in which the left hand side of each production consists of a single non-terminal symbol
Context-free grammar
A list of steps that shows how a sentence in a language is derived from a grammar by application of grammar rules is called derivation
True
A symbol that is used as the name of a variable, type, constant, procedure etc.
identifier
Zero or more occurrences of a grammar item indicated by a superscript * is called ______
Kleene closure
A symbol that names a phrase in a grammar is called a nonterminal symbol.
True or False
True
What does the os.getcwd() function do in Python?
Gets the current working directory
Which module is used for network programming in Python?
socket
Which function is used to create a new thread in Python using the _thread module?
_thread.start_new_thread()
Which of the following is not a valid method for reading data from a file in Python?
readfile()
What is the purpose of the __init__ method in Python classes?
Initialize a new object
The len() function is used to find the length of a dictionary in Python.
True or False
False
All variables in Python must be explicitly declared with a data type.
True or False
False
phrase = “Hello, World!”
print(phrase[7:])
What is the output of this code?
World!
numbers = [1, 2, 3, 4, 5]
print(numbers[-2])
What is the output of this code?
4
def modify_list(my_list):
my_list.append(4)
my_list = [1, 2, 3]
numbers = [10, 20, 30]
modify_list(numbers)
print(numbers)
What is the output of this code?
[10, 20, 30, 4]
In Python, what happens if you try to add a string and an integer without converting them?
Raises a TypeError
Which of the following statements is used to skip the rest of the code in the current iteration and jump to the next iteration in a loop?
continue
Which of the following loops is used for definite iteration in Python?
for
numbers = list(range(2, 10, 2))
What is the output of print(numbers)?
[2, 4, 6, 8]
try:
result = 10 / 0
except ZeroDivisionError:
result = “Error”
print(result)
What is the output of this code?
Error