Final Flashcards

1
Q

The primary purpose of the symbol table during lexical analysis is to store information about identifiers such as variable names
True of False

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Strength reduction is a compiler optimization technique that involves replacing less expensive operations with expensive ones.
True or False

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A deterministic finite automaton M is a 5-tuple, (Q, Σ, δ, q0, F).
True or False

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In short, the parse tree is generated by the syntax analyzer.
True or False

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

True or False
In Python structure, a statement indentation does not matter

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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 _______

A

22

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the socket.AF_INET parameter represent in the socket.socket() constructor?

A

Socket address family for IPv4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

try:
num = int(“abc”)
except ValueError:
num = 0
finally:
num += 1
print(num)

What is the output of this code?

A

2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which module is used for network programming in Python?

A

socket

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

All variables in Python must be explicitly declared with a data type

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Convert all characters to upper case

A

str.upper()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Add an element to the end of the list

A

list.append()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Opens a file for reading or writing

A

open()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Reading data from a file in python

A

readline()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Set the maximum number of queued connections

A

socket.listen()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

In a DFA state diagram, circles represent states, and arrows (transitions) indicate the transitions between states based on input symbols.
True or false

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Optimization of a program that works within a single basic block of code is called .

A

local transformation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Which gcc compiler optimization flag optimizes the generated code for both size and speed?

A

-O2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

The grammar of the programming (i.e., grammatical errors) is checked at phase of the compiler

A

syntax analysis

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Which of the following is the correct extension of the Python file?

A

.py

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is the order of precedence in python?

A

Parentheses, Exponential, Multiplication, Division, Addition, Subtraction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What will be the output of the following Python function?

max(max(True,-3,-4), 2 ,0 )

A

2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

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))

A

Error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
What will be the output of the following Python code? >>>list1 = [1, 3] >>>list2 = list1 >>>list1[0] = 4 >>>print(list2)
[4,3]
25
What will be the output of the following Python code? x = 'abcd' for i in range(len(x)): print(i)
0 1 2 3
26
What will be the output of the following Python expression? >>>from math import * >>>ceil(4.576)
5
27
What will be the output of the following Python code? >>>example = "snow world" >>>example[3] = 's' >>>print(example)
Error
28
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
29
Regular expressions are closed under ____________ Intersection Union Kleene Star All the above
All the above
30
The context free grammar S → SS | 0S1 | 1S0 | ɛ generates _________
Equal number of 0s and 1s
31
Which of these does not belong to CFG (Context free grammar)?
End symbol
32
Which among the following is the root of the parse tree?
Starting variable / Starting symbol S
33
This parse tree corresponds to the production rule: P 0 P 0 1 P 1 E
P->0110 over {0,1}*
34
A grammar with more than one parse tree is called unambiguous grammar.
False
35
A digit, when used in the CFG notation, will always be used as a terminal. True or false
true
36
A lexical analyzer reads the source code character by character. True of False
True
37
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
38
A compiler accepts a program written in a high-level language and produces an object program. True or false
True
39
Intermediate code generator receives input from its predecessor phase, semantic analyzer, in the form of an annotated syntax tree.
True
40
Syntax Analyser takes groups of tokens of the source program into grammatical production.
True
41
What is the purpose of the symbol table in a compiler?
Tracking variable information
42
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
43
Compilers translate code to machine language, while interpreters execute code directly. True or false
True
44
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
45
Consider the regular expression (a | b)*b+b* What is the simplest regular expression that denotes the same language?
(a|b)*b
46
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
47
A set of symbols used in the definition of a language is called................
alphabet
48
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
49
A specification of the order in which operations should be performed when two operators of the same precedence are adjacent.
Associativity
50
The phase of a compiler in which executable output code is generated from intermediate code.
code generation
51
A grammar in which the left hand side of each production consists of a single non-terminal symbol
Context-free grammar
52
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
53
A symbol that is used as the name of a variable, type, constant, procedure etc.
identifier
54
Zero or more occurrences of a grammar item indicated by a superscript * is called ______
Kleene closure
55
A symbol that names a phrase in a grammar is called a nonterminal symbol. True or False
True
56
What does the os.getcwd() function do in Python?
Gets the current working directory
57
Which module is used for network programming in Python?
socket
58
Which function is used to create a new thread in Python using the _thread module?
_thread.start_new_thread()
59
Which of the following is not a valid method for reading data from a file in Python?
readfile()
60
What is the purpose of the __init__ method in Python classes?
Initialize a new object
61
The len() function is used to find the length of a dictionary in Python. True or False
False
62
All variables in Python must be explicitly declared with a data type. True or False
False
63
phrase = "Hello, World!" print(phrase[7:]) What is the output of this code?
World!
64
numbers = [1, 2, 3, 4, 5] print(numbers[-2]) What is the output of this code?
4
65
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]
66
In Python, what happens if you try to add a string and an integer without converting them?
Raises a TypeError
67
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
68
Which of the following loops is used for definite iteration in Python?
for
69
numbers = list(range(2, 10, 2)) What is the output of print(numbers)?
[2, 4, 6, 8]
70
try: result = 10 / 0 except ZeroDivisionError: result = "Error" print(result) What is the output of this code?
Error