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

  Draw and implement abstract base class

Draw and implement the abstract base class ArithmeticExpression which represent any binary (having two arguments) arithmetic expression.

  Write a program that inputs number of hours worked

Write a program that inputs the number of hours worked and hoursly pay rat for employesand outputs their total pay.

  Write a function that accepts temperature in degrees

write a function that accepts temperature in degrees fahrenheit degf andcomputes the corresponding value in degrees

  Program to print total balances forward and total withdrawal

At the end of report, print total balances forward, total deposits, total interest earned, total withdrawals and total final account balances.

  Create the circle moving program using the new language

Create the circle moving program using the new language, and your reference sheet - Process Events needs to be called once each event loop to update SwinGame with the actions that have occurred since the last time through the loop.

  Program in perl that have two subroutines add() and multiply

Write a program in PERL that have two subroutines add() and multiply() that will add or multiply its arguments and print the result to screen.

  Read about what to look for when determining authenticity

Determine whether or not the author(s) provided reliable information supporting their argument/product.

  Explain why the insert statement for the view

Explain why the insert statement for the view you created in #2 did not work.

  Recursive method to search a string for a byrd

Write a recursive method that searches a string for a Byrd. A Byrd has the following properties. Its first character is an 'A'. If it is a two character Byrd then its second and last character is an 'H'.

  Prepare a presentation on backgrounds and fonts

Can you still read the text? Is it too narrow or thick? Is an icon hidden by the background? You should also include tips for choosing backgrounds and fonts.

  Why do we have both debug and release builds

When two or more functions have the same name, how does the compiler determine which one to use for a particular function call?

  Explain the contents of the text box

Describe the contents of the text box after the button is clicked

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