We’re rewarding the question askers & reputations are being recalculated! Read more.

# Questions tagged [formal-grammars]

Questions about formal grammars, generative descriptions of formal languages.

924 questions
Filter by
Sorted by
Tagged with
227 views

### Context free grammar construction

My problem with CFG is, I am to generally create ones that don't have requirements such as: $\qquad \{a^m b^n \mid m \le n \le 2m \}$ I have no clue where to begin, and how to approach it. I was ...
1k views

### Does a context-free grammar with multiple variables have a “starting” point?

So lets consider the following grammar \begin{align*} S &\to 0 \mid 0A \\ A &\to 1 \end{align*} would the string "1" be accepted by the language or must the language start with $S$?
2k views

### Proving that a word is *not* generated by a context-free grammar

I saw the answer in one of the solutions and I cannot figure out how they got the answer. The question is asked if the word is in the language or not for CNF... How did they get the answer so that ab ...
4k views

### How to convert a context free grammar (could generate regular language) to a right-linear grammar

Consider the context free grammar: $$S \rightarrow aSb \mid aSa \mid bSa \mid bSb \mid \varepsilon$$ It could generate regular language, which means it can be converted to a right linear grammar. Is ...
5k views

### Context-free grammar for $\{ a^n b^m a^{n+m} \}$

I've got a problem with this task. I should declare a context-free grammar for this language: $\qquad \displaystyle L := \{\, a^nb^ma^{n+m} : n,m \in \mathbb{N}\,\}$ My idea is: We need a start ...
3k views

### Grammar of regular languages vs. context free languages

Let $L$ be some language. What could you say about $L$'s grammar if it is a regular language, that couldn't be said if it was a context free language? For example, in case $L$ is regular, could you ...
2k views

### How to represent whitespace in a context-free grammar?

Say we want to support: xx The following grammar does accept it: S -> xAx A -> ε. because S => xAx => xx. But what about supporting: x x I realize this might be a stupid question but I'm really ...
337 views

### Formal language without grammar

Definitions: Alphabet $Σ$: finite, non-empty set Language: subset of $Σ^*$ Grammar: Unrestricted grammar (Chomsky Type 0) Language of a grammar: all words that can be produced by applying $P$ ...
464 views

### Context-free grammar of the concatenation of a string S and subsequence of reversed S

I have to find a Context-Free grammar that generates the language: $L_1 = \{x\#y\ |\ y$ is a subsequence of $x^R$, and $x\in\{a,b\}^*\}$, $\Sigma=\{a,b,\#\}$ The concatenation of two mutually ...
7k views

### What is rightmost sentential forms?

I'm solving some past job interview problems. I met an embarrassing question about compilers. The question is : Consider the following grammar, with start symbol $E$: \begin{align*} E &\...
217 views

### Correspondence between automata and formal grammars?

From Wikipedia Since there is a one-to-one correspondence between linear-bounded automata and such grammars, no more tape than that occupied by the original string is necessary for the string ...
3k views

### Finding the grammar type of the programming language

How can someone find what type of grammar for a given programming language? Formerly I'm looking for a grammar type for most popular programming languages: C, C++, C#, Java, List, OCaml, Haskell etc.
807 views

### non LL(1) grammar but LL(1) language

I'm reading a Basics of Compiler Design and on page 84 it is making the following statement: A language may well be LL(1) even though the grammar used to describe it is not. Can someone give ...
239 views

### Figuring out the language of a non-linear CFG

I have the CFG G with the following production rules: $$S \to aSaS \mid b$$ Is it possible to find $L(G)$? I have no idea how describe it by any pattern. I use grammophone to check example words, ...
1k views

661 views

### Examples for CFG that cannot be expressed by regular language

There are nice examples for context free grammars which cannot be expressed with regular language, for example the palindrome and a similar contrived example here, but they are very intuitively ...
949 views

### Converting REGEX to BNF grammar

Say I have a bunch of regex expressions which are used as filtering rules. (Any special extraction capabilities are unnecessary here, the set of regular expressions I have is only used for filtering ...
66 views

### Understanding this answer: A CFG defines a language as a the smallest solution to a system of language equations

Statement comes from this answer. A blanket statement that this is a well-known fact is made in this other question. I have never heard of a language equation. But I am just a student. Given the ...
104 views

### Prove that if you can derive w from α in n steps, it's possible with n left-derivations as well

My university's automata theory book claims that the following claim can be proved by induction but it doesn't bother showing the proof. I've tried to prove it myself but I got stuck at the ...
1k views

### An example of a non-regular grammar for a regular language?

I understand that a regular language can be specified by either regular or non-regular grammars. What is an example of a non-regular grammar for a regular language?
62 views

### Is $\{ w_1cw_2 \mid w_1 ≠ w_2 \}$ a context-free language?

Is the language $L_1 = \{w_1cw_2 ~|~ w_1,w_2 \in \{a,b\}^{\ast} \text{ and } w_1 \neq w_2\}$ a context-free language? It certainly isn't regular, but is it context free? I'm having trouble creating ...
52 views

### Create a grammar that generate the language a^n . b^m . c^q . d^p such that n + p = q + m

I'm stuck on this question. I'm struggling on how to keep track of the number of a and d I have generated. The professor hasn't given the correction. I have seen similar questions but the condition ...
52 views

67 views

### How do you call alternatives in the grammatical productions?

I have encountered a question, which asks what is a syntactic form. This motivated me to ask myself, what is the anatomy of the grammatic rule, ...
145 views

### Can every DCFG be converted to DGNF?

I know you can convert every context-free grammar into Greibach normal form grammar. But can I convert every deterministic context-free grammar into deterministic Greibach normal form grammar?