text: Program to construct DFA for Regular Expression C ( A + B ) + | Function to find whether the given String is Accepted by the DFA ; If n <= 1 , then print No ; To count the matched characters ; Check if the first character is C ; Traverse the rest of String ; If character is A or B , increment count by 1 ; If the first character is not C , print - 1 ; If all characters matches ; Driver Code
code: function DFA ( str , N ) { if ( N <= 1 ) { document . write ( " " ) ; return ; } let count = 0 ; if ( str [ 0 ] == ' ' ) { count ++ ; for ( let i = 1 ; i < N ; i ++ ) { if ( str [ i ] == ' ' str [ i ] == ' ' ) count ++ ; else break ; } } else { document . write ( " " ) ; return ; } if ( count == N ) document . write ( " " ) ; else document . write ( " " ) ; } let str = " " ; let N = str . length ; DFA ( str , N ) ;