A context-free grammar is a 4-tuple
-
$$V$$ is a finite set called the variables, -
$$\Sigma$$ is a finite set, disjoint from$$V$$ , called the terminals, -
$$R$$ is a finite set of rules, with each rule being a variable and a string of variables and terminals, and -
$$S\in V$$ is the start variable
记号
- 单步推导(yield)$$uAv\Rightarrow uwv$$
- 任意步推导(derive)$$u\Rightarrow^v$$. 并产生一棵parse tree*
A launguage is called a context-free launguage if it can be generated by a CFG.
CFL=L(CFG)
合并、正则、匹配、递归
{CFLs}对$$\cup$$封闭
是一个创作过程
A string
Grammar
固有歧义性:有些context-free language只能被ambiguous CFG产生,比如$${a^ib^jc^k|i=j$$ or
$$j=k}$$
A context-free grammar is in Chomsky normal form if every rule is of the form
其中$$a$$是terminal,$$A,B,C$$是variables,$$B,C$$不是start variable
Any context-free language is generated by a CFG in Chomsky normal form.
证明方法:构造法,提供了一套把任意CFG改写成等价Chomsky normal form的流程。
这样理解:Parse tree可以有等价的二叉树