title: CFG for string of length 3
body: <p>I'm trying to create context free grammar for the following language:</p>
  
  <blockquote>
    <p>L={w∈{a,b}* | w is of the form a^nxb^n+2, where x is any string of
    length 3 in {a,b}*}</p>
  </blockquote>
  
  <p>(a is raised to the power of n, and b is raised to the power of n+2)</p>
  
  <p>My solution this far is ( _ is epsilon):</p>
  
  <p>S -> aSbb | T | _</p>
  
  <p>T -> aT | bT | _ </p>
  
  <p>However this is not correct as it for example accepts string abbb. My problem is that I don't understand how to make the T part of the grammar, how can I limit the string to be size of 3? It would not make any sense to list all the strings of length 3 in {a,b}*, or is it the only way?</p>
  
  <p>Also I'm not 100% confident if the aSbb is correct, because I think my solution is now a^nxb^2n, or am I wrong?</p>