Preview

Concepts of Programming Languages

Good Essays
Open Document
Open Document
635 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Concepts of Programming Languages
1.Compute the weakest precondition for each of the following assignment statements and postconditions: (p. 165 Problem set 19, 20)

(a)a = 2 * (b - 1) – 1 {a > 0}

(b)a = a + 2 * b – 1 { a > 1}

(c)a = 2 * b + 1;

b = a – 3

{b < 0}

(d)a = 3 * ( 2 * b + a);

b = 2 * a – 1

{b > 5}

(a) 2* (b-1) - 1 > 0

2* (b - 1) > 1

2b - 2 > 1

2b > 3

{b > 1.5}

(b)a+2*b-1 > 1

a+2*b>2

{a > 2-2*b}

(c)a-3 < 0

a3

2*b+a>1

{2*b>1-a}

2.Write a denotational semantics mapping function for the following statements: (p. 165 Problem set 21)

(a) Java for

(b) C do-while

(a) = for (, , ) {} = = = = > | < | >=| 0}

count = n;

sum = 0;

while count 0 do

sum = sum + count;

count = count – 1;

end

{sum = 1 + 2 + … + n}

part of the invariant can be:

sum = (count+1) + (count+2) + ... + (n-1) + n, let's call this I

Thus we have I and {n > 0}, and {count 0}, which reduce to I and {count>0}

Because in Loop we have (count = count - 1), and {count > 0}, thus the precondition before the loop is {count >= 1}

Using this precondition for the first assignment in Loop, we have sum = sum + count {sum = count + (count + 1) + ... + n and count >= 1}

The precondition for this is sum = 1 + 2 + ... + n. thus we proved that the post-condition for this program is correct.

4.Dynamic type binding is closely related to implicit heap-dynamic variables. Explain this relationship. (p. 241 Problem set 5)

In languages featuring dynamic binding, most of them supports virtual memory management, in which the virtual machine determines the variable type, allocated memory space and de-allocate them after the varable is no longer needed. These are implicit heap-dynamic variables where users do not have to worry about what type of variables they are going to use, and save a lot of programer time for de-allocating un-used memory spaces.

5.Consider the following skeletal C

You May Also Find These Documents Helpful

  • Satisfactory Essays

    b. Ch. 2: RQs 1 – 9, 10, 11 and Problems #1 and 2 (include all attributes).…

    • 2322 Words
    • 10 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Rub

    • 957 Words
    • 5 Pages

    6. Skip to Page 381 Key Issue 3 and read about site and situation. Then read the Glossary’s definition for each. Which definition, site or situation’s, changes the most?…

    • 957 Words
    • 5 Pages
    Satisfactory Essays
  • Powerful Essays

    Exam on Algorithms

    • 1238 Words
    • 5 Pages

    The following algorithm is to be applied to the positive integers from 1 to 12.…

    • 1238 Words
    • 5 Pages
    Powerful Essays
  • Satisfactory Essays

    Question 1 – Ideally your answer should be based around the information provided on page 2 of the course materials.…

    • 379 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Mid Term 1 Solution

    • 534 Words
    • 3 Pages

    Answer: n T (n) = 2T ( n ) + log n 2 2 n = 4T ( n ) + logn n + log n 4 2 2 2 n = 4T ( n ) + log nn−1 + log n 4 2 2 = ... ∑log2 n 1 = nT (1) + n i=1 i ∑n Since i=1 1 → ln n, T (n) ∈ Θ(n log log n) i…

    • 534 Words
    • 3 Pages
    Satisfactory Essays
  • Better Essays

    Formal definition (symbols): f(n) = O(g(n)) if $ c, n0 | f(n) <= c * f(n) when n >= n0.…

    • 1429 Words
    • 6 Pages
    Better Essays
  • Satisfactory Essays

    Number Conversion

    • 3476 Words
    • 14 Pages

    E.G. 19 = 1 9 = 0001 1001 = 11001 THUS, FOR SUMS BETWEEN 10 o 18 MUST SUBTRACT 10 AND PRODUCE A CARRY SUBTRACT 10 = 10102 COMPLEMENT = 0110 >> ADD 2’s…

    • 3476 Words
    • 14 Pages
    Satisfactory Essays
  • Satisfactory Essays

    $2,000  $100/(1  i)  $100/(1  i)2  . . .  $100/(1  i)20  $1,000/(1  i)20.…

    • 264 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    (i ) k where (i ) (i ) (i 1 ) (i 1 ) θ 1 , ..., θ k 1 , θ k +1 , ..., θ p (i )…

    • 7365 Words
    • 30 Pages
    Good Essays
  • Powerful Essays

    Golden Rules for Teaching

    • 1193 Words
    • 5 Pages

    SOME EXAMPLE PRINCIPLES • • • • • • • Iteration vs. recursion Compilation vs. interpretation Caching Use of hints Hashing Locality in space and time Delayed binding…

    • 1193 Words
    • 5 Pages
    Powerful Essays
  • Satisfactory Essays

    Assignments

    • 380 Words
    • 2 Pages

    This examination paper consists of 2 questions. For grading purposes, the questions are given the following approximate weights:…

    • 380 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Gauss Program on C++

    • 369 Words
    • 2 Pages

    P = GenMW - LoadMW; % Pi = PGi - PLi, Real Power at the buses.…

    • 369 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    1 2 5 6 3 4 X 7 8 b) Differentiate between DFS and BFS tree traversals. Explain how DFS algorithm can be used to obtain the topological sorting with an example. (08 Marks) PART -B 5. a) Write and explain the Heap sort algorithm using top-down approach. Sort the elements {M,O,R,N,I,N,G} in alphabetical order.…

    • 379 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Side effects are the most common way that a program interacts with the outside world (people, filesystems, other computers on networks). But the degree to which side effects are used depends on the programming paradigm. Imperative programming isknown for its frequent utilization of side effects. In functional programming , side effects are rarely used. Functional languages such as Standard ML , Scheme and Scala do not restrict side effects, but it is customary for programmers to avoid them. [3] The functional language Haskell restricts side effects with a static type system ; it uses the concept of monads to do stateful and IO computations. [4] [5]…

    • 351 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    Presentatiom

    • 361 Words
    • 2 Pages

    1. Provide complete solutions to problems 3.21, 3.25, 3.30, 3.34 from the textbook on pages 104 – 107 Submit the solution to the following questions. 1. Consider the following LP: Maximize Z = 3X1 + 2X2 Subject to: 2X1 + 4 X2 -X1 + 4 X2 4X1 - 2 X2 1X1 - 1 X2 ≤ 22 ≤ 10 ≤ 14 ≤3 (1) (2) (3) (4)…

    • 361 Words
    • 2 Pages
    Satisfactory Essays

Related Topics