public override void VisitMatrixData(MatrixData element) { String MatrixValues = element.getText(); int rowsize = 0, colsize = 0; for (int i = 1; i < MatrixValues.LastIndexOf(']'); i++) { if (MatrixValues[i] == ',') { colsize++; continue; } if (MatrixValues[i] == '[') continue; if (MatrixValues[i] == ']') { rowsize++; continue; } int element_value = int.Parse(MatrixValues[i].ToString()); mStack.Push(element_value); } colsize = (colsize / rowsize) + 1; int[,] mat = new int[rowsize, colsize]; for (int i = rowsize - 1; i >= 0; i--) for (int j = colsize - 1; j >= 0; j--) { int result = mStack.Pop(); mat[i, j] = result; } matStack.Push(mat); }