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
-1
votes
1 answer

Confused at transferring an ambiguous grammar to an unambiguous one

An ambiguous grammar is given and I am asked to rewrite the grammar to make it unambiguous. In fact, I don't know why the given grammar is ambiguous, let alone rewriting it to an unambiguous one. The given grammar is S -> SS | a | b , and I have…
-1
votes
1 answer

CFG and DCFG Decidable problems

Can you guys list the problems that you are aware that are decidable for Context free Language and for Deterministic Context free languages. I did get some info on list of undecidable problems on Stack Overflow and Wiki, but not related to CFG or…
Nikhil Mahajan
  • 54
  • 1
  • 2
  • 12
-1
votes
1 answer

Context free grammar that starts and end with 00

I need help creating a Context Free Grammar which starts and ends with 00. The language to be used will be {0,1}
Tayyab Shabab
  • 259
  • 1
  • 6
  • 16
-1
votes
1 answer

Are there different types of parsers?

Consider this simple grammar: S -> a | b The set of strings that may be generated by the grammar is: {a, b} Thus, a grammar generates a set of strings. A parser for a grammar takes an input string and determines if the string could be generated…
Roger Costello
  • 3,007
  • 1
  • 22
  • 43
-1
votes
1 answer

Explicitly failing a context free grammar sentence parse

I have a context free grammar sentence parser which functions correctly except for the fact that when you either type in something that doesn't exist in its knowledge base or doesn't conform to the grammar it will remain in an infinite loop. I…
user2211776
  • 239
  • 1
  • 2
  • 11
-1
votes
1 answer

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

The context free grammar: (e represents epsilon) S --> aSb|aSa|bSa|bSb|e It could generate regular language which means it can be converted to a right linear grammar. Is there a general rule to convert CFG into a RLG?
henry
  • 185
  • 2
  • 2
  • 13
-1
votes
1 answer

CFG and PDA for the grammar that has perfectly nested parentheses and brackets

I gotta make a CFG and PDA for the grammar that has perfectly nested parentheses and brackets. S -> [S] S -> (S) S -> SS S -> Epsilon Not sure if this is correct, or how to make the PDA from it?
y2k
  • 65,388
  • 27
  • 61
  • 86
-2
votes
1 answer

How are these parse tree generated?

I need assistance regarding generating the parse tree and the syntax tree. My version of the solutions are the images below but I don't know if they are correct or way off. Given the Grammar: S-->aSb | e And the String: Generate the: (i) Parse…
-2
votes
1 answer

PDA and CF grammar for L={w| w={a,b}* such that 2* (number of "a"-s in w) != 3* (number of "b"-s in w) +2 }

I found the following problem in a past exam: Construct a PDA with void stack acceptance and a CF grammar for the language: L={w| w={a,b}* such that 2* (number of "a"-s in w) != 3* (number of "b"-s in w) +2 } Assume that w = {a, b}* with that…
-2
votes
1 answer

Language can not be constructed using contex ftee grammar

How can i prove with pumping-lemma that this language (L := {ww| w ∈ {0, 1}∗}) can not be constructed using context free grammar? Thanks in advance.
-2
votes
1 answer

How do I find the language for a context free grammar?

I am having trouble determining the language from a given context free grammar. I've been given a hint that there are 2 parts to the language but cant figure either out. G= ({S,A,B,C,D,E,Z},(0,1),R,S), S→E|Z E→A|C A→01B|0A|e B→1B|10A…
jordan neely
  • 39
  • 1
  • 6
-2
votes
1 answer

Generate a CFG for a list of words

It is possible to write an algorithm that generates a CFG that parses a list of words, with maxim m rules, or if it is imposible to parse all words, to parse maximum words possible? Do you have any ideas about how should I start the algorithm? All…
tairqammar
  • 151
  • 3
  • 10
-2
votes
1 answer

Map Java If statement to abstract syntax tree metamodel (ASTM) class?

I'm implementing abstract syntax tree metamodel (ASTM) for my java parser. Now I done with parse tree with my grammar file. Now I tried to map parse tree to astm. I'm totally confused to map which to which, mapped If statement to IfStatement.java…
-2
votes
1 answer

Is this languages REGULAR / CONTEXT FREE but not REG / Nothing?

(1) {((a^2)(b^4)ab)^(3k) : k>=0} (2) {a^(2n)b^(3n) : n >= 7} (3) {a^(2n)b^(3n) : n <= 7} No clue for this one. I think it's contextFree cause there is no limitation on n, unlike 3) we can't build a finite automate but we can build a Grammar: S…
-2
votes
1 answer

Provide a context-free grammar that generates odd length language {w = 0*1* : |w| is odd}

Provide a context-free grammar that generates the following language over Σ = {0,1}: {w = 0*1* : |w| is odd} My Solution: S->AB|0|1 A->0A|^ B->1B|^ But using this grammar we are able to create an even number of string. I want grammar that produces…
1 2 3
90
91