The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 4 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
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.
-=============================================================
Â