Number 8 please. Answer the following questions, (1) Translate the facts into Pr
ID: 3570995 • Letter: N
Question
Number 8 please.
Answer the following questions, (1) Translate the facts into Prolog predicates. (2)Translate the rules into Prolog predicates. (3)Write down the query that searches for all lovers and all rivals in love respectively (two queries totally). (4)Write down the results, i.e., who and who are lovers, and who and who are rivals in love. 8. Given the following program in C, ASCII Table (partial) Decimal Char 38 & 90 Z 100 d 120 x 121 y Draw the symbol table at line 12 by using static scoping and dynamic scoping respectively (two symbol tables totally). Then write down the output of the program for static scoping and dynamic scoping respectively (two sets of outputs totally).Explanation / Answer
In static scoping, the scope of an indentifier is determined by its location in the code, and since that doesn't change, the scope doesn't either. In dynamic scoping, the scope is determined by the sequence of calls that has led to the use of an identifier, and since that can be different each time that use is reached, is dynamic.
At line 12:
static scope
so compiler try to find x before occurence of x inside q(),its not found,so finds in global variables,so finds int x=100,so prints 100
dynamic scope
so compiler try to find x before occurence of x inside q() ,its not found,so finds in calling functions,so finds char x='x',so prints 120,,
see table 'x' has integer value 120
output\
static
100
y
dymanic
120
&
reason of output
static scope,,
q()...will print x 100(told before) and call p(),which will find y,but not found before occurence of y inside q(),,so prints global variable char y='y',so prints y
dynamic scope
q()...will print x 120(told before)and call p(),which will find y,but won't find y before occurence of x inside q() -though int y[10] is there ,declared after-so sees inside calling function q(),finds int y=38,so prints corresponding charatcer value given in table
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.