惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

O
OpenAI News
Microsoft Azure Blog
Microsoft Azure Blog
量子位
T
The Blog of Author Tim Ferriss
Vercel News
Vercel News
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
Y
Y Combinator Blog
阮一峰的网络日志
阮一峰的网络日志
V
V2EX
GbyAI
GbyAI
The Cloudflare Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
博客园 - 叶小钗
L
LINUX DO - 最新话题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks
Attack and Defense Labs
Attack and Defense Labs
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Darknet – Hacking Tools, Hacker News & Cyber Security
IT之家
IT之家
Schneier on Security
Schneier on Security
Scott Helme
Scott Helme
L
Lohrmann on Cybersecurity
Hacker News - Newest:
Hacker News - Newest: "LLM"
G
GRAHAM CLULEY
P
Proofpoint News Feed
Blog — PlanetScale
Blog — PlanetScale
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
H
Heimdal Security Blog
L
LINUX DO - 热门话题
S
Security @ Cisco Blogs
F
Fortinet All Blogs
Webroot Blog
Webroot Blog
腾讯CDC
H
Hacker News: Front Page
The Last Watchdog
The Last Watchdog
A
About on SuperTechFans
大猫的无限游戏
大猫的无限游戏
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
云风的 BLOG
云风的 BLOG
D
DataBreaches.Net
The GitHub Blog
The GitHub Blog
T
Threat Research - Cisco Blogs
C
Cisco Blogs
T
Threatpost
S
Secure Thoughts

Victrid's Personal Site

斯普拉遁3打工模式联机网络过程分析 DHCP无类型静态路由──一个摆设 配置透明代理,实现无感上网 LaTeX插入其他PDF中的矢量图 光速不变原理和迈克尔孙──莫雷实验 交大葡萄演义 调试微信内置浏览器 欧悌甫戎篇 苏格拉底的申辩篇 LCA 最近公共祖先 弥罗斯人的辩论 埃斯库罗斯作品:波斯人、阿伽门农 电路理论资料 Coronavirus: A Humanitarian Crisis 雨夜 linux配置SSR 二叉堆的实现 懒政 Placement New Flipped: A Love Story 我宁可呆在这样的疯人院里 谈新发本地病例 勇敢与智慧 Powerful but Limited Drafted VLC Libva Error Troubleshooting Ring-Fit新上手 政治艺术化与艺术政治化 动态规划——从分割等和子集入手 被背叛的革命 (1) Everything About DPT-RP1 When Using LINUX HTTP STATUS 451 二分法——重复情形 鸽巢排序与桶排序 为什么要写博客 系统更换 动窗法与前缀和——简单实践 非类型模板参数 判断的短路规则 CodeBlocks重装 C-Style String Operation
Generating Unlimited Grammar: A Messenger Perspective
Victrid · 2021-11-05 · via Victrid's Personal Site

Chomsky hierarchy describes a containment hierarchy of classes of formal grammars. Lower level of languages, like regular and context-free, are well studied, and used in multiple practical fields, like regular expressions, and programming languages parsing.

Most textbooks introduce how to construct deterministic finite automaton from regular expressions, and some textbooks focusing on compilers will present LL, LR, LALR, etc. to show how a subset of context-free grammars are transferred to parsers. These topic are well researched, and if you use bison, it will even show you how reduce-reduce, shift-reduce conflicts are happening by examples.

When the problem comes to higher classes in the Chomsky hierarchy, the problem becomes difficult. C++ has a context-sensitive grammar, and GCC have to use a hand-written parser for it. Most textbooks will stop at context-free grammar, and teach you to use the pumping theorem to prove that some languages are not context-free.

For these languages, it’s even difficult to describe them with a correct grammar! Take $a^n b^n c^n, n \ge 0$ as an example (A popular and easy non-context-free language, commonly used to demonstrate pumping lemma). There are no definitive algorithm to guarantee a grammar for it.

Sentinel and Combination

A common solution for this can be sentinel and combination. In our example, we can first combine the last two part as $a^n (BC)^n$, which can be generated as context-free grammar, and with the sentinel $CB \rightarrow BC$, arrays like $BCBCBC\cdots$ can be derived as $BBB\cdots CCC$.

This can be obscure, if the part increases. We need to either combine recursively, or create larger sentinels to do the part. When the part is not definitive, the problem cannot be solved.

Take this problem as another example:

Let $\Sigma = \{1\}$ and $L_{\text{square}} := \{1^n \mid n \text{ is a perfect square}\}$. So $\epsilon, 1, 1111, 111111111$ are in $L$ but $11, 11111$ are not. Give an unrestricted grammar generating $L_{\text{square}}$.

Square numbers can be expanded to $1 + 2 + \cdots + (n-1) + n + (n-1) + \cdots + 2 + 1$. If we take this route, the problem could be difficult to solve by the combine method, as the items in the sequence increases with $n$.

Now we show a new perspective to view the problem. Taking the string as a queue, and messengers moving along them between head and tail. When certain situations are met, messengers will change the sequence, otherwise they’ll move through the queue.

This method will have longer reductions, but it will be easier and more intuitive to construct, and having less rules.

In the second problem, we separate the 1’s with 0, to specify a border for messengers to recognize. And we add symbols [ and ] to indicate the head and tail. A state in the reduction could be [01011010].

We can have 2 messengers to solve the problem.

  • messenger A, from head to tail:
    • insert new groups, i.e. 010, at the head and tail.
    • increase inner groups’ 1 number
  • messenger B, from head to tail:
    • remove all zeros, head and tail symbol, to reformat the string into the final look.

With the border of each group, the recognition field, i.e. the range it looks to derive uniquely, decides the size of its rule set. We here define these messengers with grammar:

$$\begin{align*} [ &\rightarrow [01A \\ A0 &\rightarrow 01A \\ A1 &\rightarrow 1A \\ A] &\rightarrow 0] \\ \end{align*}$$

and $B$:

$$\begin{align*} [ &\rightarrow B \\ B0 &\rightarrow B \\ B1 &\rightarrow 1B \\ B] &\rightarrow \epsilon \\ \end{align*}$$

and the start symbol: $S \rightarrow []$. Only 5 variables and 9 rules is needed.

Exercise

  1. Give the unlimited grammar generating language in the first problem.

    Hint: You may need to deal with situations when two messengers meet, causing a deadlock. (e.g. Emulate a lock by changing the head symbol to allow at most one messenger traveling in the sequence).

  2. Let $\Sigma = \{1\}$ and language $L := \{1^k \mid k \text{ is prime}\}$. Give an unlimited grammar generating $L$.

    Hint: Here is a not-so-clever path doing it:

    • list all numbers by increasing order
    • use Eratosthenes Sieve to filter primes
    • select one and remove others

    Not only head symbols can send messengers, and the direction are not limited from head to tail.

    You may change the head and tail symbol to indicate stages.

    You may need to deal with situations when messengers in different directions meet, causing a deadlock. (e.g. by explicitly swap them with $AB \rightarrow BA$).

Ads by Google

Read our privacy policy on how these personalized advertisements are delivered to you.

For your reading experience, we provide full-text RSS feeds. Although math formulas cannot be displayed well, the interface can be adjusted as you like and there are no ads.