Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Prob 1. Answer the following questions in the programming language design. 1.1 B

ID: 3716091 • Letter: P

Question

Prob 1. Answer the following questions in the programming language design.

1.1 Briefly describe the difference between static data type checking (SDTC) and dynamic data type checking (DDTC).
1.2 In the programming language, describe the eager evaluation and the lazy evaluation in conjunction with the parameter passing technique, and give examples that you can utilize.
1.3 When calling a function, list what you need to store in the Activation Record, and explain what they are.
1.4 Describe Garbage Collection and Dangling Reference and provide solutions.
1.5 In the static scoping rule, we apply the rule "Look outside, but never inside" to find a stored location of non-local variables. Describe any problems that may arise if you do not apply this rule.
1.6 Describe the Copy-in and Copy-out methods of parameter passing techniques and analyze their advantages and disadvantages compared to other techniques.
1.7 Provide about 4 side effects that can occur when designing the data type of a programming language and explain why.

Explanation / Answer

There are a lot of questions in the part and as i have limited time to answer. I am providing first 4 . Please have a look and if you have any doubt just leave a comment.

1.1 Type checking in the context of programming language is about making sure that program is type-safe. In different languages there are different data types like Primitives (int , float) and composites( enum, array etc) are there. When we make methods we expect some arguments or some time and return of other. Type checking is about making sure that when we call them we pass correct types otherwise the program will fail at run time. So type checking helps in making sure that the possibility of type errors is kept to a minimum. TYpe checking is of two type:

1. Compile time(Static) : Static type checking helps to catch error much earlier. The complier checks for errors before run-time. Differnet languages like Java, C++ support static type checking.

2. Run-time(dynamic) : Is when the type checking is done on run time.A lot of new dynamic languages are coming up where we dont have to specify variables type etc in advance. They are passed at the run time. Dynamic type checking checkes types on the fly, during execution. The main problem with these types of language is that the code will compile even if they contain errors but when we run then we find about the errors. Differnet languages like JavaScript, Groovy are dynamically-typed languages

1.2 Eager evaluation and the lazy evaluation

1. Eager Evaluation : In eager evaluation, the actuals parameters are evaluated before a call. Pass-by-value, pass-by-reference, pass-byvalue-result are all examples of eager evaluation. For example in case of pass-by-value:

Class CallByValue{

public int swap(x,y){

//Change position of x and y;

}

public static void main(){

int x = 10;

int y = 20;

swap(10,20);

print(x);//10

print(y);//20

}

}

In the above case A copy of the passed-in variable is copied into the argument of the sum(). So if we change any thing to the argument will not affect the orginal values. So even we passed x and y to swap their value was changed in the swap() but that was just a copy , after returing to main() we can see x and y still print the same value.

2. In lazy evaluation, they are evaluated only when used. Pass-by-name is an exampe of Lazy evaluation. Pass-by-name re-evaluate the actual parameter on every use. In lazy evaluation, the actual parameter is not evaluated until the we actually use parameter's value. So, at that time, the actual parameter is evaluated, and the value is cached. Then, if the value of the formal parameter is needed again, the cached value will be used. It is not used in many modern languages. It is mostly supported in pure Functional languages like Algol. e.g.

procedure sum(x,y);

real x,y;

begin

x:=x+y

end;

So when we call sum(x,y) the procedure sum() can change the values of variables used in the argument expression and hence change the expression’s value as well.

1.3. What we need to store in Activation Record:

Activation record for a function is used for storing variables local to a function are allocated to the stack frame. When the function comes back to original method the variables are popped out from the stack. So mainly it is used for temporary storage of variables, temporary storage of program addresses. Example of Activation Record in case of a function call

public int sum(int a, int b)

{

int x, y;

y = a+b;

return y;

}

So stack order(Activation Record) will be like this:

Top: x

y

return address

return value y

a

Bottom: b

1.4 . Garbage Collection and Dangling Reference and provide solutions:

Garbage Collection: is clean up. All the programming languages support garbage collection for memory managment feature. In programs we create a lot of objects after the use is done we dont care about what happens to the objects: are they still in memory? If they are not cleaned up then we will get outofMemoryError after some amount of time. So , a lot of the languages provide garbage collection that takes care of object destruction like java . garbage Collection frees the storage for other programs. In some of the languages like C we have to do it manually. An object is considered valid for garbage collection if there exists no reference for that object.

Dangling Reference: A dangling reference is a reference to an object that no longer exists. It is a reference to a memory address that was originally allocated, but is now deallocated . The object is destructed but still there is some variable referring to it. So for some reason the object is destroyed but the pointer still points to the memory location of the deallocated memory. This can cause problem during execution of next program. It can be avoided by initialize pointer to NULL, after de-allocating memory, so that pointer will be no longer dangling. Assigning NULL value means pointer is not pointing to any memory location. Also we can make a delete funtion that takes care of all the delete at once. C has features like "smart pointer" to handle such dangling references

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote