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
-1
votes
1 answer
NLTK and PYTHON GRAMMAR
I already have python 2.7 and nltk installed on my system
please and please, how can I make my python program use the below cfg to be attaching part of speech to my sentences??
N -> 'ọnẹkẹlẹ'|'igbẹlẹ'|'ọma-ọnẹkẹlẹ'
Pr ->…
-1
votes
1 answer
need help finding the context free grammar of these languages
I need help finding the grammar of these languages.
I feel like I am getting nowhere with these solution
1) {a^h b^k a^m b^n | h + k = m + n}
2) {a^i b^j a^k | (i = j and k ≥ 0) or (i ≥ 0 and j > k)}
any help would be appreciated

marc k
- 63
- 7
-1
votes
1 answer
Specifying two alternative rules for an expression in YACC
I am writing a HTTP header parser in YACC. Since HTTP request and response has same structure except for first line, I hope to use the same parser for them. I individually tested request_line and response_line and they work on HTTP request and HTTP…

user274602
- 59
- 1
- 2
- 7
-1
votes
1 answer
Compilers: change ambiguous grammar
I have a little problem with this exercise.
Given this grammar:
S -> aX | X
X -> aXb | b | eps
a) shows that it is ambiguous with a string
b) say what language captures the grammar
c) change the grammar and build a descendant parser
Solution by…

Federico
- 143
- 1
- 1
- 10
-1
votes
1 answer
Need help in generating a CFG for a language
I want to match strings that contain "k" number of 0's followed by "k+4" number of 1's where k is greater than or equal to zero
I tried the following grammar is this correct?
S->0S1|1111

mike
- 49
- 1
- 8
-1
votes
1 answer
check if regular language given CF grammar
I have this grammar
S->aSbA
S->e
A->aB
B->bA
How can i determine if the language is regular? My problem is that A and B doesnt have a terminal character so i dont know what languages it will produce.

user2936672
- 73
- 5
-1
votes
1 answer
LL(1) Grammar and parsing
I'd like some help on how to transform a grammar to LL(1) using factoring. Possibly other techniques but I have already used left recursion
For example I have the question
S--> 1X1F|2X2F|1X
X--> 1X|0
F--> 0F|ε
ε denotes a termination without…

duldi
- 180
- 1
- 17
-1
votes
1 answer
Give a CFG for this language
The language is: {0n1m|n=2m}
I need to give a CFG based on this language, and I can't figure it out. It's been an hour and I am extremely frustrated, anyone got any hints/lead-way?

bob afro
- 213
- 1
- 2
- 10
-1
votes
1 answer
Context grammar for specific language
I can't understand simple problem. I have to indicate grammar for the following
words
a) (ab)^2i c, i>=1
for i=1 ababc for i=2 ababababc
S -> abA
A -> ab | abc | c
b) a^(m-1) b^(m+1) a^n b^n, m>=1 n>=1
for i=1 bbab for i=2…

IkyryguJava
- 83
- 1
- 9
-1
votes
1 answer
Generating Context-Free-Grammar (TOC Basics)
The question states:
Give a context-free grammar that generates the language
A = {a^i b^j c^k | i=j or j=k where i,j,k >= 0}
Is the grammar ambiguous? Why or why not?
[Intro. to TOC Sipser 2.10]
The book doesn't have too many good examples on…

Daal
- 79
- 2
- 2
- 7
-1
votes
1 answer
Provide a context free grammar for the following languages:
a) L = {1^i - 1^j = 1^(i-j) | i-j>=0, i,j>=0}
b) L = {a^i b^j c^k | k!=i+j, i,j,k>=0
I can't seem to figure out how to implement these procedures. I understand the concept, I just can't seem to work it out. Any help would be great! I've been…

Tiffany
- 1
- 2
-1
votes
1 answer
Make a grammar unambiguous?
I have the following problem. This grammar is ambiguous:
stmt -> if expr then stmt stmt’ | a
stmt’ -> else stmt | EPSILON
expr -> b
I tried to modify it and my result is:
stmt -> if expr then stmt’’ | a
stmt’’ -> stmt | stmt’
stmt’ -> B else…

thommyho
- 1
-1
votes
1 answer
Best way to parse suffixed words
I need a parser that recognizes the part of speech according to the last letter of each word. I've used Python but I'm not sure the available CFG parsers will accept this.
Let's take Esperanto words for example. All adjectives end with -a (eg.…

Piechjo
- 1
- 2
-1
votes
1 answer
One Language and Proof How it's ambiguous?
I just took my midterm but couldn't answer this question.
How we can show the following language is ambiguous ?
L={a n bm c p : n≠m} U {a n
bm c p : m≠p}
I think this is very hard, Who can Help me with automated tools or ... how we can…
user4249446
-1
votes
3 answers
C: Trouble starting a program designed to recognize a string pattern
I'm in my first programming class and having trouble with a project of ours. The program is designed to take a string's inputs and see if they match the pattern and recognize if the pattern is broken; in this case it is meant to recognize if the…

JohnX
- 29
- 3