Questions tagged [context-free-grammar]

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).

1364 questions
-2
votes
1 answer

Linear grammar exercise

I am a student and i have an exercise with a linear grammar G=(N, Σ,S,P) where N is a set of nonterminal symbols, Σ is a set of terminal symbols, P is a set of production rules, and S is the start symbol with the productions: S->aS S->bX X->ε 1.So…
Croco
  • 1
-2
votes
1 answer

How to prove that a grammar is unambiguous?

E → I | C | (E+E) | (E∗E) I → y | z C → 4 It is written that it is unambiguous and also I understand intuitively that given grammar is unambiguous. But for now, all I can do is to argue. Can anyone tell me how to prove that a grammar is…
Ankit Shubham
  • 2,989
  • 2
  • 36
  • 61
-2
votes
1 answer

Creating a context-free grammar for a specific language

I am trying to create a context-free grammar for the language L = {u2v; u,v E {a,b}*; |u| >= |v|} however, I can't really understand how to pick up from here. My idea is that for every a/b character that I generate in u, I should generate another…
prkist
  • 431
  • 5
  • 13
-2
votes
1 answer

How to define floats with same number of digits with context-free grammar

I can't figure out on my own how do this exercise. I need to define context-free grammar that is able to write positive floats with same number of digits on left and right side of comma. Something like that L = { {0..9}^k,{0..9}^k | k is positive…
radeko
  • 33
  • 1
  • 4
-2
votes
1 answer

Prolog program to recognize context free grammar a^n b^n

Using Prolog I'm trying to write a predicate that recognizes context free grammar and returns true if the input list matches the CFG. The alphabet of the input consists only of a,b. The CFG i'm trying to match is S-> TT T -> aTb | ab I'm not quite…
Jay
  • 15
  • 1
  • 7
-2
votes
1 answer

How to give this context grammar

How to create a context free grammar for L={w∈{a,b,c}*|w has more as than bs}
-3
votes
1 answer

How can I randomly generate strings with this CFG?

I have this code describing a context-free grammar and I'm trying to generate random strings that match it; for example, like this: "John thinks that Mary hates every green cat" But my current output is: [['_S', ['_NP _VP']], ['_NP', ['_Det _Adj…
python Q
  • 11
  • 1
-3
votes
1 answer

find context-free grammar for the following language

Find context-free grammar for the following language (with n≥0 and m≥0): L={w∈{a,b}*: n_a≠n_b} Assume: n_a=n_b S-> SS | aSb | bSa | λ Add a’s or add b’s S-> SS | aSb | bSa | aS | bS | a | b
Fulla
  • 79
  • 7
-3
votes
1 answer

Can you help me understand this answer?

I'm currently studying for an exam and I came across a question regarding grammar in formal languages for which I'm pretty sure the professor got the answer wrong, I'd like to hear your idea. The question presents this grammar: The question asks to…
Avi Sasson
  • 666
  • 7
  • 22
-3
votes
1 answer

Grammar or specification of Bison/Lemon files

I need to write parser for Bison and Lemon grammar files. I'm looking for specification or grammar of these files format. Any links will be helpful.
melihovv
  • 1,055
  • 1
  • 10
  • 15
-3
votes
1 answer

How can I prove this grammar is ambiguous?

S → ASB | ab | SS A → aA | ε B → bB | ε
-4
votes
1 answer

CAN Inherently ambiguous languages HAVE DETERMINISTIC CONTEXT FREE GRAMMARS?

DANGLING ELSE PROBLEM: S->iEtSS' / a S'->∊/ eS E->b is a Deterministic context free grammar, and is ambiguous for "iEtiEtSeS" but ALL DCFG ARE UNAMBIGUOUS . so " how can this DCFG be ambiguous?"
-4
votes
1 answer

Strings from grammar

I must have dozed off in class. I have an exam tommorow and this is on the review sheet and i have no idea what this means. If someone could explain it and/or have a link for somewhere I can learn about "it" that would be helpful. thanks Consider…
-6
votes
1 answer

Any Language that can be generated LL1 Grammar is regular. True/False

I am reading about grammars, I have a question is every language generated by LL(1) grammar is regular? I know that every regular language can be generated by LL(1) grammar.
1 2 3
90
91