Questions tagged [formal-grammars]

Questions about formal grammars, generative descriptions of formal languages.

Filter by
Sorted by
Tagged with
0
votes
1answer
2k views

CFG for $\{a^i b^j : 2 i<j\}$ [duplicate]

So I have a question: Give a CFG for $\{a^i b^j : 2 i<j\}$ And this is my approach: $S\to AB$ $A\to aAb\mid \varepsilon$ $B\to b \mid bB$ A confirmation, or correction, along with how you ...
0
votes
1answer
141 views

Context free grammar for {a^mb^n | m ≠ n} [duplicate]

I need to find a context-free grammar for the above expression, $a^{m}b^{n}$ for the set $L = \left\{{a, b}\right\}$, but I am having difficulty accounting for the condition $m \neq n$. This is what ...
0
votes
0answers
59 views

How i can use Mathematical induction to prove CFG production? [duplicate]

If I have production $G_n$ $S \rightarrow A_i b_i \quad$ for $1 \le i \le n$ $A_i \rightarrow a_j A_i \mid a_j\quad$ for $1 \le i$ and $i \ne j$ Prove $G_n$ is sub-productions from $2n^2 - n$ ...
0
votes
1answer
32 views

Design a CFG that generates the language { x in {a,b}* | the length of x is odd and its middle symbol is a b }

I am trying to design a context-free grammar that generates the language { x in {a,b}* | the length of x is odd and its middle symbol is a b }. This is really confusing me, I'm having trouble with ...
0
votes
1answer
78 views

Construct a grammar for the language

How can I achieve this. Write a grammar for the language consisting of strings built only of the letters a and b. The strings may have any number of these letters, but the letter combinations bab must ...
0
votes
1answer
123 views

Context free grammar problem with hashtag

I am trying to solve the following context free grammar problem with hashtag approach but i can't figure it out. Can anyone help please? Show a context-free grammar for the following languages: $$\{w\...
0
votes
1answer
1k views

How to write an EBNF grammar for Java float literals?

I've got this question on my study guide: "Write an EBNF grammar description for Java float literals and one for Java double literals." I've browsed the Oracle site and found the grammar for java ...
0
votes
2answers
908 views

Context-free grammar for“not-at-all” palindromes

I need to bulid a context-free grammar for $\qquad \mathscr{L_4}=\{w\in\{a,b,c\}^* \mid w\text{ is not palindrome at all}\}$ Not palindrom at all: We will say that a word $w$ is not palindrome at ...
0
votes
2answers
99 views

Which Type of Grammar is this?

I am learning Compiler Design. Can somebody explain what type of Grammar this is? The answer given is $LL(1)$ but there exists a left recursion in the grammar so it cannot be $LL(1)$. I derived the ...
-1
votes
2answers
6k views

Ambiguous Grammar to Unambiguous Grammar

I'm wondering if somebody can please help me to understand how I go about converting this grammar to an unambiguous grammar. If you can point me in the right direction, I would greatly appreciate it. ...
-1
votes
1answer
79 views

Help me find the ambiguity in this grammar

I've been sitting on this for 20+ minutes and can't seem to generate a string that is ambiguous. Can anyone help me? The grammar is: $$S \xrightarrow{} SS \mid T$$ $$T \xrightarrow{} aTb \mid ab $$ ...
-1
votes
2answers
273 views

Unrestricted grammar to generate $a^{n(n+1)/2}$

I have been asked to find a grammar that will generate the language $a^{n(n+1)/2}$, where $n\ge1$ as an exercise. Any idea on how to set up such grammar? Any help would be appreciated.
-1
votes
1answer
44 views

Could someone please explain this language to me and its grammar? [closed]

This is the problem: http://i.imgur.com/Io7h1en.png This was a problem I saw and I really have 0 clue what the Language means the (**) part, and its solution. I was wondering if anyone could please ...
-1
votes
2answers
863 views

Pushdown Automata: CFG to PDA

I have the following grammar for a context-free language: $G = (\{S,A,B\}, \{x,y,z\}, P, S)$ with $P = \{S \rightarrow A, A \rightarrow xAz, A \rightarrow xBz, B \rightarrow y\}$ My question is: How ...
-1
votes
1answer
2k views

Left Linear Grammar: How to construct?

I need help constructing a Left Linear grammar for the language $L = \{ a^n b^m c^p \mid n\geq 2, m\geq 3, p\geq 4 \}$ Here is what I have so far, I know : $N = \{S\}$ $T = \{ a, b, c \}$ $P = \{$...
-1
votes
1answer
82 views

Write a grammar for a language $L=\{ba^{2^n}b |n\ge 1\}$ [closed]

Write a grammar for a language $$L=\{ba^{2^n}b | n\ge 1\}.$$ It's not even context-free as I think. I just can't produce it, although I've tried a lot. Now my best attempt is: \begin{aligned} S &\...
-1
votes
1answer
2k views

CFG for the language “number of a's = number of b's + 2”

How can I construct a context-free grammar for the following language? $$ L = \{ w \in \{a,b\}^* : \#_a(w) = \#_b(w) + 2 \}. $$ Please help me out in this. I am not sure how to approach this ...
-1
votes
2answers
84 views

Design a grammar for this context-free language

I am doing an exercise from Models Of Computation - Ch - 5, Q-1(r). Design a grammar that generates this context-free language $\{ x\space\$\space y^R \,|\, x, y \in\{0, 1\}^* \text{ and } x \ne y\}...
-1
votes
1answer
321 views

Context sensitive grammar for an odd number of copies of the same word

Let $L = \{ w^m \mid m = 2k +1, k \ge 1 \}$. Please give some idea to write a Context sensitive grammar for $L$. Will it be like $L' = \{www \mid w \in \{a, b\}^*$? Then for each $w$ we have to ...
-1
votes
2answers
505 views

Context-free Grammar To Generate $L=\{a^nb^k | 1 =< n =< 2k } [duplicate]

I need to write a context-free grammar for this Language : $\L = {a^nb^k | 1 =< n <= 2k} Please help me solve this problem! Thanks.
-1
votes
1answer
150 views

Show L is not context free using the CFL pumping lemma

I am trying to use the pumping lemma to show this language is not context free: $L = a^nb^{n+1}c^{2n} : n \ge 0$ So I took $z = a^mb^{m+1}c^{2m}$ where $|z| = 4m+1 > m$. We can decompose $z = a^mb^...
-1
votes
1answer
97 views

L is a regular language and w is any word, not necessarily in L. Show that L is regular

$L$ is a regular language and $w$ is any word, not necessarily in $L$. We define the set as $$L/w = \{x \in \Sigma ^* \mid xw \in L\}.$$ Show that $L/w$ is regular. I'm really struggling with this ...
-1
votes
2answers
28 views

Finding the language generated by a grammar

Forgive my lack of knowledge, I am new. I tried to find the language generated by this grammar S → aA | bS | cS | ɛ A → aA | bB | cS | ɛ B → aA | bS | ɛ And I ...
-1
votes
1answer
49 views

Constructing a DFA of strings that are in A but not in B

I am tasked with creating a DFA for the regular language L = A/B, which are the strings that are in A but not in B. The alphabet is Σ = {a,b,c} I am not really sure where to even start with this one, ...
-1
votes
1answer
697 views

Proving that a language given by a CFG is not regular [duplicate]

Consider the language defined by the following grammar: $$ \begin{align*} &S \rightarrow E \\ &S \rightarrow \epsilon \\ &E \rightarrow E+E \\ &E \rightarrow E-E \\ &E \rightarrow \...
-1
votes
1answer
1k views

Generating grammar for the given language

Can someone please give a couple of examples of the language and construct a grammar for the language (given below), or at least show me how I can go about it? I am looking for a context-free grammar ...
-1
votes
1answer
108 views

Building an undecidable T-Grammar

I am asked, "Show that these T-Grammars constitute a set of languages that are undecidable. Do this by building a T-Grammar for a Turing machine description. For a starting point you might think about ...
-1
votes
1answer
432 views

How should I show that a grammar is not LL(1) and convert grammar to LL(1)

I'm trying to find the ambiguity in this grammar so I can remove it and convert it to LL(1), however for the life of me, I can't find the ambiguity. Moreover, I think there is cycle between X and Y ...
-1
votes
1answer
41 views

Unambiguous CFG that generates regular language according to Pumping Lemma?

The pumping lemma for regular languages states: Specifically, the pumping lemma says that for any regular language L there exists a constant p such that any word w in L with length at least p can ...
-1
votes
1answer
56 views

Context-free grammar for “member of”/set membership?

I'm wondering whether context-free grammars (or what else) can be used to implement "member of" structures, which are structures for describing that something is a member of something. E.g. I want to ...
-1
votes
1answer
2k views

Chomsky Normal Form-remove unit production

In the step of removing unit productions when converting a grammar to Chomsky normal form, I sometimes found that the variables may end up having the same production bodies. Is this possible? If so, ...
-1
votes
1answer
122 views

Eliminate Left Recursion

The part I want to modify: B -> F | B A | A What is the correct way to remove this left recursion? I was thinking ...
-1
votes
1answer
265 views

Programming Languages Grammar Ambiguity [closed]

I don't know if it is the right site to ask this. But we're studying about ambiguities of grammar. Including left most derivation and right most derivation. We are given the problem: ...
-1
votes
1answer
175 views

Equivalence of some Automata & Language & NFA

I read some note about Automaton Course. i see this note, that following all is the same. but i think the L(g) is not equal to NFA and regular expression. anyone could help me with defining the ...
-1
votes
1answer
945 views

Construct grammar given the following language [duplicate]

Construct grammar given the following language! $ L = \{(ab)^{n+1}u(ba)^n|n>0, l_c(u) = 1, u\in\{a,c,d\}^* \}$ My interpretation in a less accurate way: $(ab)^{n+1}$ says we need to concatenate $...
-1
votes
1answer
164 views

generation of linear grammar

We have the following linear grammar: $$E \rightarrow aO | bO | bbE | bb$$ $$O \rightarrow aE | bE | abaE | aba$$ Does the linear grammar generate a regular language, if yes why ? Our alphabet is $\...
-1
votes
1answer
59 views

How to design a formal grammar to convert EBNF description to a list of CFG production rules

I would like to write a grammar to convert EBNF description to a list of CFG production rules, instead of an algorithm. Can CFG production rules is generated from an EBNF description by a rewrite ...
-1
votes
1answer
17 views

How to simplify context free grammar?

How to simplify this context-free grammar into a similar one with no unit productions and no useless symbols? $$ S \to ABA \\ A \to aAA \mid aBC \mid bB \\ B \to A \mid bB \mid Cb \\ C \to CC \mid cC ...
-1
votes
1answer
29 views

How to find the language and create Push down automaton if the A is continuously looping ? and will PDA accept L produced without A

Let us consider the following Context-Free Grammar G = ({S,A,B,C,D},{a, b}, S, P) with production rules P: S → SSA | Bb A → BSA B → A | Cb C → AD | Cb | ɛ D → a | b | ɛ Let L be the language ...
-1
votes
1answer
30 views

Grammar for the following language: L = {$a^{k}$$b^{n}$$a^{m}$ : m,n,k $\in$$ N^{+}$ $\land$ m + k $\geq$ n}

I'm trying to create a grammar (having the highest type) for the language: L = {$a^{k}$$b^{n}$$a^{m}$ : m,n,k $\in$ $N^{+}$ $\land$ m +k $\geq$ n} I'm not finding any good approach for it. Hints ...
-1
votes
1answer
66 views

How construct PDA to $L = \{x \in(a,b,c,d)^* \mid -10 \leq ( |x|_a + |x|_b) - ( |x|_c + |x|_d) \leq 10 \}$

$L = \{x \in(a,b,c,d)^* \mid -10 \leq ( |x|_a + |x|_b) - ( |x|_c + |x|_d) \leq 10 \}$ I don't have any idea. Can someone help me.
-1
votes
1answer
249 views

Convert grammar to Greibach form

The grammar is $S \rightarrow AA|a$$A \rightarrow SA|ab$The actual question is to find an NPDA accepting the language generated by this grammar but for that i firstly need to convert it into Greibach ...
-1
votes
2answers
53 views

Context-free grammars for two languages

How do I write context-free grammars for the following languages? $B_2 = \{0^n1^n \mid n > 0\} \cup \{0^n1^{2n} \mid n > 0\}$ $B_3 = \{a^nb^mc^k \mid k = n+m\}$ Can someone help me? I'm not ...
-1
votes
1answer
3k views

Describing language generated by grammar

S -> aSb | A | B A -> aS | a B -> Sb | b is this the language generated by this CFG? Or am I missing something?
-1
votes
2answers
2k views

Removing epsilon transition from context-free grammar

I have the following context-free grammar from which I have to remove epsilon transitions: $S \to 0A0|0$ $A \to BC|2| CCC$ $B \to 1C | 3D | \epsilon$ $C \to AA3 | \epsilon$ $D \to AAB | 2$ By ...
-1
votes
2answers
408 views

Find the Unambiguous Grammar [closed]

Consider the following grammar: S->A. A->A+A|B++. B->y Check whether grammar is Ambiguous or not? Also ,unambiguate the grammar.Now please tell me what will be the grammar after removing the ...
-1
votes
1answer
49 views

Tools or techniques for studying the language a CFG produces? [duplicate]

When developing a CFG, I find that one can be confused about whether the grammar is correct, i.e. whether it recognizes only the required strings and not other strings. But this can be hard to see? ...
-1
votes
1answer
265 views

How to write Context-free Grammar for this language? [closed]

I am trying to teach myself how to write Context-free Grammar for different languages. I have an example language I am trying to work out and this is the answer I came up with, does it make sense? ...
-1
votes
1answer
35 views

Fixing a grammar

I'm sorry I don't know the technical terminology for this. All I see in my notes is fixing a grammar. Can someone please help explain this? What exactly is this called?
-1
votes
1answer
80 views

Create a grammer for [duplicate]

create a grammer for {a^nb^m, n>0, m=2^n+1} itS unrestricted grammer. I tried to but couldnt understand. if you know the answer please breif it. coz i m new in this subject