ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 4 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 19 May 2017 My Price 9.00

Execution of these statements prints

Question 1

 Consider a programming language with the following statements:

 

 

 

 

 

 

 

Execution of these statements prints the value 6 on the console.

Is this a declarative, imperative, or functional language?  Explain.

 

-=============================================================

The syntax above is of an imperative language. Basing the fact is by determining the distinct characteristic where control is the programmer’s fundamental responsibility; explicitly allocating memory ‘write’ and declaring the variables x,y,z.

 

-=============================================================

Question 2

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

 

 

 

 

 

 

 

 Now consider the following statements, which execute successfully:

 

 

 

 

 

 

 

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.).

 

Based on the code done on C sharp (C#) programming language, several factors can be distinguished regarding the objects referencing and access to variables by objects as follows:-

 

Creating object – Score is the class and is instantiated to an object by the key word new prior to the class constructor call.

Referencing object – A class instance in C# can be stored/pointed to a single variable x.

Subclasses – C# allows for creation of subclass instances to be created through the superclass’ instance; Piece is the subclass pointing to Score instance new Score();

Variables – Instance variables not declared static can be called by object references of their classes. Hence, an instance of Score ‘x’ accesses variable key assigning it a String value explicitly. On the other hand, instance of Piece ‘y’ accesses variable time assigning it an integer value.

 

.

 

-=============================================================

Question 3

Consider the grammar:

 

statement → assign

statement → sub_call

assignment → id = expression

sub_call → id ( arguments )

expression → head tail

tail → operation expression

tail → ε

head → id

head → sub_call

head → ( expression )

operation → + | - | * | /

arguments → expression arg_tail

arg_tail → , arguments

arg_tail → ε

 

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

 

Construct a parse tree for the input string:

foo(a , b)

 

-=============================================================

 

    Stmt

 

 

Subr_call

 

 

Id(foo)            (  arg_list  )

                       

Expr                                        arg_tail

 

 

Primary                        expr_tail          ,                       arg_list

                                                           

Id(a)                             ε                               

  expr                    arg_tail

                                               

Primary            expr_tail          ε

                                               

Id(b)                        ε

 

 

 

 

 

 

 

-=============================================================

Question 4

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

 

 

 

 

 

 

 

-=============================================================

 

statement → assign

statement → sub_foo

assignment → id = expression

sub_foo → id ( arguments )

expression → head tail

tail → operation expression

tail → ε

head → id

head → sub_foo

head → ( expression )

operation → + | -

arguments → expression arg_tail

arg_tail → , arguments

arg_tail → ε

 

 

 

For questions #5, #6, and #7 below;

Are the following Lambda Calculus expressions well-formed?  Explain.

(Assume an Applied calculus, where the operators ( +  -  *  / ) are legal well-formed terms in the language, and parentheses are allowed.)

 

-=============================================================

Question 5

λx, y . x + y

No

 

This expression should characterize the identity function. The name after the λ is the identifier of the contention of this function. The expression after the point (for this situation a solitary x) is known as the "body" of the definition. This is the character capacity connected to y. Enclosure are utilized for clarity as a part of request to keep away from equivocalness. Capacity applications are assessed by substituting the estimation of the contention x (for this situation y) in the body of the capacity definition, i.e.

(_x.x)y = [y/x]x = y

 

Therefore, the +y disqualifies the calculus lambda function.

-=============================================================

Question 6

λx . y

Yes

In λ calculus all names are local to definitions. In the capacity λx.x we say that x is "bound" since its event in the body of the definition is gone before by λx. A name not went before by a λ is known as a "free variable". In the expression (λx.xy) the variable x is bound and y is free. In the expression (λx.x)( λy.yx) the x in the body of the main expression from the left is bound to the principal λ.

-=============================================================

Question 7

λa . λb . (a + b)

Yes

Similar to previous. In λ calculus all names are local to definitions. In the capacity λx.x we say that x is "bound" since its event in the body of the definition is gone before by λx. A name not went before by a λ is known as a "free variable". In the expression (λx.xy) the variable x is bound and y is free. In the expression (λx.x)( λy.yx) the x in the body of the main expression from the left is bound to the principal λ.

 

 

 

-=============================================================

 

Question 8

Which variable, if any, occurs free in the following Lambda Calculus expression?  Explain.

λx. λy. x (λx. x) y (λy. y) z (λz. z)

Yes

In the case, if the function λx. <exp> is connected to E, we substitute every single free event of x in <exp> with E. In the event that the substitution would bring a free variable of E in an expression where this variable happens bound, we rename the bound variable some time recently playing out the substitution. For instance, in the expression (λx.( λy.(x(λx.xy))))y we relate the contention x with y. In the body (λy.(x(λx.xy))) just the primary x is free and can be substituted.

-=============================================================

 

Answers

(11)
Status NEW Posted 19 May 2017 08:05 AM My Price 9.00

-----------

Not Rated(0)