0% found this document useful (0 votes)
15 views22 pages

Sample Mid1

Uploaded by

ismailovich1904
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views22 pages

Sample Mid1

Uploaded by

ismailovich1904
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

MIDTERM

SAMPLE
QUESTIONS
MIDTERM EXAM
 Scheduled on campus
 Time and location not finalized

 Content required
 Topics 1 – 6 with reference material from the
book (up to datatypes II)
 One hour duration
 Exam Structure
 10 multiple choice questions

 4 short answer questions

 4 problems
EXAM MATERIAL
 Write/analyse BNF, Convert to EBNF, build a parse tree based on
a grammar and a statement, prove grammar is ambiguous
 Write denotational/operational/axiomatic semantics derivations
and rules of given statement(s)
 Static vs dynamic scope binding, (value of variable based on
given code)
 2d array element indexing
 All other material can come in form of MCQ and SAQ
MCQ – Q1
 The lifetime of a variable is the time during which
A. The variable is bound to a specific type
B. The variable is bound to a specific name
C. The variable is bound to a specific value
D. None of the above
MCQ – Q1
 The lifetime of a variable is the time during which
A. The variable is bound to a specific type
B. The variable is bound to a specific name
C. The variable is bound to a specific value
D. None of the above
MCQ – Q2
 A binding is dynamic if
A. It occurs before run time and remains unchanged throughout
program execution
B. It occurs before run time and changes throughout program
execution
C. It occurs during runtime and remains unchanged throughout
program execution
D. It occurs during runtime and changes through program execution
MCQ – Q2
 A binding is dynamic if
A. It occurs before run time and remains unchanged throughout
program execution
B. It occurs before run time and changes throughout program
execution
C. It occurs during runtime and remains unchanged throughout
program execution
D. It occurs during runtime and changes through program execution
MCQ - Q3
 Explicit Heap Dynamic allocation is used when:
A. The developer wants to allocate an object during runtime
B. The local variables of a function are allocated
C. An array whose length is known during a block activation
D. A type is bound to a variable during execution
MCQ - Q3
 Explicit Heap Dynamic allocation is used when:
A. The developer wants to allocate an object during runtime
B. The local variables of a function are allocated
C. An array whose length is known during a block activation
D. A type is bound to a variable during execution
MCQ – Q4
 A grammar is said to be ambiguous if:
A. Two production rules have the same meaning
B. There are two ways of writing a given production rule
C. A string in the language described by the grammar has two parse
trees.
D. There are two non-terminals on the left-hand side of the production
E. None of the above.
MCQ – Q4
 A grammar is said to be ambiguous if:
A. Two production rules have the same meaning
B. There are two ways of writing a given production rule
C. A string in the language described by the grammar has two parse
trees.
D. There are two non-terminals on the left-hand side of the production
E. None of the above.
SAQ – Q1
 State True or False. If False correct.
a) The designers of Java traded reliability for execution efficiency,
so Java programs execute faster than semantically equivalent C
programs ( )
b) ADA supports Jagged arrays, where row lengths do not have to
be the same ( )
c) Java is a strongly typed programming language ( )
SAQ – Q1
 State True or False. If False correct.
a) The designers of Java traded reliability for execution efficiency,
so Java programs execute faster slower than semantically
equivalent C programs
(F)
b) ADA Java supports Jagged arrays, where row lengths do not
have to be the same ( F )
c) Java is a strongly typed programming language ( T )
SAQ – Q2
 Consider the following function
void foo(int x, int y, int z){
int a, b, c;
a = x + 1;
b = y + 2;
c = z + 3;
}
When foo finishes, its local variables (a, b and c) no longer exist. Why don’t we have to
manually deallocate the space that they occupy?

Because a, b and c are variables whose scope or lifetime is within


the block. When foo finishes, its allocated memory is
automatically deallocated.
PROBLEM
PROBLEM
<expr> := [‘-’] <num>
<num> := <digits> [‘.’ <digits>]
<digits> := <digit>{<digit>}
<digit> := ‘0’|’1’|’2’|’3’|’4’|
’5’|’6’|’7’|’8’|’9’

Example statement: - 12.5

<expr> => - <num>


=> - <digits>.<digits>
=> - <digit><digit>.<digit>
=> - 1<digit>.<digit>
=> -12.<digit>
=> -12.5
PROBLEM
(a)

PROBLEM ‘1’’+’’3’ => 1 ‘+’ ‘3’


=> 1 ‘+’ 3
(Rules 1 and 7)
(Rules 1 and 10)
=> 1 + 3 (Rule 3)
=> 4

‘(‘‘1’’+’’3’’)’ => ‘(‘4’)’ (Rule 13)


=> 4 (Rule 6)

‘2’’*’ ‘(‘‘1’’+’’3’’)’ => ‘2’’*’4 (Rule 9)


=> 2 ‘*’ 4 (Rule 12)
=> 2 * 4 (Rule 5)
=> 8

(b)
𝑀𝑑𝑒𝑐 ′1′ = 1
𝑀𝑑𝑒𝑐 𝑛𝑢𝑚𝑏𝑒𝑟 ′3′ = 10 ∗ 𝑀𝑑𝑒𝑐 (𝑛𝑢𝑚𝑏𝑒𝑟) + 3
𝑀𝑑𝑒𝑐 𝑛𝑢𝑚𝑏𝑒𝑟 ′2′ = 10 ∗ 𝑀𝑑𝑒𝑐 (𝑛𝑢𝑚𝑏𝑒𝑟) + 2

Derivation:
𝑀𝑑𝑒𝑐 (‘1’’2’’3’)= 10 ∗ 𝑀𝑑𝑒𝑐 (‘1’’2’) + 3
= 10 ∗ 10 ∗ 𝑀𝑑𝑒𝑐 ‘1’ + 2 + 3
= 10 ∗ 10 ∗ 1 + 2 + 3
= 10 ∗ 12 + 3 = 120 + 3 = 123
PROBLEM

Assuming static scoping,


PROBLEM

Assuming static scoping,


PROBLEM
PROBLEM

Location(arr[i,j]) = address of arr[0, 0] + ((i * n) + j ) * element_size

Location(A[6,7]) = 3000 + ((6 * 20) + 7 ) * 4 = 3,508

You might also like