Briefly describe the properties of type system

Assignment Help Programming Languages
Reference no: EM131140155

Question 1

Consider a progamming language with the following statements:
y := 2;
z := x + y; write(z);
Execution of these statements prints the value 6 on the console. Is this a declarative, imperative, or functional language?

Question 2

Consider the following record definitions that create two structures named. Score and Piece.

record                 record (
key string;          time long;
time long;           key string;
Score )                Piece

Now consider the following statements, which execute successfully:

1 Score x = new Score( );
2 tai. key = "C#";
3 Score y = x;
4 y. time = 3600;

Based on this example, briefly describe the properties of type system of the corresponding programming language. Pay attention to each of the statements since there are a few obvious statements you can make (e.g. weakly vs. strongly typed, etc.).

Question 3

Consider the g-rammar:

statement                assign
statement                sub call
assignillent              id = expression

sub call                    id ( arguments )
head

tail                           operatioli express i071

tail
head                       id
head                      sub call
head                      (expression)
operation              argunients
arg tail
arg tail

(Note: Epsilon, a, denotes an empty string and id is any alphabetic token. e.g. foo.)

Construct a parse tree for the input string:
                                                               foo(a b)

Question 4

Using the grammar in the previous question, add the production rules necessary to extend this grammar to include the definition of a subroutine. For example,

subroutine foo (x, y) z = x + y
bar (z)
}

Are the following Lambda Calculus expressions well-forced? (Assume an Applied calculus, where the operators (+ - * l ) are legal well-formed terms in the language and parentheses are allowed.)

Are the following Lambda Calculus expressions well-formed? (Assume an Applied calculus, where the operators (+ - * ) are legal well-formed terms in the language and parentheses are allowed.)

Question 5

y . x + y

Question 6

Question 7

ka + b)

Question 8

Which variable, if any, occurs free in the following Lambda Calculus expression? Xx . Ay. x (Ax. x) y (Ay. y) z (Az. z)

Questions 9 - 12 let.
zero E 'XX X
one E succ zero two E succ one
SUCC E 7i, . (As. (s cadr) n) cadr = X . . v
(Note: cadr is a Lisp utility function that returns the second element in a list. In this case, realize that it's returning the second argument in a two parameter Curried function. That is, it's selecting the second argument. Don't worry about Currie functions. We mention it only because currying allows the representation of multiple argument functions since any multi-argument function can be rewritten as an equivalent function that accepts one argument.)

Question 9

Using the inference rules of Lambda Calculus, show that
one cadr = zero
(There is only one tricky substitution. use parentheses to keep it straight.)

Question 10
Using the inference rules of Lambda Calculus, show that
two cadr cadr = zero
(There is only one tricky substitution, use parentheses to keep it straight.)

Question 11
Given that cadr selects the second argument of a two parameter Curried friction.
Write a three parameter (Curried) Lambda Calculus function, ‘caddr. that selects the third parameteriargument.

Question 12
Write a three parameter (Curried) Lambda Calculus function 'second'. that selects the second argument

Question 13
Consider the assignment statement:
= y = z = 0;
"Many languages support multiple target variables for a single source expression. A common use of such a construct is to initialize two or more variables to the same value. The previous assignment statement initializes all three variables to zero.

The previous quote describes the semantics of the previous assignment statement. As semantic descriptions can be characterized along two primary dimensions, which two categories of semantics best describe the previous statement?

Question 14

Consider the following code:
1 int i, j;
2 void bar(int x)
3 int k, 1;
4 J = 2 * x;
5 x = x + 1;
6
7 1
8 void foo(int y, int z)
9 float j, k;
10 bar(i);
11 = 3;
12
13 }
14 void baz() [

15
16
17
18
19
20 int b, i = 5; foo(b, bar(i); c;
b =
c); 3; c = 2;

Assuming execution starts with line 14, subsequent execution of this code provides examples of both Lexical (static) and Dynamic scoping.
Briefly describe when and how each of these scoping examples occurs. In your description. include the line numbers in the order of execution. For example. all executions will begin by sequentially executing lines: 14, 15, 16, ...
Consider the following code, which
• defines a linked-list structure named 'item' (lines 4-7) and
• two variables named 'top and ‘p' (line 9).
• Both of these variables that have a pointer data type named 'link' (line 3) (i.e. they are pointers to an 'item' record).
• Execution of this program begins at line: 10.
The program is both simple and silly.
• it reads a character fiord the console, acids it as a new item in the list (lines 12-18),
• it then deletes all of the items in the list (lines 19-24)

PROGRAM ricksList (input, output) I
TYPE
link = "item; item = RECORD
next ' link;
data : char


END;
VAR
top, p : link; BEGIN
base := NIL; WHILE NOT eof DO BEGIN
new(p); read(pA.data); p" .next := top;
top := p;
END; {while'
WHILE top <> NIL DO BEGIN
p := top;
top := p^.next; dispose(p);
END; { while } END; { ricksList

Question 15

Based on the above example. what type of memory management (implicit or explicit) does this programming language utilize?

Question 16

Based on the above example, does this language utilize strong or weak typing?

Question 17

Based on the above example. does this language utilize implicit or explicit declarations.

Question 18

Based on this example, what type of bindings (dynamic or static) does this programming language support?
Consider the following factorial function (it's not Lisp):

(define (fact n) (if (eqv? n 0) 1
(* n (fact (- n _)))))

Question 19
Based on this example, describe two properties associated with this language's type system (they are obvious).

Question 20

Consider the Lisp function:
#' ( lambda ( x y )
x )
Is this an example of a first class function or an anonymous function?

Question 21

Consider the following Java method:
1 public void noop() t
Boolean flag = false;
4 if (true) {
5 flag = "false";
6 }
7 }

Line 5 results in a compile-time compiler error. What type of semantics is in play here?

Question 22
Consider the Prolog code:
male(albert). male(edward). female(alice). female(Victoria).
parents(edwardrVictoria,albert). parents(alicerVictoria,albert).
sister of(X,Y) :- female(X), parents(X,M,F), parents(X,M,F).
To ask whether Alice is the sister of anyone. the appropriate query is:
?- sister of(alice,X).
Briefly describe what happens when Prolog executes this query?

Question 23
Consider the following Logical Programming language (i.e. Prolog-like) code:
speaks (rick, german).
talkswith(X,Y) speaks(X,L), speaks(Y,L), X 1 Y.

Question 24
In your own words, why is language in Question 21 declarative and the language in Question 14 nor?

Question 25
Consider the following granmnar:
xpress1011 -> tertian: expression = expression
tertictn. secondary I expression + serondart,
secoildark. primaly secondary * prinian.
priina?7. literal variable 1( expression
/item/ 1, 2, 3, ...
variable a. b, c,

Does this grammar specify an abstract or concrete syntax? [Hint: there's one huge give away.]

Question 26

Substitute the following production rule for the expression rule in Question 2.6. eNpres s loll -. literal expression + expression expression - expression

Give two parse trees that delnollstrate that this new grammar is ambiguous.

Reference no: EM131140155

Questions Cloud

Prepare and post adjusting and closing entries : Prepare a post-closing trial balance, and determine whether the subsidiary ledgers agree with the control accounts in the general ledger.
Establish task precedence relationship : Create a Work Breakdown Structure (WBS) that includes all project tasks (hierarchically grouped) and durations - Establish task precedence relationship
Which spectrogram has the shortest time window : Which pair (or pairs) of spectrograms have approximately the same frequency resolution? (a&b) (b&d) (c&d) (a&d) (b&c)
Journalize the transactions that have not been journalized : (b) Journalize the transactions that have not been journalized in a one-column purchases journal and the cash payments journal (see Illustration 7-16).
Briefly describe the properties of type system : Briefly describe the properties of type system of the corresponding programming language. Pay attention to each of the statements since there are a few obvious statements you can make
Update implementation and communication of strategic plan : Why is it important to continuously update the implementation and communication of a strategic plan? Who should be responsible for updating and communicating a strategic plan? Why?
Bounded rationality and sub-optimization : For this assignment you will be using the discussion board/ forum. Explain the following decision making terms in your own words. Use examples, if necessary and make sure you read and respond to the postings of others. Bounded rationality. Sub-optimi..
Explain the checks and balances system : Describe the US government structure in 1000 or more words. Explain the checks and balances system and indicate its strengths and weaknesses
Insert the beginning balances in the accounts receivable : Insert the beginning balances in the Accounts Receivable control and subsidiary accounts, and post the June transactions to these accounts.

Reviews

Write a Review

Programming Languages Questions & Answers

  Programming problem

Programming Problem can be solved by a program that performs three basic tasks-Input Data, Process Data, and Output Results.

  Create a driver class to test implementation

Assume you are asked to re-implement the notification part of e.centennialcollege.ca by using observer pattern. When there is a new grade item released or the assignment due date is two days away, those students who register the notification could..

  Business rules form the basis of the database design.

A member receives many invitations, and each invitation is sent to many members.

  Run the program with a file name

Write a short Python program that asks the user to input two numbers, and then divides the first number by the second. The program must use an exception handling structure to process the situation when the denominator is zero. Run your program wit..

  Pseudocode to create thread-safe countdownevent by locks

Write pseudocode to implement a thread-safe CountdownEvent using locks and condition variables by implementing the following methods (lists 4 methods) and then "implement a Barrier using a CountdownEvent.

  E for scientific notation

+, 0, decimal points, E for scientific notation +, 0, decimal points, E for scientific notation

  Compute the trajectory of the particle

Your program should then compute the trajectory of the particle and display the motion of the particle as an animation in 3 dimensions

  Write vl program to convert leagues-number of nautical miles

Write a VL program which will convert 20,000 leagues to number of nautical miles. Your program requires no input elements, just elements to compute result and output how many nautical miles is equivalent to 20,000 leagues.

  Formulate a linear programming model for given problem

A company produces two products that are processed on two assembly lines. Assembly line 1 has 100 available hours, and assembly 2 has 42 available hours. Formulate a linear programming model for this problem

  Write client-side javascript function to convert ampersands

Your job is to write a client-side JavaScript function that converts all ampersands in a form field to the text string " and " when the form loses focus on the textbox in question.

  Program to prompt a user for hourly pay rate

Create program called "calculatePay" which will prompt user for their hourly pay rate.

  Writing a class

Build a class for a type called Fraction

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd