Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

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.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M91896654
  • Price:- $130

Guranteed 48 Hours Delivery, In Price:- $130

Have any Question?


Related Questions in Programming Language

Task arrays and structsoverviewin this task you will

Task: Arrays and Structs Overview In this task you will continue to work on the knight database to help Camelot keep track of all of their knights. We can now add a kingdom struct to help work with and manage all of the ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Task silly name testeroverviewcontrol flow allows us to

Task: Silly Name Tester Overview Control flow allows us to alter the order in which our programs execute. Building on our knowledge of variables, we can now use control flow to create programs that perform more than just ...

Task - hand execution of arraysoverviewin this task you

Task - Hand Execution of Arrays Overview In this task you will demonstrate how arrays work by hand executing a number of small code snippets. Instructions Watch the Hand Execution with Arrays video, this shows how to ste ...

Task working with arraysoverviewin this task you will

Task: Working with Arrays Overview In this task you will create a simple program which will create and work with an array of strings. This array will then be populated with values, printed out to the console, and then, w ...

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

Question 1 what is a computer program what is structured

Question: 1. What is a Computer program? What is structured programming? 2. What is modular programming? Why we use it? 3. Please evaluate Sin (x) by infinite series. Then write an algorithm to implement it with up to th ...

Extend the adworks applicationi add dialogs to allow the

Extend the AdWorks application I. Add Dialogs to allow the user to Add, Edit, Read and Delete a Customer and refresh the view accordingly. 1. The user should be able to select a specific customer from the DataGrid and cl ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As