Formal Languages & Automata A formal language: Is an abstraction of the general characteristics of programming languages.. Formal Languages & Automata An automaton: Is a construction
Trang 1Automata and formal language
Dr Huỳnh Trung Hiếu Faculty of Information Technology HoChiMinh City University of Industry
Trang 3Formal Languages & Automata
A formal language:
Is an abstraction of the general characteristics of programming languages.
Consists of a set of symbols and some formation rules by which these symbols can be
combined into sentences
Trang 4Formal Languages & Automata
An automaton:
Is a construction that possesses all the indispensable features of a digital computer.
Accepts input, produces output, may have some temporary storage, and can make
decisions in transforming the input into the output
Trang 6 Introduction to automata theory, languages, and computation.
John Hopcroft & Jeffrey Ullman
Trang 7Mục tiêu môn học
Xây dựng mô hình trừu tượng cho máy tính.
Lý thuyết cung cấp cho chúng ta những khái niệm giúp ta đi đến những ứng dụng như :
Thiết kế kỹ thuật số.
Ngôn ngữ lập trình.
Trình biên dịch.
Nhận dạng ngôn ngữ,….
Trang 8Nội dung môn học
Phần 3: Ngôn ngữ và văn phạm chính quy.
Trang 9GiỚI THIỆU KHÁI NiỆM, DẪN NHẬP
Trang 11Languages
Là một hệ thống thích hợp nhằm để diễn tả những ý kiến, sự kiện, khái niệm chắc
chắn Chúng bao gồm tập hợp các ký hiệu và quy luật
Trang 14Languages
Example 1:
Σ = {a, b}
Σ* = {λ, a, b, aa, ab, ba, aaa, }
L1 = {a, aa, aab} (finite language)
L2 = {anbn | n ≥ 0} = {λ, ab, aabb, }
Các chuỗi aabb, aaaabbbb là các từ trên ngôn ngữ L2, nhưng chuỗi abb thì không.
Trang 18<noun> → boy | dog
<verb> → runs | walks
khi đó ta có những câu như: "a boy runs" và "the dog walks" là có
"dạng đúng" có nghĩa là được sinh
ra từ văn phạm trên
Trang 19Grammars
Formal grammar:
G = (V, T, S, P) V: finite set of variables (tập biến)
T: finite set of terminal symbols (tập ký hiệu kết thúc)
S ∈ V: start variable (tập biến bắt đầu)
P: finite set of productions (luật sinh)
Trang 21Grammars
Generated language:
Cho G = (V, T, S, P) là 1 văn phạm thì tập:
L(G) = {w∈T* | S ⇒* w} là ngôn ngữ được sinh ra bởi G
Derivation: nếu w∈L(G) thì tồn tại dẫn xuất:
S ⇒ w1 ⇒ w2 ⇒ ⇒ wn ⇒ w
Sentential forms: S, w1, w2, , wn (containing variables)
Trang 22Grammars
Example 3:
G = ({S}, {a, b}, S, P)P: S → aSb
S → λ
S ⇒ aSb ⇒ aaSbb ⇒ aabb
aabb: sentence aaSbb: sentential form
Trang 23Grammars
Example 3:
G = ({S}, {a, b}, S, P)P: S → aSb
S → λ
L(G) = {anbn | n ≥ 0}
Trang 25Grammars
Example 4:
G1 = ({A, S}, {a, b}, S, P1)P1: S → aAb | λ
A → aAb | λ
L(G1) = {anbn | n ≥ 0}
G and G1 are equivalent
Trang 26 Để chỉ ra một ngôn ngữ L được sinh ra bởi một văn phạm G Chúng ta cần chỉ ra:
a) mỗi w ∈ L được dẫn ra từ S bằng các luật sinh của văn phạm G.
b) mỗi w như ở (a) phải thuộc L.
Trang 27A → aAb
A → λ
Trang 28Grammars
Example 5:
G2 = ({S}, {a, b}, S, P2)P2: S → SS
S → λ
S → aSb
S → bSa
=>L(G2) = {w | na(w) = nb(w)}
Trang 29Automata
An abstract model of digital computer:
Control unit Input file
Output
Storage
Trang 30Automata
Input file: is divided into squares
Input is a string over a given alphabet.
Each input square holds a symbol.
The symbols are read from left to right, one at a time.
The end of the input string can be detected.
Trang 31Automata
Storage: consists of an unlimited number of cells
Each cell can hold a symbol from an alphabet (which can be different from the input
alphabet)
The contents of the storage cells can be read and changed.
Trang 32Automata
Control unit: has a finite number of internal states
Can be in any one of the internal states.
Can change state in some defined manner.
Trang 33Automata
Transition function:
current state × input symbol × storage info → next state
Output may be produced Info in the storage may be changed
Configuration: current state × input symbol × storage info
Move: current configuration → next configuration
Trang 34Transducer: string of symbols as output