上下文无关语言
上下文无关语言 (Context-Free Languages)
定义 (Definition): 上下文无关语言是由上下文无关文法(CFG)生成的语言。CFG 是一种形式语法,其产生式的形式为 ,其中 是单个非终结符号, 是终结符号和非终结符号的序列。
Context-free languages are languages generated by context-free grammars (CFGs). A CFG is a type of formal grammar where the production rules have the form , where is a single non-terminal symbol, and is a sequence of terminal and non-terminal symbols.
例子 (Example)
假设有一个上下文无关文法 。这个文法生成的语言是 。
Consider a context-free grammar . The language generated by this grammar is .
上下文无关语言的封闭性 (Closure Properties of Context-Free Languages)
上下文无关语言在某些运算下是封闭的,包括并、连接和 Kleene 闭包,但不包括交和差。
Context-free languages are closed under certain operations, including union, concatenation, and Kleene closure, but not intersection and difference.
封闭性运算 (Closure Operations):
-
并 (Union): 如果 和 是上下文无关语言,则 也是上下文无关语言。
If and are context-free languages, then is also a context-free language.
-
连接 (Concatenation): 如果 和 是上下文无关语言,则 也是上下文无关语言。
If and are context-free languages, then is also a context-free language.
-
Kleene 闭包 (Kleene Closure): 如果 是上下文无关语言,则 也是上下文无关语言。
If is a context-free language, then is also a context-free language.