词法分析部分总结.pptVIP

  • 20
  • 0
  • 约 80页
  • 2017-08-19 发布于北京
  • 举报
词法分析部分总结 田 聪 构造词法分析器的一般方法和步骤 描述:用正规式对模式进行描述; 构造NFA:为每个正规式构造一个NFA; 确定化:将NFA转换成等价的DFA; 最小化:优化DFA,使其状态数最少; 构造词法分析器:由DFA构造词法分析器(表驱动,直接编码,LEX)。 涉及到的形式化概念 正则表达式(正规式) NFA DFA 正则语言 正则语言 正则语言 正则表达式 有限状态自动机 上下文无关语言 上下文无关文法 非确定的下推自动机 上下文有关语言 上下文有关文法 线性有界自动机(特殊的图灵机) 递归可枚举语言 短语结构 图灵机 Algebraic Laws for RE’s Union and concatenation behave like addition and multiplication. + is commutative (可交换的) and associative (可结合的) a+b=b+a, a+b+c= a+(b+c) concatenation is associative (可结合的) a.b.c=a.(b.c) Concatenation distributes over +(可分配的) a.(b+c)=a.b+a.c Exception: Concatenation is not commutative (可交换的) a.b ≠b.a Identities and Annihilators ? is the identity (单位元) for +. R + ? = R. ε is the identity (单位元) for concatenation. εR = Rε = R. ? is the annihilator (零元) for concatenation. ?R = R? = ?. 正则语言相关内容 如何证明正则表达式和NFA的等价性? (1)We need to show that for every RE, there is an automaton that accepts the same language. (2)And for every automaton, there is a RE defining its language. RE to ε-NFA: Basis Symbol a: ε: RE to ε-NFA: Induction 1 – Union RE to ε-NFA: Induction 2 – Concatenation RE to ε-NFA: Induction 3 – Closure 正则语言相关内容 如何证明正则表达式和NFA的等价性? (1)We need to show that for every RE, there is an automaton that accepts the same language. (2)And for every automaton, there is a RE defining its language. From Automata to RE Arden’s rule For any sets of strings S and T, the equation X=SX+T has X=S*T as a solution. Moreover, this solution is unique if ε not in S. From Automata to RE Given an automaton A A has states {q0, …, qn} with q0 being the start state Let Xi denote the set of strings accepted by A starting in state qi Thus, L(A)=X0 We can write an equation for each Xi, defining it in terms of the sets corresponding to its successor states. From Automata to RE From Automata to RE DFA-to-RE Another approach Page 93, theorem 3.4. (形式语言与自动机) Induction on k-path. Decision Properties of Regular Languages Properties of Language Classes A language class is a set of languages. We have on

文档评论(0)

1亿VIP精品文档

相关文档