Hey guys, I'm trying to write a grammar file for a MATLAB-like language, and I'm having trouble with the transpose operator. The transpose operator, represented by the single quote, can be used in a variety of different situations:<div>

<br><div><br></div><div># Transposing a variable:</div><div>myMatrix'</div><div><br></div><div># Transposing the result of a function:</div><div>myFunc( myMatrix )'</div><div><br></div><div># Transposing the result of a parenthetical:</div>

<div>(myMatrix - 1)'</div><div><br></div><div># Transposing a matrix literal:</div><div>[1,2,3]'</div><div><br></div><div><br></div><div>The first two forms are not difficult, they can be matched with simple "match" forms.  However, the parenthetical and matrix literal forms are more difficult; using begin/end blocks in the pattern matching causes <i>every </i>open parentheses or open square bracket to match, regardless of whether or not there is a transpose operator matched with the closing parentheses or square bracket.  Not only does this cause performance issues, this causes issues with nested operators such as:</div>

</div><div><br></div><div>([1,2,3]' - [4,5,6]')</div><div><br></div><div>Any ideas on how to do this the proper way?  I don't really care about matching the parentheses or the square brackets; I just care that they are present. Positive look-behind assertions would work fabulously here, but they can't be variable-length, so that's a no-go here.</div>

<div><br></div><div>Thanks!</div><div>-E</div>