in Compiler Design edited by
18,099 views
50 votes
50 votes

Which of the following statements are TRUE?

  1. There exist parsing algorithms for some programming languages whose complexities are less than $\Theta(n^3)$

  2. A programming language which allows recursion can be implemented with static storage allocation.

  3. No L-attributed definition can be evaluated in the framework of bottom-up parsing.

  4. Code improving transformations can be performed at both source language and intermediate code level.

  1. I and II
  2. I and IV
  3. III and IV
  4. I, III and IV
in Compiler Design edited by
18.1k views

3 Comments

For point 2 we can refer to  question https://gateoverflow.in/477/gate2008-54  (point 3)

1
1
L- attributed → top-down parsing

S-attributed → bottom-up parsing and top-down parsing

Every S attributed is L attributed grammar.
0
0
1
1

3 Answers

46 votes
46 votes
Best answer

Answer is B.

  1. Yes there does exist parsing algorithms (e.g. CYK algorithm) which run in $\Theta(n^3)$.
  2. It cannot be implemented with static storage allocation. It needs dynamic memory allocation.
  3. Every S-attributed definition is also an L-attributed definition and can be evaluated in the framework of bottom up parsing.
  4. True.
edited by

4 Comments

A programming language which allows recursion can be implemented with static storage allocation.FALSE

 It needs Stack storage allocation instead of dynamic storage allocation.

2
2
recursion requires stack and not heap(used for dynamic memory allocation)
3
3
Can you please, state an example.
0
0
19 votes
19 votes

LL(1) and LR parsers are linear time parsers. ie, $O(n)$

I is True.

PS: Recursive descent parser runs in $O(2^n)$ time.


Recursion needs stack

II is False

L-attributed definitions have both inherited and synthesized attributes. Can be evaluated with top-down-left-to-right style.

S-attributed definitions have only synthesized attributes. Can be evaluated with bottom-up style.

 

So, in case a definition only has synthesized attributes, we can call it both L and S attributed. Such an L-attributed definition can be evaluated with bottom-up style.

So, III is False.

Code improvement can obviously be done at the user-level by not writing stupid code. And compiler also improves (optimises) the code. Hence,

IV is True.

3 Comments

Every S attributed grammer is L attributed too and S-attributed SDTs are evaluated in bottom-up parsing, as the values of the parent nodes depend upon the values of the child nodes. This means some L attributd SDT are also solved in bottom up fashion , which prooves 3rd statement is FALSE
0
0
Correct! :)
0
0

@JashanArora Sir can you please clear one doubt from this question https://gateoverflow.in/908/gate2003-18?

I am not able to understand why option B is correct? Is it because L-attributed contains both inherited and synthesized attribute, and inherited one can be solved using bottom up? Is my understanding correct?

Thanks in advance.

0
0
0 votes
0 votes
  1. There exist parsing algorithms for some programming languages whose complexities are less than (O(n3):

    • True. There are parsing algorithms, such as LL(k) and LR(k), whose complexities are less than O(n3).
  2. A programming language which allows recursion can be implemented with static storage allocation:

    • False. Recursion generally requires dynamic storage allocation, as static allocation may not handle arbitrary levels of recursion.
  3. No L-attributed definition can be evaluated in the framework of bottom-up parsing:

    • True. L-attributed definitions require a top-down parsing approach, as they involve attributes associated with the leftmost derivations.
  4. Code improving transformations can be performed at both source language and intermediate code level:

    • True. Code optimizations can be applied at both the source language level (before compilation) and the intermediate code level (during compilation).

Therefore, the correct answer is:

I and IV

Answer:

Related questions