Generating NFA from regex