Course Hero Logo

NFA.docx - 170801094 Ex.no: CONSTRUCTION OF NFA FOR A GIVEN...

This preview shows page 1 - 2 out of 4 pages.

170801094Ex.no:CONSTRUCTION OF NFA FOR A GIVEN REGULAR EXPRESSIONDate:AIM:To write a c program to construct a NFA for a given regular expression.ALGORITHM:1.Declare a struct called node with node_no, a_count, b_count and node pointersnexta, nextb and nextnode.2.Declare a static variable nodecount.3.Get the regular expression from the user.4.Check each character in the regular expression until the last is reached.5.If the character is ‘(‘, parse the regex till ‘)’ is encountered. If the character is‘a’, assign p->nexta=p and increment a_count. Do the same for ‘b’6.If the character is *, loop the state to itself.7.If the character is ‘a’ or ‘b’, define a new state by creating a temp node andassign the respective pointers.8.Increment the ‘nodecount’ value everytime a new node is created.9.Print the transition table. For each state, print the next states for ‘a’ and ‘b’inputs.10.Stop.CODE:#include<stdio.h>#include<string.h>#include<stdlib.h>int nodecount=0;struct node{struct node *next_node;int node_no;

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 4 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
NoProfessor
Tags
Regular expression, Nondeterministic finite state machine, char c

Newly uploaded documents

Show More

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture