8 Comments On This Entry

interesting idea, I don't think it would be very useful but it's definitely an interesting idea. I know of no languages that do this nor any lexer or parser generators that do this. there are some bigger issues to be worked out about how the characters actually come in and how do you tell the bottom of one thing from the top of another?

1 2 3
c ::= [1 2 3]
1 2 3
1 2 3
d ::= [1 2 3]
1 2 3

what does this mean? it's an ambiguity if you ask me.

say that the above issue is solved; there is a still the rather real issue of parsing this at all. the characters are stored in serial files yet we seek to imply that the production starts at a location ahead of the current location. If the goal is to have a nice syntax then perhaps it would be ideal to have a editor that could actually display the braces going from top to bottom. it could store it in a mark up or s-expression style language but the user need only see the pretty displayed version to edit it. you could write all sorts of neat mathematical equations in a WYSIWYG style and use all sorts of crazy syntax with a special editor.

A matrix is a linear array. The multidimensional addressing is really just math/syntactic sugar. See Cantor's work on equivalence of number of points on the line/points on the plane.

So you could write a parser with special notations for multidimensional matrices (why stop at 2?) or you could just define a grammar: the grammar would want to treat the incoming data as a linear array while allowing the user to consider it as a matrix in N dimensions. Converting it to the matrix, given the dimensions, is trivial.
Interesting question, then, is to define the grammar that allows those dimensions to be discoverable (by machine) and obvious (by eye) without being explicitly stated outside of the data. That way, changes to the data don't have to be made twice (once in representation, once in description) so you avoid a class of errors that would be easy and annoying.

I won't go to the trouble of suggesting that Lisp and XML have both got reasonable solutions to this, since this will already have occurred to you. There might be better ones, though.

The proposed grammar, as exemplified here:

1 2 3 10 0 0
c ::= [ 4 5 6 ] + [ 0 1 0 ]
7 8 9 0 0 1

is awkward in that backtracking is required. I'd need to store some number of lines, unparsed, until I get to the magic line that tells me the dimensions of the matrices being added.