edited by
1,301 views
4 votes
4 votes

$Q_1 \Rightarrow$ For synthesized attribute, value is only computed when symbol is on the _____ side of production. For inherited attribute, value is computed in productions where symbol is on the _____ side.

$1.$ Left, Right   $2.$ Right, Right    $3.$ Right, Left     $4.$ Left, Left


$Q_2 \Rightarrow$ In static scoping undefined variable

$a).$ Search in upper block 
$b).$ Search where the function is called 
$c).$ Refers to global variable 
$d).$ None of these

edited by

1 Answer

4 votes
4 votes

Q2. Ans. Option D

Undefined Variable:->>  variable that is accessed in the code but has not been previously declared by that code.

In any scoping result will produce compilation error for undefined variables.

Note:->C uses static(lexical) scoping.

Ex:-foo.c 
int main() 
{
  int y = x;//here x is used without declaration so called undefined variable. 
  return 0;
}
foo.c: In function `main':
foo.c:2: error: `x' undeclared (first use in this function)
foo.c:2: error: (Each undeclared identifier is reported only once
foo.c:2: error: for each function it appears in.)

https://en.wikipedia.org/wiki/Undefined_variable#C

Another Example

//const int b = 5;

int foo() {
   int a = b + 5;
   printf("%d",a);
}

int bar() {
   int b = 2;
   return foo();
}

int main()
{
   foo(); 
   bar();
   return 0;
}

O/P of Static Scoping :->> Compiler error 'b' is undeclared.

If we remove first line comment then o/p:->> 10,10

Related questions