Consider the grammar below
s→s1s2;s1→s3+s1|s3;s2→*s1s2|∈;s3→id
In the predictive parsing table, M of the grammar, the entries M [s, id] and M [s2, $] are respectively.
-
Solution
The predictive parsing table is
Consider the following grammar :
S→AC|CB
C→aCb|∈
A→aA|a
B→bB|b
What language is generated by given grammar?
-
Solution
Hence, we can say the language generated is
L = {annbm| n, m≥1, n≠m}
The grammar A→AA |A| ε is not suitable for predictive parsing because the grammar is
-
Solution
an operator grammar
Consider the following expression:
(P v Q) v (P→R) ∧ (Q→S)
Find the equivalent expression of the above expression.
Consider the following two regular languages:
L1= (a + b) * a and L2= b(a +b)*.
The intersection of L1 and L2 is given by
-
Solution
Here, L1= (a + b)*a is nothing but set of all strings of a and b ending with a.
L2= b(a + b)* is a set of all strings of a and b starting with b.
The intersection of L1 and L2 is the set of all strings starting with b and ending with a.
∴ L21∩L2=b(a + b)*a
Hence, option (d) is the correct answer
Consider the C function given below :
int f (int j)
{
static int i = 50;
int k;
if (i == j)
{
printf (“something”);
k = f(i);
return 0;
}
else return 0;
}
Which one of the following is true?
-
Solution
When f = 50, the fn will exhaust run time stack, because function will be called infinite times which results into an infinite loop at j = 50.
Consider the following C function :
float f (float x, int y){
float P, S; int i;
for (S = 1, P = 1, i = 1, i < y, i++){
P* = x/i;
S+ = P;
}
returns;
}
for large value of y the return value of the function of best approximates.
-
Solution
ex
What does the following fragment of C program print?
char c[ ] = “GATE 2017”;
char * p = c;
printf(“%s”, p + p[3] – p[1]);
-
Solution
Assume that base address of c is 2000
p + p[3] – p[1]
2000 + 69– 65 = 2004
\(∵\begin{pmatrix} p[3]=E=69\: in \: ASCII & \\ p[1]=A=65\: in\: ASCII & \end{pmatrix}\)
At position 2017⇒2017.
Consider the given Cprogram :
main ()
{
char s[ ]= {‘a’, ‘b’, ‘c’, ‘\n’, ‘c’, ‘\0’};
char *p, *str, *str1;
p = &s[3];
str = p;
str1 = s;
printf (“% d”, ++ *p +++ *str1 – 32);
}
What should be the output of the above program?
-
Solution
p is pointed to character‘\n’, str1 is pointing to character‘a’. For ++ *p, p is pointing to ‘\n’ and that is incrementedby one. The ASCII value of ‘\n’ is 10 which is then incremented by 1 to 11. The value of ++ *p is 11. ++* str1,str1 is pointing to ‘a’ that is incremented by 1 and becomes b. ASCII value of b is 98.Now performing (11 + 98 – 32) = 77 (“M”) so,Output = 77
Which varlable should be optimize in following C code?
If your compiler actually optimizes access time of only two register variables per function, which two variables in the following program are best ones to be made into register variables.
#include
#include
void main (void)
{
int i, j, k, m;
do
{
printf(“enter value”) ;
scanf (“%d”, &i);
m = 0;
for (k =0; k <100; k++)}
}while (i >0);
-
Solution
It is known that register is used to define local variables that should be stored in a register instead of RAM. A variable is used at many places in a program, it is better to declare its storage class as register. In the given program, K and m are used in many places. So, these are the best one to be made into register variables.