• edited by
3,272 views
4 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

1 Answer

4 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

Position:
Show:

Related questions

0 0 votes
0 0 answers
3.3k
3.3k views
2 2 votes
2 2 answers
2.1k
2.1k views
the.brahmin.guy asked Jan 22, 2017
2,120 views
Let Grammar be with these transitions:S - a{print "0"}AA - b{print "1"}BA - c{print "2"}A - ε{print "-"}B - d{print "1"}AB - ε{print "0"}What is the output produced for i...
0 0 votes
0 0 answers
597
597 views
arpit.jha asked Aug 23, 2024
597 views
In this question I believe as there is no evaluation taking place as you can see the Translation part of the production ruleonly printing is taking place nothing is given...