Image for CFG (Context-Free Grammar)

CFG (Context-Free Grammar)

A Context-Free Grammar (CFG) is a set of rules used to describe the structure of a language, such as programming languages or natural language sentences. It consists of symbols (like words or characters) and rules (productions) that specify how symbols can be combined to form valid strings or sentences. These rules are "context-free" because they can be applied regardless of where they appear in a sequence. CFGs are fundamental in designing compilers, parsing languages, and understanding how complex patterns are generated and recognized systematically.