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
Q

What will be the output of the following Python code?

> > > list1 = [1, 3]
list2 = list1
list1[0] = 4
print(list2)

A

[4,3]

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

What will be the output of the following Python code?

x = ‘abcd’
for i in range(len(x)):
print(i)

A

0 1 2 3

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

What will be the output of the following Python expression?

> > > from math import *
ceil(4.576)

A

5

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

What will be the output of the following Python code?

> > > example = “snow world”
example[3] = ‘s’
print(example)

A

Error

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

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

A

String containing at least two 0’s

29
Q

Regular expressions are closed under ____________
Intersection
Union
Kleene Star
All the above

A

All the above

30
Q

The context free grammar S → SS | 0S1 | 1S0 | ɛ generates _________

A

Equal number of 0s and 1s

31
Q

Which of these does not belong to CFG (Context free grammar)?

A

End symbol

32
Q

Which among the following is the root of the parse tree?

A

Starting variable / Starting symbol S

33
Q

This parse tree corresponds to the production rule:
P
0 P 0

         1             P         1
                        E
A

P->0110 over {0,1}*

34
Q

A grammar with more than one parse tree is called unambiguous grammar.

A

False

35
Q

A digit, when used in the CFG notation, will always be used as a terminal.
True or false

A

true

36
Q

A lexical analyzer reads the source code character by character.
True of False

A

True

37
Q

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

A

None of the above

38
Q

A compiler accepts a program written in a high-level language and produces an object program.
True or false

A

True

39
Q

Intermediate code generator receives input from its predecessor phase, semantic analyzer, in the form of an annotated syntax tree.

A

True

40
Q

Syntax Analyser takes groups of tokens of the source program into grammatical production.

A

True

41
Q

What is the purpose of the symbol table in a compiler?

A

Tracking variable information

42
Q

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.

A

Loop unrolling

43
Q

Compilers translate code to machine language, while interpreters execute code directly.
True or false

A

True

44
Q

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

A

45
Q

Consider the regular expression (a | b)b+b

What is the simplest regular expression that denotes the same language?

A

(a|b)*b

46
Q

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

A

True

47
Q

A set of symbols used in the definition of a language is called…………….

A

alphabet

48
Q

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 _____________

A

unambiguous grammar

49
Q

A specification of the order in which operations should be performed when two operators of the same precedence are adjacent.

A

Associativity

50
Q

The phase of a compiler in which executable output code is generated from intermediate code.

A

code generation

51
Q

A grammar in which the left hand side of each production consists of a single non-terminal symbol

A

Context-free grammar

52
Q

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

A

True

53
Q

A symbol that is used as the name of a variable, type, constant, procedure etc.

A

identifier

54
Q

Zero or more occurrences of a grammar item indicated by a superscript * is called ______

A

Kleene closure

55
Q

A symbol that names a phrase in a grammar is called a nonterminal symbol.
True or False

A

True

56
Q

What does the os.getcwd() function do in Python?

A

Gets the current working directory

57
Q

Which module is used for network programming in Python?

A

socket

58
Q

Which function is used to create a new thread in Python using the _thread module?

A

_thread.start_new_thread()

59
Q

Which of the following is not a valid method for reading data from a file in Python?

A

readfile()

60
Q

What is the purpose of the __init__ method in Python classes?

A

Initialize a new object

61
Q

The len() function is used to find the length of a dictionary in Python.
True or False

A

False

62
Q

All variables in Python must be explicitly declared with a data type.
True or False

A

False

63
Q

phrase = “Hello, World!”
print(phrase[7:])

What is the output of this code?

A

World!

64
Q

numbers = [1, 2, 3, 4, 5]
print(numbers[-2])

What is the output of this code?

A

4

65
Q

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?

A

[10, 20, 30, 4]

66
Q

In Python, what happens if you try to add a string and an integer without converting them?

A

Raises a TypeError

67
Q

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?

A

continue

68
Q

Which of the following loops is used for definite iteration in Python?

A

for

69
Q

numbers = list(range(2, 10, 2))
What is the output of print(numbers)?

A

[2, 4, 6, 8]

70
Q

try:
result = 10 / 0
except ZeroDivisionError:
result = “Error”
print(result)

What is the output of this code?

A

Error