The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+4 votes
320 views

$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

in Compiler Design by Boss (28.4k points)
edited by | 320 views
+1
@mcjoshi @Kapil

Q2. D is the Ans
0
Okkk !

@mcjoshi, what is the answer provided by them ?
+1
Option (C). Refers to Global variable
0
Any reason for that ?
0
No solution given.
0
If undefined variable referred to global variable (int a)then that variable never called as undefined variable.

If the question would asked wrt to static scoping  .if a variable is referred and u want to find its scope Then:~)if we can't find its scope in local then we move ancestor blocks gradually and if we fail to find there also we last take the defined global variable.
0

 Rishabh Gupta 2  Shubhanshu  Anu007 

answer for first is "a"

explain pls

0

what synthesized says 

Left side take prodution take value from right side of pruction 

E.value →→ E.num + Enum 

here value is synthesizes attribute. value is calculate based on num.

what inherited says 

right side take prodution take value from right side of pruction 

E.num →→ E.value + Ecount 

here count is inherited  attribute. value(inherited) takes values from num and count . count take values from value and num .

0

 Anu007

same thing also told in prashant  comment. But m not getting 

Left side take prodution take value from right side of production

pls give some examples

0

I simply copppied his comment :

Left side take production take value from right side of production 

E.value (Left side) → E.num + Enum  (Right side)

here value is synthesizes attribute. value is calculate based on num.

Now got it 

1 Answer

+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

by Boss (23.6k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,288 questions
55,719 answers
192,111 comments
90,122 users