Which of the following correctly lists the four components that make up a context-free grammar (CFG)?
Think about what defines the structure and rules of a language in CFG.
A context-free grammar consists of terminals (basic symbols), non-terminals (syntactic variables), a start symbol (where derivation begins), and production rules (how symbols can be replaced).
What does a derivation in a context-free grammar represent?
Consider how strings are formed from the start symbol using rules.
Derivation is the process of applying production rules step-by-step to replace non-terminals and produce a string of terminals starting from the start symbol.
Given the grammar with productions:
S → S + S | S * S | ( S ) | a
Which statement is true about this grammar?
Try to draw parse trees for the string 'a + a * a'.
This grammar is ambiguous because the expression 'a + a * a' can be parsed in multiple ways, reflecting different operator precedence and associativity.
Which of the following statements correctly distinguishes context-free grammars (CFGs) from regular grammars?
Think about the kinds of patterns each grammar type can describe.
CFGs can describe languages with nested or recursive patterns (like balanced parentheses), which regular grammars cannot handle.
Consider the CFG with productions:
S → a S b | ε
What language does this grammar generate?
Look at how the production adds 'a' and 'b' in pairs recursively.
The grammar generates strings where each 'a' is matched by a corresponding 'b' later, ensuring equal numbers in the correct order.