In formal language theory, a context-free grammar (CFG) is a grammar subject to a special constraint: that the left-hand side (LHS) consist of a single non-terminal symbol. CFGs are capable of representing the set of context-free languages (CFLs).
Questions tagged [context-free-grammar]
1364 questions
0
votes
1 answer
Programming Project (Course Project) Need Help. Read Grammar, output Chomsky
So I have been assigned this project and have been giving it the old college try but I am a little lost on how to go about it. The idea is you're given a txt file with a grammar in the form:
V: S, A, B, C
T: a, b
S: S
P:
S -> aAaA|aABBA
A ->…

neojb1989
- 181
- 1
- 3
- 12
0
votes
0 answers
Context Free Grammars - LR(0) DFA
I need some help with constructing a LR(0) DFA for a Context Free Grammar.
S -> A
A -> aaAb | B
B -> aBb | e
This is what I have:
State
{ S -> .A
A -> .aaAb
A -> .B
B -> .aBb
B -> .e
}
Then I have an arrow labeled a to:
State
{ A->…

mrjasmin
- 1,230
- 6
- 21
- 37
0
votes
1 answer
What are the parsing algorithms for programmed grammars?
I want to know what are the parsing algorithms used for parsing programmed grammars. Any Links , blogs or anything where i can read about programmed grammars and there parsing algorithms except IEEE research papers ?

akshaykumar6
- 2,147
- 4
- 18
- 31
0
votes
1 answer
Confusion related to a context sensitive grammar
I want to know if I have the following rule
AB -> BA.
Is it context sensitive?
Another rule
A -> aAB
Is it context sensitive as well.
I think both of them are not context sensitive. Any insights or guidance?

user34790
- 2,020
- 7
- 30
- 37
0
votes
3 answers
Testing membership in context-free language
I'm working on a slot-machine mini-game application. The rules for what constitutes a winning prize are rather complex (n of a kind, n of any kind, specific sequences), and to make matters even more complicated, this code should work for a…

Hughie Coles
- 179
- 1
- 10
0
votes
1 answer
Use pumping lemma to prove grammar is not context free?
I'm trying to prove that L={y#x|(y is a substring of x) ∧x,y∈{a,b}^* } is not context free using the pumping lemma, but I can't seem to do that. If
|vy|≠ε ,|vxy|≤k , uv^n xy^n z∈L ,∀n≥0
Then either vxy has both a and b, or only b or only a.
How…

JAN
- 21,236
- 66
- 181
- 318
0
votes
2 answers
Combine free-form dictation and semantic in a srgs grammar
I'm trying to combine both the result of a semantic and a dictation request in the semantic value of a SRGS document. For example, I would say "Search potato" and the output would be something like out="Search Potato" where Potato is a random word…

Charles
- 317
- 2
- 10
0
votes
1 answer
LL vs LR in CFGs
What is the precise definitions for, and difference between, LL and LR?

Ceelos
- 1,116
- 2
- 14
- 35
0
votes
2 answers
Context Free pumping lemma
Is the following language context free?
L = {a^i b^k c^r d^s | i+s = k+r, i,k,r,s >= 0}
I've tried to come up with a context free grammar to generate this but I can not, so I'm assuming its not context free. As for my proof through…

kbirk
- 3,906
- 7
- 48
- 72
0
votes
2 answers
Prove the following language is context-free:
This question is on a sample exam that our professor was too lazy to type up solutions to and I am stuck pretty bad. Thanks in advance for your help!
Prove that the following language is context-free {x is an element of {a,b,c}* | the number of a's…

Tarvaris Jackson
- 97
- 2
- 10
-1
votes
1 answer
Removing Left recursion in CFG's
How would I go about removing left recursion from this line from a grammar?
A -> D | R | r B A n ; | AA | epsilon
r, n and ; are terminal symbols. D,R,B and A are all non-terminals.
Thanks in advance

user1058452
- 9
- 4
-1
votes
1 answer
Can epsilon production be assumed in a left recursive grammar
I have a grammar:
S->Sa|Sb
I want to know if I can assume S->e as a production in the grammar?
I.e.,
Is S->Sa|Sb is the same as S->Sa|Sb|e ?
e = null string (epsilon)
I am trying to understand removal of left recursion and I came across this…

Vedant Jumle
- 13
- 3
-1
votes
1 answer
L={aʲbᵏaˡ | l = j * k} Context free? Recursive?
I have to classify the language L={aˆjbˆkaˆl | l = j * k}.
I applied the pumping lemma for CFL and think that it is not context free. However, to prove that it is in fact recursive or recursively enumerable, would I have to be able to construct a…

nTn
- 11
- 1
-1
votes
1 answer
How would you re-write the production rules for an existing grammar so that semi-colons were optional?
Suppose that there was a programming language Mod(C) just like C++ except that it was white-space sensitive.
That is, parsers and compilers written for Mod(C) did not ignore line-feeds, spaces, etc...
Also suppose that someone had already written…

Toothpick Anemone
- 4,290
- 2
- 20
- 42
-1
votes
1 answer
CFG for a = b and c = d (length)
I know how to construct the context-free grammars for strings that have same counts of a and b, or have the same counts of c and d:
S → ε S → ε
S → SASBS S → SCSDS
S → SBSAS S → SDSCS
A → a C → c
B → b …

leander
- 33
- 4