Last Lecture Revisited

Slides:



Advertisements
Similar presentations
Chapter 2 Combinatorial Analysis 主講人 : 虞台文. Content Basic Procedure for Probability Calculation Counting – Ordered Samples with Replacement – Ordered.
Advertisements

College English Unit 2 Contents Revision Cultural Introduction New Lesson Vocabulary Games Acting Dialogues Exercises.
第 2 章 初探 C++.
Memory Pool ACM Yanqing Peng.
Java Programming Hygiene - for DIDC
编译原理上机实习
编 译 原 理 指导教师:杨建国 二零一零年三月.
-Artificial Neural Network- Hopfield Neural Network(HNN) 朝陽科技大學 資訊管理系 李麗華 教授.
程設一.
Unit 5 Dialogues Detailed Study of Dialogues (对话) Exercises(练习)
Welcome Welcome to my class Welcome to my class!.
深層學習 暑期訓練 (2017).
Minimum Spanning Trees
Period 2 Unit 2 Where’s the post office? Section A 1b 2b 3a 3b
Operators and Expressions
CH1 Number Systems and Conversion
Module 5 Shopping 第2课时.
! 温故知新 上下文无关文法 最左推导 最右推导 自上而下 自下而上 句柄 归约 移进-归约冲突 移进-归约分析 递归下降预测分析
组合逻辑 刘鹏 Mar. 17, 2015 浙江大学 信息与电子工程系
2.2 语法分析器生成器YACC 分析器的构造步骤: 产生式→识别活前缀的DFA→分析表(+驱动器) YACC概述
樹狀結構 陳怡芬 2018/11/16 北一女中資訊專題研究.
C 程式設計— 語言簡介 台大資訊工程學系 資訊系統訓練班.
Last Lecture Revisited
Lexical analyzer generator
Guide to Freshman Life Prepared by Sam Wu.
编译原理与技术 词法分析(1) 2018/11/28 《编译原理与技术》讲义.
Course 9 NP Theory序論 An Introduction to the Theory of NP
C++ 程式設計— 語言簡介 台大資訊工程學系 資訊系統訓練班.
C 語言簡介 - 2.
第三章 词法分析.
主讲人: 吕敏 { } Spring 2016,USTC 算法基础 主讲人: 吕敏 { } Spring 2016,USTC.
第2次课 上下文无关文法
第七章常見的演算法 目的:解決問題 遞迴演算法 (一)從程式語言的角度來看:就是程序自 己呼叫自己的情況。
编译原理与技术 词法分析 (2) 2018/12/30 《编译原理与技术》讲义.
重點 資料結構之選定會影響演算法 選擇對的資料結構讓您上天堂 程式.
Formal Pivot to both Language and Intelligence in Science
本章中將會更詳細地考慮有關重複的概念,並且會 介紹for和do…while等兩種用來控制重複的敘述 式。 也將會介紹switch多重選擇敘述式。 我們會討論直接和迅速離開某種控制敘述式的 break敘述式,以及用來跳過重複敘述式本體剩餘 部份的continue敘述式。 本章會討論用來組合控制條件的邏輯運算子,最後.
Section B 2b–3b & Self Check
语法分析 本章内容 语法分析器:把词法分析生成的词法单元流翻译成语法分析树(parse tree)
第十五课:在医院看病.
句子成分的省略(1).
Chapter 5 Recursion.
Chp.4 The Discount Factor
第二章 词法分析4 词法分析程序实现 构造词法分析器步骤 单词的形式化描述 词法分析程序的实现.
成品检查报告 Inspection Report
Have you read Treasure Island yet?
每周三交作业,作业成绩占总成绩的15%; 平时不定期的进行小测验,占总成绩的 15%;
在Microsoft Access 下 建立資料庫
Chp.4 The Discount Factor
软件工程 第四章 软件设计 软件过程设计技术与工具.
中央社新聞— <LTTC:台灣學生英語聽說提升 讀寫相對下降>
Instructor:Po-Yu Kuo 教師:郭柏佑
计算机问题求解 – 论题2-1 - 算法的正确性 2018年3月7日.
Chp.4 The Discount Factor
精品学习网---初中频道 海量同步课件、同步备考、同步试题等资源免费下载!
计算机问题求解 – 论题1-5 - 数据与数据结构 2018年10月16日.
冀教版 九年级 Lesson 20: Say It in Five.
李宏毅專題 Track A, B, C 的時間、地點開學前通知
Create and Use the Authorization Objects in ABAP
计算机问题求解 – 论题 图的连通度 2018年11月13日.
5. Combinational Logic Analysis
雲端計算.
2 Number Systems, Operations, and Codes
怎樣把同一評估 給與在不同班級的學生 How to administer the Same assessment to students from Different classes and groups.
Arguments to the main Function and Final Project
Introduction to Computer Security and Cryptography
编译原理 第一章 编译程序概述 第二章 PL/0编译程序的实现 第三章 文法和语言 第四章 词法分析 第五章 自顶向下语法分析方法
Gaussian Process Ruohua Shi Meeting
When using opening and closing presentation slides, use the masterbrand logo at the correct size and in the right position. This slide meets both needs.
Presentation transcript:

Last Lecture Revisited State transition graph Source Code String Stream Combination Lexical Units Tokens Pattern Name Non-formalization description Formalization description Computer realization ? Regular expression Letters Combination String Language Set Alphabet Table Plus LUM Conjunction LM Closure L* Positive closure L+ conjunction exponent

2.2 The description and recognition of lexical tokens 2.2.4 Convention  Relational operator convention relop  < | < = | = | < > | > | > =   5 1 6 2 4 8 3 7 return(relop, LE) return(relop, NE) return(relop, LT) return(relop, GE) return(relop, GT) return(relop, EQ) Start < = > * other

Convention of Identifiers and reserved words id  letter (letter | digit )* 9 10 11 Start letter other * letter or digit return(install_id( )) 1、To check the reserved words. If any, return the corresponding token. if none, goto 2. 2、To look for the identifiers. If the unit is there, return the pointer. If not, goto 3. 3、To add the lexical unit in a new item to the identifier set, and return the pointer.

Convention of the unsigned integer num  digit+ (.digit+)? (E (+ | )? digit+)? Start 19 12 13 14 15 16 17 18 digit other . E +/ return( install_num( ) ) *

BLANK Convention delim  blank | tab | newline ws  delim+ 21 22 Start delim other * 20

? 2.3 The finite automation State convention graph Regular expression Computer realization Equivalence The finite automation Deterministic finite automaton Nondeterministic finite automaton

2.3.1 The nondeterministic finite automaton (NFA) The Corresponding mathematic models State set S; Input identifier set ; Convention function move : S  ({})  P(S); S0 = Starting point; F  S which is the accepted state set Drawbacks: 1 Input identifiers includes . 2 One state may have several output edges. 1 2 Start a b Language Recognition (a|b)*ab NFA

NFA Convention Input Identifiers a b {0, 1} {0} 1  {2} 2 States 1 2 {0, 1} {0} 1  {2} 2 States 1 2 Start a b Language Recognition (a|b)*ab NFA

The NFA to recognize aa*|bb* 1 2 Start a b 3 4 

2.3.2 The deterministic finite automaton (DFA) The Corresponding mathematic models: State set S; Input identifier set ; Convention function move : S    S; The unique starting point s S; Final states F  S; Advantages: 1 Input identifiers do not include . 2 One state has only one output edge. 1 2 Start a b Language Recognition (a|b)*ab DFA

Subset Construction Method: 2.3.3 From NFA to DFA Subset Construction Method: One state in DFA corresponds with one state set in NFA When got the input a1 a2 … an, NFA can reach the states: s1, s2, …, sk, and DFA can reach {s1, s2, …, sk} 1 2 Start a b

Inputs a b States 1 9 Start  a b 6 7 8 2 3 4 5

Inputs a b A A = {0, 1, 2, 4, 7} States 1 9 Start  a b 6 7 8 2 3 4 5

Inputs a b A B A = {0, 1, 2, 4, 7} B = {1, 2, 3, 4, 6, 7, 8} States 1 9 Start  a b 6 7 8 2 3 4 5

Inputs a b A B A = {0, 1, 2, 4, 7} B = {1, 2, 3, 4, 6, 7, 8} States 1 9 Start  a b 6 7 8 2 3 4 5

Inputs a b A B C A = {0, 1, 2, 4, 7} B = {1, 2, 3, 4, 6, 7, 8} C = {1, 2, 4, 5, 6, 7} States 1 9 Start  a b 6 7 8 2 3 4 5

Inputs a b A B C A = {0, 1, 2, 4, 7} B = {1, 2, 3, 4, 6, 7, 8} C = {1, 2, 4, 5, 6, 7} States 1 9 Start  a b 6 7 8 2 3 4 5

Inputs a b A B C A = {0, 1, 2, 4, 7} B = {1, 2, 3, 4, 6, 7, 8} C = {1, 2, 4, 5, 6, 7} States 1 9 Start  a b 6 7 8 2 3 4 5

Inputs a b A B C D A = {0, 1, 2, 4, 7} B = {1, 2, 3, 4, 6, 7, 8} States 1 9 Start  a b 6 7 8 2 3 4 5

Inputs a b A B C D A = {0, 1, 2, 4, 7} B = {1, 2, 3, 4, 6, 7, 8} States 1 9 Start  a b 6 7 8 2 3 4 5

Inputs a b A B C D A = {0, 1, 2, 4, 7} B = {1, 2, 3, 4, 6, 7, 8} States 1 9 Start  a b 6 7 8 2 3 4 5

Inputs a b A B C D A = {0, 1, 2, 4, 7} B = {1, 2, 3, 4, 6, 7, 8} States 1 9 Start  a b 6 7 8 2 3 4 5

Inputs a b A B C D States 从转换表构造转换图。 B D Start a A b C 1 9 Start  a b a b 6 7 8 2 3 4 5 从转换表构造转换图。 23

1 2 Start a b B D Start a A b C 1 9 Start  a b 6 7 8 2 3 4 5 Language b Language Recognition (a|b)*ab Automaton B D Start a A b C 1 9 Start  a b 6 7 8 2 3 4 5 将前面的DFA和现在的DFA进行比较,引出DFA化简问题。 24

1 2 Start a b B D Start a A b C 1 2 Start a b 1 9 Start  a b 6 7 8 2 Language Recognition (a|b)*ab Automaton 1 2 Start a b B D Start a A b C 1 2 Start a b 1 9 Start  a b 6 7 8 2 3 4 5 将手工构造的NFA和由算法构造的NFA进行比较,鼓励在掌握算法的同时,学会手工构造简单的DFA。 25

2.3.4 DFA Simplification The dead state B D Start a A b a, b C E B D Remain the LEFT and put the dead state E to the RIGHT B D Start a A b a, b C E B D Start a A b C

A and B are distinguishable States A and C are undistinguishable States B D Start a A b C

Method: 1. {A, B, C}, {D} move({A, B, C}, a} = {B} move({A, B, C}, b} = {C, D} 2. {A, C}, {B}, {D} move({A, C}, a} = {B} move({A, C}, b} = {C} B D Start a A b C

Method: 1. {A, B, C}, {D} move({A, B, C}, a} = {B} 2 Start a b Method: 1. {A, B, C}, {D} move({A, B, C}, a} = {B} move({A, B, C}, b} = {C, D} 2. {A, C}, {B}, {D} move({A, C}, a} = {B} move({A, C}, b} = {C} B D Start a A b C

2.4 From the regular expression to the finite automaton State convention graph Computer realization ? Equivalence The finite automation Deterministic finite automaton Nondeterministic finite automaton Content of this class

NFA to recognize  NFA to recognize a Construct the NFA to recognize  and one symbol i Start  NFA to recognize  a f NFA to recognize a

N (s)  Start f i N (t) NFA to recognize s | t Construct the NFA to recognize the main operators as the selection  f i Start NFA to recognize s | t N (s) N (t)

Start N (s) N (t) i f NFA to recognize st Construct the NFA to recognize the main operators as the conjunction i N (s) f Start NFA to recognize st N (t)

Start  N (s) i f NFA to recognize s* Construct the NFA to recognize the main operators as the closure N (s) f Start NFA to recognize s* i 

For (s), we take N(s) as its NFA.

The NFA of this method has the following attributes: The max number of states of N(r) is twice as many as the number of symbols and operators in r. N(r) has only one start state and one accepted state,and the accepted state has no convention outwards Every state in N(r) has a convention with  pointing to another state or two conventions of  pointing to another state.

The decomposition of (a|b)*ab r9 r7 r8 r4 r3 r5 r6 * ) ( r2 r1 a | b The decomposition of (a|b)*ab 1 9 Start  a b 6 7 8 2 3 4 5

The decomposition of (a|b)*ab 1 9 Start  a b 6 7 8 2 3 4 5 r9 r7 r8 r4 r3 r5 r6 * ) ( r2 r1 | The decomposition of (a|b)*ab

The decomposition of (a|b)*ab  1 9 Start a b 6 7 8 2 3 4 5 r9 r7 r8 r4 r3 r5 r6 * ) ( r2 r1 | The decomposition of (a|b)*ab

The decomposition of (a|b)*ab 1 9 Start  a b 6 7 8 2 3 4 5 r9 r7 r8 r4 r3 r5 r6 * ) ( r2 r1 | The decomposition of (a|b)*ab

The decomposition of (a|b)*ab 1 9 Start  a b 6 7 8 2 3 4 5 r9 r7 r8 r4 r3 r5 r6 * ) ( r2 r1 | The decomposition of (a|b)*ab

The decomposition of (a|b)*ab 1 9 Start  a b 6 7 8 2 3 4 5 r9 r7 r8 r4 r3 r5 r6 * ) ( r2 r1 | The decomposition of (a|b)*ab

The decomposition of (a|b)*ab 1 9 Start  a b 6 7 8 2 3 4 5 r9 r7 r8 r4 r3 r5 r6 * ) ( r2 r1 | The decomposition of (a|b)*ab

The comparison of the two NFA on (a|b)*ab 1 2 Start a b 1 9 Start  a b 6 7 8 2 3 4 5 比较手工构造的NFA和用教材上语法制导的算法构造的NFA。鼓励学生写出引入尽可能少的 转换的语法制导的算法,在将来的解题中使用这个算法。 44

Appendix : From language to the deterministic finite automaton Example: To find the binary digits divisible by 5 in  ={0,1} Method: 1 List all possible states. 2 Construct the edges and input tokens on every state. 1 2 3 Start 4 《编译原理习题精选》1.5题。 45

Example: To find the binary digits divisible by 5 in  ={0,1} 1 2 3 Start 4

1 2 3 Start 4

1 2 3 Start 4

1 2 3 Start 4

1 2 3 Start 4

1 2 3 Start 4

1 2 3 Start 4

1 2 3 Start 4

1 2 3 Start 4

1 2 3 Start 4

1 2 3 Start 4

Summary State convention graph Regular expression Equivalence Computer realization Regular expression grammar Equivalence Equivalence Subset construction Nondeterministic finite automaton Deterministic finite automaton Minimalist deterministic finite automaton Combining the undistinguishable states Deterministic finite automaton Language Sate enumeration method

习 题 2.7 (c) (d), 2.8 ( 仅为2.7(c) ), 2.12(a) 练习:构造 DFA,接受 0和1的个数都是偶数的二进制串。 eg: 0011, 00, 1100, 1010, 111100