Consider the following two statements:
- P: Every regular grammar is LL(1)
- Q: Every regular set has a LR(1) grammar
Which of the following is TRUE?
View worked solution
Answer: C
To determine the truth value of the statements, let us analyze them individually:
Statement P: Every regular grammar is LL(1)
- A regular grammar can have conflicts that prevent it from being . For example, consider the following right-linear (regular) grammar:
- For this grammar, both production rules for start with the terminal . Specifically: This creates a first-first conflict, meaning the parser cannot decide which production to choose with a single lookahead token.
- Therefore, this regular grammar is not , making statement P false.
Statement Q: Every regular set has a LR(1) grammar
- A "regular set" is a regular language.
- Every regular language is a Deterministic Context-Free Language (DCFL).
- The class of languages generated by grammars is precisely the class of DCFLs.
- Since every regular language is a DCFL, there always exists an grammar for any given regular language.
- Therefore, statement Q is true.
Thus, P is false and Q is true, which corresponds to option C.
Free practice · Your answers on this page are not saved.
