Transition diagram based lexical analyzer and finite automata
This presentation is the property of its rightful owner.
Sponsored Links
1 / 14

TRANSITION DIAGRAM BASED LEXICAL ANALYZER and FINITE AUTOMATA PowerPoint PPT Presentation


  • 101 Views
  • Uploaded on
  • Presentation posted in: General

TRANSITION DIAGRAM BASED LEXICAL ANALYZER and FINITE AUTOMATA. Class date : 12 August, 2013 Prepared by : Karimgailiu R Panmei Roll no. : 11CS10020 GROUP NO. : 9. State Transition Machine 1. Stream of input characters (source). State Transition Machine 2. Token.

Download Presentation

TRANSITION DIAGRAM BASED LEXICAL ANALYZER and FINITE AUTOMATA

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Transition diagram based lexical analyzer and finite automata

TRANSITION DIAGRAM BASED LEXICAL ANALYZERandFINITE AUTOMATA

Class date : 12 August, 2013

Prepared by : Karimgailiu R Panmei

Roll no. : 11CS10020

GROUP NO. : 9


Transition diagram based lexical analyzer and finite automata

State Transition Machine 1

Stream of input characters (source)

State Transition Machine 2

Token

State Transition Machine 3

Lex Compiler

pattern1 pattern 2 pattern 3


Transition diagram based lexical analyzer and finite automata

Simulating the transition machines :

Input string : x1,x2 ,x3 …… 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


Transition diagram based lexical analyzer and finite automata

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


Transition diagram based lexical analyzer and finite automata

Approach 2 :

Parallel simulation

  • Simulate all transition diagrams in parallel

  • The machine stops when no match is found


Transition diagram based lexical analyzer and finite automata

Lex compiler

generate state transition machines

NFA : Advantage

Pattern : Define based on regular expression

Pattern

C Compiler

a.out

tokens

Source code

a.out

DFA : advantage


Transition diagram based lexical analyzer and finite automata

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)


Transition diagram based lexical analyzer and finite automata

NFA

Definition :

N={ Σ, S, so , F, Δ}

where

Σ : set of input symbol

S : finite set of states

so : start state

F : finite set of final states

Δ : transition function (S × Σ → P(S))

where P(S) is the power set of S


More about nfa

More about NFA

  • Given an input a, NFA allows to go from one state to a multiple state

    a

    a

  • ϵ-transition is allowed

    ϵ


Transition diagram based lexical analyzer and finite automata

DFA

Definition :

D={ Σ, S, so , f, δ}

where

Σ : set of input symbol

S : finite set of states

so : start state

F : finite set of final states

δ : transition function (δ : S × Σ → S)


More on dfa

More on DFA

  • No ϵ-transition is allowed

  • For a given input a, DFA allows to moves from one state to a single state

    a


Simulating dfa

Simulating DFA

Input :

- a string x

- DFA with start state so , accepting

states F and transition function

detect

Output :

“yes” if accepts and “no” if rejects


Transition diagram based lexical analyzer and finite automata

Algorithm :

s=so ;

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;


Transition diagram based lexical analyzer and finite automata

THE END


  • Login