Questions tagged [context-free-language]

In formal language theory, a context-free language (CFL) is a language generated by some context-free grammar (CFG). The set of regular languages is a subset of the set of context-free languages.

183 questions
1
vote
2 answers

Automata: CFG for following language

Please have look at following language : (a, b, c)* − {anbncn|n≥0} My question is: How do I write a Context-Free Grammar for it ? In general how can I write a grammar when something is excludes from it (i.e. has "-" sign) ?
1
vote
1 answer

Recursion in EBNF

The problem is: a. Write a directly recursive EBNF rule named mp that describes all symbols that have matching parentheses: (), ()()(), ()(()()), and ((())())(()(()))(). It should not recognize (, ())(, or (()() as legal. b. Write a tabular proof…
Vlad
  • 2,739
  • 7
  • 49
  • 100
1
vote
2 answers

Context Free Grammar for unequal number of symbols

I'm aware of how it is possible to construct a context free grammar with the same number of two given elements ie. if we use {0,1} S->SS S->0S1 S->1S0 S->ε I am however struggling to find a way to construct a grammar that has a given amount of one…
1
vote
1 answer

Is the complement of any context free language context free?

I read multiple answers that state if a language is not context free, then its complement is context free (correct me if I am wrong). Is this true for the opposite? the complement of a context free language is context free?
1
vote
1 answer

How to write a CFG with functions?

In an Assignment, I was asked to write a CFG for functions like: def f(x, y): return x + y def g(x, y): return x – y def h(x, y, z): return x + y % z def w(x, y, z): return x * y – z and def h1(x, y, z): return (x + y) % z def h2(x, y, z): return x…
1
vote
1 answer

G is CFG, Is L(G) Regular

G is a given CFG, is L(G) regular? It's an undecidable problem. But My argument is, Language is given and if i can do any of the following things then it will be regular else non-regular: Creation of DFA/NFA Writing Left Linear or Right Linear…
Manu Thakur
  • 345
  • 5
  • 11
1
vote
1 answer

How can we distinguish between regular languages and context free languages?

to express regular languages we use regexp and for context free languages we can use an stack-like memory, I know context free languages have some specifications like center embedding, but still I'm not sure when we can be confidant a given language…
user3070752
  • 694
  • 4
  • 23
1
vote
1 answer

Trying to understand parsing and scanning (difference for reg. languages and cf languages)

First off,I don't study Computer Science, I'm just interested in the subject. A parser basically does this right: reading the input create tokens actually parse tokens and create an AST So I thought that in order to decide whether a word is in a…
user3629892
  • 2,960
  • 9
  • 33
  • 64
1
vote
1 answer

Multiplying using a CFG

I am trying to make a CFG that is equivalent the function below. I know that B is the loop counter so it could be a series of elements pushed onto a stack, every time the loop is completed an element from B is popped and if B = Epsilon quit. How do…
CodeMonkey
  • 268
  • 5
  • 16
1
vote
0 answers

Proving that CFG generates a language

I need to construct a CFG for the language consisting of even length palindromes with the same number of a's and b's and then prove that it generates that language. This is the CFG I got: S→ abba | baab | abSba | baSab | ε I'm unsure of what to do…
1
vote
1 answer

Is This Language Regular or not?

I have the language {4^(w⋅g)34^(g)|w,g∈NAT} over the alphabet {0,1}. I need to find out if this language is recognizable, decidable, context free, regular or none of these. How would i go about doing that or knowing? Thanks
1
vote
2 answers

Find a grammar of binary number divisible by 5 with 1 as MSB

How can I find a grammar of binary number divisible by 5 with 1 as MSB and find the reversal of L So, I need a grammar that generates numbers like.. 5 = 101 10 = 1010 15 = 1111 20 = 10100 25 = 110011 and so on
1
vote
2 answers

Regenerating a context free grammar

I need to generate unambiguous grammar to access the language L= { a^i b^j c^k | i, j, k ≥ 0 , i = j or i = k } What I already have is: S : X | Y X : TC T : aTb | ԑ C : cC | ԑ Y : aYc | F F : bF | ԑ but this grammar is ambiguous, it can recognize…
1
vote
1 answer

How to generate string using a JSGF grammar in Java?

JSpeech Grammar Format allows user to specify tags for separate strings in curly brackets as follows: = jump { primitive jump } [up] | jump [to the] (left { primitive jump_left } |right { primitive jump_right } ); or =…
smihael
  • 863
  • 13
  • 29
1
vote
1 answer

Construct a context-free grammar from this language

Language: {a^m b^n : m ≤ 2n} If someone could give advice on how to approach this to construct the grammar as well as a solution that would be great and much appreciated!
Schwarz
  • 395
  • 4
  • 18