istatlist -> istatlist istat | istatShow how a bottom-up parser would parse the input
istat -> "import" name ";" | "import" name "." "*" ";"
name -> name . <id> | <id>
import Employee;Show a sequence of "shift" and "reduce" steps
import java.util.*;
istatlist -> istat | istatlist istat
istat -> "import" name tail ";"
tail -> "" | "." "*"
name -> <id> | name . <id>
varname=initialValue
function funnameFunction parameters are not named. Instead, you refer to them as $1, $2, $3...
{
. . .
}
funname arg1 arg2 arg3 . . .
local varname=initialValue
$varname
For example, the commandecho $aprints the value of a.
a) Write a short program that tests whether bash shell variables are
statically or dynamically scoped. Specify the output you expect under
static and dynamic scoping.
void work()a) Write assembly instructions (in x86 assembler or pseudo-assembler) for the function calls to print and fib (labeled 1 and 2). Show how the parameters and the static link are pushed on the stack. Assume that the static link is pushed onto the stack immediately before a nested function is called. Assume that the dynamic link (frame pointer) is stored in the ebp register.
{
int a = 3;
int b = 4;
int fib(int n)
{
if (n <= 0) return a;
int x = a;
int y = b;
for (int i = 2; i <= n; i++)
{
int z = x + y;
x = y;
y = z;
}
return y;
}
void print()
{
for (int i = 0; i <= 10; i++)
{
int n = fib(i); // 2
cout << n << endl;
}
}
print(); // 1
}
void main()
{
work();
}
typedef int (*Fun)(int);d) Write equivalent code in a language with closures (such as Scheme or JavaScript) to demonstrate that it is possible for work to return a closure with the action of fib that can be passed to print. Draw a diagram of the closure.
Fun work() { . . . return fib; }
void print(Fun f, int from, int to)
{
for (int i = from; i <= to; i++)
cout << (*f)(i) << endl;
}
void main()
{
Fun f = work();
print(f, 0, 10);
}
pushl %ebp ; save old frame pointerAfterwards, ebp points to the saved frame pointer. That is, the first local variable is accessed as -4(%ebp).
movl %esp, %ebp ; set frame pointer for this function
. . .
popl %ebp ; restore old frame pointer
ret