REGULAR EXPRESSION TO N.F.A

7
Compiler Design Assg. Regular Expression to N.F.A. -Devashish

description

REGULAR EXPRESSION TO N.F.A

Transcript of REGULAR EXPRESSION TO N.F.A

Page 1: REGULAR EXPRESSION TO N.F.A

Compiler Design Assg.

Regular Expression to N.F.A.

-Devashish

Page 2: REGULAR EXPRESSION TO N.F.A

Regular Expressionthe following operations over them are defined to

produce regular expressions:

• (concatenation) RS denoting the set { | in set described by αβ αexpression R and in set described by β S }. For example {"ab", "c"}{"d", "ef"} = {"abd", "abef", "cd", "cef"}.

• (alternation) R | S denoting the set union of sets described by R and S. For example, if R describes {"ab", "c"} and S describes {"ab", "d", "ef"}, expression R | S describes {"ab", "c", "d", "ef"}.

• (Kleene star) R* denoting the smallest superset of set described by R that contains and is ε closed under string concatenation. This is the set of all strings that can be made by concatenating any finite number (including zero) of strings from set described by R.

Page 3: REGULAR EXPRESSION TO N.F.A

Nondeterministic Finite Automaton

An NFA is represented formally by a 5-tuple, (Q, Σ, Δ, q0, F), consisting of:

• a finite set of states Q• a finite set of input symbols Σ• a transition relation  : Δ Q × → Σ P(Q).• an initial (or start) state q0 ∈ Q

• a set of states F distinguished as accepting (or final) states F ⊆ Q.

Page 4: REGULAR EXPRESSION TO N.F.A

Thompson-Yamada Construction Algo.

Page 5: REGULAR EXPRESSION TO N.F.A

Code Prototypechar in [SIZE]//a character array to store the evaluated postfix expression

int out [SIZE][3]

//an output 2-d array which stores the transition information

int stack [n]//an integer array used for evaluating postfix expression

Page 6: REGULAR EXPRESSION TO N.F.A

Primary Functions Usedvoid convert (char infix[], char postfix[])

// converting Infix expr. to Postfix expr.

int precedence (int symbol)// checking the precedence of operator (* . +)

void nfa ()// evaluating postfix expr. And storing resultant N.F.A. in out[]

Page 7: REGULAR EXPRESSION TO N.F.A

Thank You...