Create a NFA from BNF grammar

68 Views Asked by At

How do I create an NFA from BNF grammar?

What I am specifically stuck on is the fact when we have two cases of recursion in the grammar such as in:

< case > ::= < case > < int > 'b' | 'b'

The 'b' part does not make for an easy transition.

I am new to this, would be very thankful for help.

1

There are 1 best solutions below

0
tangyao On
  if you think about the token sequence that bnf can generate
 the corresponding regular expresion is    <'b'>(<int><'b'>)*
    so the NFA is:   -> 'b' -> end
                         |
                          -> <int> -> 'b' -> end
                         |             |
                          --------------