That's very poor wording, so let me be more precise. Suppose $L$ is an unambiguous regular language on an alphabet $\{a\_1, \dots, a\_n\}$, and suppose to each letter of the alphabet we associate two non-negative integers $(x\_i,y\_i)$ which are not both zero. Associate to a word $w$ the sum of the pairs of integers associated to each of its letters; call this $M(w) = (x, y)$.


Let $L'$ be the language consisting of all words such that $M(w) = (x, x)$ for some $x$. Is $L'$ an unambiguous context-free language?



Is the "diagonal" of a regular language always context-free?
Yes.


There's no reason to have two nonnegative integers, you can just use one integer xi-yi. Then you care about whether the sum is zero. The language K of things which sum to zero is recognized by a push down automata -- the stack is always just a bunch of +1 tokens or -1 tokens corresponding to the current sum. Since K is recognized by a push down automata, it is context free.


The language you are interested in is L intersect K. The intersection of a regular language and a context free language is always context free.


