## Efficiency/Redundancy in Chomsky normal form

I have a context-free grammar with the following production rules, S being the start symbol: S→ABA→aB→a Is this in Chomsky normal form? My problem is I thought CNF is supposed to be an efficient way to write a grammar, yet the grammar is not efficient in the sense that we can clean its rules as … Read more

## Is there any difference in the expressiveness of boolean grammars versus definite clause grammars?

Definite clause grammars have been around a long time and are included in logic languages such as Prolog. They can be translated into (are just syntactic sugar for) Prolog programs and are therefore I assume turing complete (unless I have missed an important limitation of DCGs relative to full Prolog). Prolog is a logic programming … Read more

## Why full Chomsky hierarchy is so detailed, if there are decidable recursive languages?

One can have a look on the Chomsky hierarchy https://en.wikipedia.org/wiki/Chomsky_hierarchy , especially the inset named “Automata theory: formal languages and formal grammars” at the bottom of the page. When one tries to model natural language (e.g. as http://www.grammaticalframework.org/ tries to do it), then one usually aims for the most expressive formal language that is still … Read more

## Is the following Grammar LL(1)

I was given the following grammar S→S(S)S∣ϵ First I was asked to eliminate left recursion, yielding me the following : S→S′ S′→(S)SS′∣ϵ I was then asked If the grammar is LL(1). So I computed the FIRST and FOLLOW sets shown below: FIRST(S)=FIRST(S′)={(,ϵ}, FOLLOW(S)=FOLLOW(S′)={\$,(,)}. I now tried building the LL(1) parsing table M as follow: Since … Read more

## Is this context-free grammar correct for this regular expression?

I have created a context-free grammar S→S1∣S2S1→aS3bS4∣ϵS2→bS4S3→aS3∣ϵS4→aS4∣bS4∣ϵ for this regular expression (aa∗b(a∪b)∗)∪(b(a∪b)∗) Is the grammar correct or am I missing a certain route? Answer One way to check whether you have got correct grammar is to use plain English or regular expression to characterize each non-terminals, starting from the more basic blocks. S4→aS4∣bS4∣ϵ This rule … Read more

## Converting CFG from GNF to CNF

I am working with grammars that need to be in Greibach Normal Form. I want to check whether a grammar recognises a string. In order to perform CYK the grammar would have to be converted into CNF. Is there an established way of carrying out such conversion? Answer You can just apply the usual procedure … Read more

## Can there still be infinite recursion if I remove all left recursion?

I have to transform the following grammar into a non left recursive grammar: S → aSb | bAS A → AaA | bAA | AAa | bAb This is what I came up with: A → bAAA’| bAbA’ A’ → aAA’| AaA’| ε S → aSb | bAS As far as I can tell, there … Read more

## defining a programming language grammar for doing arithmetic

I’m studying programming language design, and I’ve been taught the grammar below which lets you write basic math expressions. Exp ::= Num | Exp Op Exp Op ::= + | – | * | Div Num ::= Digit | Digit Num Digit ::= 0 | 1 | 2 | 3 | 4 | 5 | … Read more

## Ambiguos Grammar detection algorithm

I tried to solve if a grammar is ambiguous or not. I know that I have to find a word that can be generate by two different leftmost derivations. Is there any algorithm to find a word that, if the grammar is ambiguous, can be generated by two different trees? This question is different. Answer … Read more

## I want to design a context free grammar for the following [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago. Improve this question This below language L={w∈{a,b}n:|w| mod 3=0} where n≥0. Answer Since this seems very much like homework, i will give you a little … Read more