Image for context-free grammar (CFG)

context-free grammar (CFG)

A context-free grammar (CFG) is a set of rules used to generate sentences or structures in a language, such as programming languages or natural language syntax. It consists of symbols and production rules that describe how to form valid sentences from basic components, called non-terminals, which can be replaced by other symbols or groups of symbols. The term "context-free" means these rules apply universally, regardless of surrounding symbols. CFGs help in designing parsers that analyze whether sentences follow correct grammatical structure, aiding in language understanding, compilation, and processing tasks.