Generation and recognition of formal languages