What type of grammar can be used for both top-down and bottom-up parsing ?
2024
What type of grammar can be used for both top-down and bottom-up parsing ?
- A.
LL(1)
- B.
LR(0)
- C.
CFG (Context-Free Grammar)
- D.
None of these
Attempted by 31 students.
Show answer & explanation
Correct answer: C
A Context-Free Grammar (CFG) is the broad class of grammars that encompasses both top-down and bottom-up parsing techniques. While specific subsets like LL(1) are designed exclusively for top-down parsing and LR(0) is strictly for bottom-up parsing, the general CFG definition does not restrict itself to one direction. Top-down parsers (like recursive descent) build the parse tree from the root down, whereas bottom-up parsers (like shift-reduce) construct it from leaves up. Since any grammar that can be parsed by either method must fundamentally adhere to the rules of a Context-Free Grammar, CFG is the correct classification. Therefore, Option C is the right answer because it represents the superset capable of supporting both parsing strategies depending on the specific algorithm chosen.