简体   繁体   English

正则表达式和语法自由上下文转换

[英]Regex and grammar free context conversion

Can the following CFG be converted to a Regex?可以将以下 CFG 转换为正则表达式吗?

在此处输入图像描述

Someone said that this could be it regex: (ab* a + b)*有人说这可能是正则表达式:(ab* a + b)*

is this true and why?这是真的吗?为什么? I cant seem to understand it我似乎无法理解

It's not a regular language.它不是一种常规语言。

Consider the subset of the language with exactly one b .考虑恰好有一个b的语言子集。 (In other words, the intersection of the language with a*ba* .) If the language were regular, that subset would also be regular, since it would be the intersection of two regular languages. (换句话说,语言与a*ba*的交集。)如果语言是正则的,则该子集也将是正则的,因为它将是两种常规语言的交集。

But it's not regular, since it consists of strings in which the number of a s following the b is at least as large as the number of a s preceding the b , and that is not a regular language ("regular languages can't count").但它不是规则的,因为它由字符串组成,其中b之后的a s 的数量至少与b之前的a s 的数量一样大,并且这不是常规语言(“常规语言不能计数”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM