# Recent questions tagged compiler-design

In the following gate 2021 question from compiler design, https://gateoverflow.in/357425/gate-cse-2021-set-1-question-26 suppose option C is modified as : The actions can be used to type-check syntactically correct boolean variable declarations BUT NOT boolean expressions. ... separate semantic rule using the production D → bool ID. Then, will option C be correct in addition to option B ?
S → S + S {S.val = S1.val - S2.val} S → S * S {S.val = S1.val + S2.val} S → S – S {S.val = S1.val * S2.val} S → (S) {S.val = S1.val +2 } S → id The value of the attribute at the root when the following expression is evaluated using the above SDT is _____. ( (5 + 4) – 8) + 12
Consider the basic block given below: a=10 b=4*a t1=i*j c=t1+b t2=15*a d=t2*c e=i t3=e*j t4=i*a c=t3+t4 The minimum number of nodes present in the DAG representation of the above basic block is _____.
Draw the canonical collection of lr(0) item s-->da|ab a-->ba|c B-->bB|c. Find out whether the grammar is LR(0) or not and SLR(1) or not.
Caption
Consider the following $\text{ANSI C}$ program: int main () { Integer x; return 0; } Which one of the following phases in a seven-phase $C$ compiler will throw an error? Lexical analyzer Syntax analyzer Semantic analyzer Machine dependent optimizer
In the context of compilers, which of the following is/are $\text{NOT}$ an intermediate representation of the source program? Three address code Abstract Syntax Tree $\text{(AST)}$ Control Flow Graph $\text{(CFG)}$ Symbol table
Consider the following $\text{ANSI C}$ code segment: z=x + 3 + y->f1 + y->f2; for (i = 0; i < 200; i = i + 2) { if (z > i) { p = p + x + 3; q = q + y->f1; } else { p = p + y->f2; q = q + x + 3; } } Assume that the variable $y$ points to ... the form $\textsf{ y ->f1}$ or $\textsf{y ->f2}$) in the optimized code, respectively, are: $403$ and $102$ $203$ and $2$ $303$ and $102$ $303$ and $2$
1 vote
For a statement $S$ in a program, in the context of liveness analysis, the following sets are defined: $\text{USE}(S)$ : the set of variables used in $S$ $\text{IN}(S)$ : the set of variables that are live at the entry of $S$ $\text{OUT}(S)$ : the set of variables that are live at the ... $) }\cup \text{ OUT ($S_2$)}$ $\text{OUT ($S_1$)} = \text{USE ($S_1$)} \cup \text{IN ($S_2$)}$
Consider the following augmented grammar with $\{ \#, @, <, >, a, b, c \}$ ... $I_0 = \text{CLOSURE}(\{S' \rightarrow \bullet S\})$. The number of items in the set $\text{GOTO(GOTO}(I_0<), <)$ is ___________
1 vote
Consider the following statements. $S_1:$ Every $\text{SLR(1)}$ grammar is unambiguous but there are certain unambiguous grammars that are not $\text{SLR(1)}$. $S_2:$ For any context-free grammar, there is a parser that takes at most $O(n^3)$ time to parse a string of length $n$. ... $S_2$ is false $S_1$ is false and $S_2$ is true $S_1$ is true and $S_2$ is true $S_1$ is false and $S_2$ is false
1 vote
Consider the following grammar (that admits a series of declarations, followed by expressions) and the associated syntax directed translation $\text{(SDT)}$ ... The actions can be used to type-check syntactically correct boolean variable declarations and boolean expressions. The actions will lead to an infinite loop
Consider the following context-free grammar where the set of terminals is $\{a,b,c,d,f\}$ ... $\boxed{1}\;\text{blank} \qquad \boxed{2}\;\text{S} \rightarrow \text{R}f \qquad \boxed{3}\; \text{blank} \qquad \boxed{4}\;\text{blank}$
1 vote
Consider the following $C$ code segment: a = b + c; e = a + 1; d = b + c; f = d + 1; g = e + f; In a compiler, this code segment is represented internally as a directed acyclic graph $\text{(DAG)}$. The number of nodes in the $\text{DAG}$ is _____________
1 vote
Can we generate different parsing table for grammar
Consider the following grammar S → S ; T | T T → s Construct DFA of LR(1) Items Show the parsing stack for the input string s;s;s
Identify lexical, syntax and semantic errors from the following C program. Write line number, error message, and type of the error for each error in the program 01: float Factorial(int N) { 02: float F; 03: F==1; 04: while(i<F) 05: F*=i; 06: return F 07: } 08: Void mane() 09: integer r; 10: r=Factorial(5); 11: IF(r>0) 12: PrintResult(r); 13: }
1 vote
How to solve it?
(i) if a non token were in the code would it be counted in the lexical analysis? (ii) and will it generate an error in the lexical analysis phase or simply ignore that and count rest of the tokens? like, in this code : ifx = 12*54; what would be the output from lexical analysis phase?
what are the minimum number of registers required without any register splitting in following case c=a+b; d=a+b; as we can see at instruction 1, a and b are live c is dead at instruction 2 also a and b are live d is dead how many min register are required? ... required only. so according to that only 2 variable at max are live at any point so 2 register should be required..what would be the answer
Consider the basic block given below. u=u+v v=v+w x=v-w y=v-x z=u+v Find the sum of the minimum no of edges and nodes present in the DAG representation of the basic block given above.
Choose the correct output when the lexical analyzer scans the following input: “cabacccab”.
Answer will 8 or 9? i got 9 (according to me no optimization should be done in Intermediate representation form)
The question on madeasy test: find out number of temp variables in the 3AC generated for this expression x = (-b + sqrt(b^2 - 4*a*c)) / (2*a) The answer on madeasy makes sense (screenshot below), but in this nptel video - (1 min 30th second) https://www.youtube.com/watch?v ... ) or the 2nd (nptel and wikipedia method): 1. ** 2. **where Tn-1 is √(b^2 - 4ac), and Tn is the nth temporary variable
S->AB A->a B->b is ambiguous or not ? i think not ambiguous becz not having two same left most derivation tree or not hab=ving two same RMD tree…...is it correct
1 vote
x=x*x y=y*y x=x*y y=y*x Minimum number of total variables in single static assignment for above code?
Anyone please clarify why lexical error is generated.
Which of the following is/are not the functions of Syntax analyzer ? Recognize the language and to call the appropriate action routines that will generate the intermediate form or matrix for these constructs. Build a literal table and an identifier table Build a uniform symbol table Parse the source program into basic elements or tokens of the language. Anyone please clarify.
Can anyone help me with this? How am I supposed to test whether these are viable prefixes of some handle when I am not even given any test string which can be derived from the above grammar? Please help! Thanks in advance.
I don’t understand it at all, if someone can elaborate these options then it would be a great help.
Here answer seems to be option A but given as D. Anyone please clarify
S→ ABA A→ Bc|dA|epsilon B→ eA How many entries have multiple productions in LL(1) table? ans given is 1. but i am getting 2 In answer Follow(A)={c,e,$} but according to me it should be {c,d,e,$}