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

how to find context free grammar when ac elements have another element b in between

I am trying to find the context free grammar for this equation L = {a ᶦ b ʲ c ᵏ | i = j or i = k, i, j, k ≥ 0} I have been able to work out the grammar for when a and b have equal exponent such as S->ɛ S->XY S->ab S->aXb Y->cY | ɛ but I am having…
-1
votes
1 answer

Does aabbabb belong to the regular expression ((a*| b*)bb)*?

I'm just curious if ((a*| b*)bb)* means that whatever number of a's or b's used in the inner parentheses must be fixed. Like if I had aabb, I could not follow it with a different number of a's? ` Would something like abbaabb or a bbbabb or bbbaaabb…
Shisui
  • 1,051
  • 1
  • 8
  • 23
-1
votes
1 answer

converting CFG to regular expression

Here's a CFG that generates strings of 0s, 1s, or 0s and 1s arranged like this (001, 011) where one of the characters must have a bigger count than the other like in 00011111 or 00000111 for example. S → 0S1 | 0A | 0 | 1B | 1 A → 0A | 0 B → 1B |…
-1
votes
1 answer

Write grammar for context-free language

I need to find the grammar for the following language: L = {a^n w w^R b^n; n >= 1, w є {a,b} and w^R is the reverse of w} I'm really stuck on what "w є {a,b}" and "reverse of w" means. Could someone explain this to me?
davai
  • 11
  • 4
-1
votes
1 answer

Context free grammar for L{a^n b^m c^t where t>0,m>0,n>2}

For a context free grammar for L{a^n b^m c^t where t>0,m>0,n>2} S -> ABC A ->aB|a B ->bB|b C ->cC|c Is this correct?
-1
votes
1 answer

ANTLR4 CPP14 Grammar not able to identify decimal numbers

I am using the below ANTLR grammar for parsing my code. https://github.com/antlr/grammars-v4/tree/master/cpp The following code gives error while parsing. Here "08" is not identifying as an integer literal. TEST_F(suite_name_test_p, 08) { …
Anand
  • 823
  • 1
  • 10
  • 19
-1
votes
1 answer

What are the words recognized by the CFG S - > 1 | S 0

I am dealing with this exercise: What are the words of S - > 1 | S 0 I find the problem particularly challenging because there are so many combinations and I have no clue these how to exhaustively enumerate all possibilities. As a starter, the…
zell
  • 9,830
  • 10
  • 62
  • 115
-1
votes
1 answer

What makes this example a context-free language rather than regular language?

I'm having trouble seeing what makes "any number of a's followed by the same number of b's and c's" a context-free language, while "any number of a's followed by any number of b's followed by any number of c's" is a regular language, as I saw…
-1
votes
1 answer

How to remove left recursion from A -> Aα | ε

I think the left-recursion for this grammar is not removable. Correct me if I am wrong. α is Alpha that is a Non-terminal ε is Epsilon.
-1
votes
1 answer

How to solve shift/reduce conflict using operator precedence?

So I have this grammar I'm trying to build an LR(1) table for E' -> E E -> E + E E -> E * E E -> ( E ) E -> a So far, this my table I'm trying to solve the conflicts here. I thought about changing the grammar to…
Ruba Sbeih
  • 27
  • 1
  • 6
-1
votes
1 answer

How do i check the ambiguity in this grammar:-

E->EE+/E(E)/id Check if the given grammar is ambiguous. Also, it would be of a great help if you could tell me the process to remove the ambiguity. I tried making the parse tree for it but could not figure out how to actually make it to find an…
-1
votes
1 answer

Formal grammar to express inner join

I have a language that describe a domain by predicates of arbitrary arity. For example, in first-order logic I can write the following rule: PersonlivesInCountry(x,y) <-> person(x), PersonlivesInState(x,z), StateisInCountry(z,y) In this exampple,…
Wall
  • 293
  • 3
  • 13
-1
votes
1 answer

Is creating a context-free-grammar parser easy?

Is creating a context-free-grammar parser easy? Can they be created automatically via generators? Are there any paper about this topic?
Bighted19
  • 119
  • 7
-1
votes
1 answer

What is wrong with this grammar?

Getting this error. I'm pasting a part of the error and grammar rules. parser.y: warning: 6 nonterminals useless in grammar [-Wother] parser.y: warning: 15 rules useless in grammar [-Wother] parser.y:95.1-16: warning: nonterminal useless in…
afsara_ben
  • 542
  • 1
  • 11
  • 30
-1
votes
1 answer

Context free grammar for a language

How would I go about writing a context free grammar for the following language: {a^x b^y c^z | x >= 0, y >= 0, z >= 0, y = x + z}