REGULAR EXPRESSION TO N.F.A

Post on 24-May-2015

775 views 1 download

description

REGULAR EXPRESSION TO N.F.A

Transcript of REGULAR EXPRESSION TO N.F.A

Compiler Design Assg.

Regular Expression to N.F.A.

-Devashish

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.

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.

Thompson-Yamada Construction Algo.

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

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[]

Thank You...