我正在尝试为L =字符串集写一个无上下文语法,其中1的数字比0的数字多一个。因此,1011010,0001111等在L中,但001101,000011等字符串不在L中。
到目前为止,我有一个无上下文语法,L =一组字符串,其中1的数字大于0:
S→TS | 1T | 1S
T→TT | 0T1 | 1T0 |ε
如何更改此项以使1的数量仅比0的数量多1?
答案 0 :(得分:1)
根据templatetypedef的答案,您可以在https://math.stackexchange.com/questions/2207708/context-free-grammar-for-language-a-b-where-the-number-of-as-the-number上找到这样的语法
所以最终的语法基本上是:
group = "com.github.imflog"
version = "0.10.0-SNAPSHOT"
plugins {
kotlin("jvm").version("1.3.71")
id("java-gradle-plugin")
id("com.gradle.plugin-publish") version "0.11.0"
id("maven-publish")
id("com.github.ben-manes.versions") version "0.28.0"
}
repositories {
jcenter()
mavenCentral()
maven("http://packages.confluent.io/maven/")
}
java {
withSourcesJar()
}
// Dependencies versions
val confluentVersion = "5.4.1"
val avroVersion = "1.8.2"
dependencies {
implementation(gradleApi())
implementation(kotlin("stdlib"))
implementation("io.confluent", "kafka-schema-registry", confluentVersion) {
exclude("org.slf4j", "slf4j-log4j12")
}
}
// Test versions
val junitVersion = "5.6.1"
val mockkVersion = "1.9.3"
val wiremockVersion = "2.26.3"
val assertJVersion = "3.15.0"
dependencies {
testImplementation(gradleTestKit())
testImplementation("org.junit.jupiter", "junit-jupiter-api", junitVersion)
testImplementation("org.junit.jupiter", "junit-jupiter-engine", junitVersion)
testImplementation("org.assertj", "assertj-core", assertJVersion)
testImplementation("io.mockk", "mockk", mockkVersion)
testImplementation("com.github.tomakehurst", "wiremock-jre8", wiremockVersion)
}
tasks.withType<Test> {
useJUnitPlatform()
}
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/ImFlog/schema-registry-plugin")
credentials {
username = System.getenv("GITHUB_USERNAME")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}
val registryPluginName = "com.github.imflog.kafka-schema-registry-gradle-plugin"
gradlePlugin {
plugins {
create("schema-registry") {
id = registryPluginName
description = "A plugin to download, register and test schemas from a Kafka Schema Registry"
displayName = "Kafka schema registry gradle plugin"
version = version
implementationClass = "com.github.imflog.schema.registry.SchemaRegistryPlugin"
}
}
}
pluginBundle {
website = "https://github.com/ImFlog/schema-registry-plugin"
vcsUrl = "https://github.com/ImFlog/schema-registry-plugin.git"
tags = listOf("schema", "registry", "schema-registry", "kafka")
}
答案 1 :(得分:0)
作为提示,如果你的字符串只有一个1而不是0,那么有一些方法可以将它写成w1x,其中w和x具有完全相同的0和1。如果您可以找到一个CFG,它生成具有相同数字的0和1且带有起始符号X的字符串,那么您可以添加一个起始符号S和生产S→X1X,您应该很高兴。
答案 2 :(得分:0)
考虑:
S → T1T
T → 10T | 01T | 0T1 | 1T0 | ε
然后,您从一个1 (S → T1T)
开始,并在0's
的每个应用程序中始终添加相同数量的1's
和T
(以任何可能的方式)。