public static int[,] GetMatrixFromCode(string code) { var graph = new Graph <SStatement>(); var tokens = PLexer.ParseTokens(code); PParser.GetFunctionContents(tokens).First().BuildGraphNodes(graph); RemoveUnvisible(graph); return(graph.GetMatrix()); }
private void DisplayProgram(string program) { try { var tokens = PLexer.ParseTokens(program); foreach (var matchedFunction in PParser.GetFunctionContents(tokens)) { var graph = new Graph <SStatement>(); matchedFunction.BuildGraphNodes(graph); RemoveUnvisible(graph); var matrix = graph.GetMatrix(); dataGridView1.ColumnCount = matrix.GetLength(0); dataGridView1.RowCount = matrix.GetLength(1); dataGridView1.ColumnHeadersHeight = 4; dataGridView1.RowHeadersWidth = 4; for (var i0 = 0; i0 < matrix.GetLength(0); i0++) { dataGridView1.Columns[i0].HeaderText = (i0 + 1).ToString(); dataGridView1.Columns[i0].Width = 17; for (var i1 = 0; i1 < matrix.GetLength(1); i1++) { dataGridView1[i1, i0].Value = matrix[i0, i1]; } } } } catch (ArgumentException exc) { MessageBox.Show(@"There is an error in source code: " + exc.Message); } catch (InvalidOperationException exc) { MessageBox.Show(@"There is an error in source code: " + exc.Message); } catch { MessageBox.Show(@"An unexpected error occured!"); } }