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:
# Transposing a variable: myMatrix'
# Transposing the result of a function: myFunc( myMatrix )'
# Transposing the result of a parenthetical: (myMatrix - 1)'
# Transposing a matrix literal: [1,2,3]'
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 *every *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:
([1,2,3]' - [4,5,6]')
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.
Thanks! -E