Download presentation
Presentation is loading. Please wait.
Published byKerry Riley Modified over 9 years ago
1
TRANSITION DIAGRAM BASED LEXICAL ANALYZER and FINITE AUTOMATA Class date : 12 August, 2013 Prepared by : Karimgailiu R Panmei Roll no. : 11CS10020 GROUP NO. : 9
2
Stream of input characters (source) State Transition Machine 1 State Transition Machine 2 State Transition Machine 3 Token Lex Compiler pattern1 pattern 2 pattern 3
3
Simulating the transition machines : Input string : x 1, x 2,x 3 …… x n Scan the input using forward pointer Machine accepts or rejects based on the transition function Match the longest prefix of the input If accepted, token is produced
4
Two approach to simulate the machine : Approach 1 : Sequential simulation Sequentially simulate the transition machines If the previous machine fails, reset the forward pointer Start the next transition machine
5
Approach 2 : Parallel simulation Simulate all transition diagrams in parallel The machine stops when no match is found
6
Pattern : Define based on regular expression Lex compiler C Compiler a.out Pattern a.out Source code tokens generate state transition machines NFA : Advantage DFA : advantage
7
FINITE AUTOMATA Recognize regular languages Accepts or rejects a possible input string Two types : 1. Non deterministic finite automata(NFA) 2. Deterministic finite automata(DFA)
8
NFA Definition : N={ Σ, S, s o, F, Δ } where Σ : set of input symbol S : finite set of states s o : start state F : finite set of final states Δ : transition function (S × Σ → P(S)) where P(S) is the power set of S
9
More about NFA Given an input a, NFA allows to go from one state to a multiple state a ϵ-transition is allowed ϵ
10
DFA Definition : D={ Σ, S, s o, f, δ } where Σ : set of input symbol S : finite set of states s o : start state F : finite set of final states δ : transition function (δ : S × Σ → S)
11
More on DFA No ϵ-transition is allowed For a given input a, DFA allows to moves from one state to a single state a
12
Simulating DFA Input : - a string x - DFA with start state s o, accepting states F and transition function detect Output : “yes” if accepts and “no” if rejects
13
Algorithm : s= s o ; c= read_next_char(); //read_next_char() returns the next //character while(c!=‘\0’) { s=detect(s,c); c=read_next_char(); } if(s ϵ F) return yes; else return no;
14
THE END
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.