@@ -151,6 +151,15 @@ private void print_hs(List<HashSet<int>> lhs, string prefix)
151151 $ "{ prefix } ({ production_rules [ i ] . production_name } )={{{string.Join(", ", lhs[i].ToList().Select(x => x == -1 ? " $" : production_rules[ x ] . production_name ) ) } } } \r \n ") ;
152152 }
153153
154+ private void print_header ( string head_text )
155+ {
156+ GlobalPrinter . Append ( "\r \n " + new string ( '=' , 50 ) + "\r \n \r \n " ) ;
157+ int spaces = 50 - head_text . Length ;
158+ int padLeft = spaces / 2 + head_text . Length ;
159+ GlobalPrinter . Append ( head_text . PadLeft ( padLeft ) . PadRight ( 50 ) ) ;
160+ GlobalPrinter . Append ( "\r \n \r \n " + new string ( '=' , 50 ) + "\r \n " ) ;
161+ }
162+
154163 private void print_states ( int state , List < Tuple < int , int , int , HashSet < int > > > items )
155164 {
156165 var builder = new StringBuilder ( ) ;
@@ -275,6 +284,7 @@ public void Generate()
275284 FOLLOW [ rule . Last ( ) . index ] . Add ( r ) ;
276285
277286#if true
287+ print_header ( "FISRT, FOLLOW SETS" ) ;
278288 print_hs ( FIRST , "FIRST" ) ;
279289 print_hs ( FOLLOW , "FOLLOW" ) ;
280290#endif
@@ -423,6 +433,7 @@ public void GenerateLR1()
423433 FOLLOW [ rule . Last ( ) . index ] . Add ( r ) ;
424434
425435#if true
436+ print_header ( "FISRT, FOLLOW SETS" ) ;
426437 print_hs ( FIRST , "FIRST" ) ;
427438 print_hs ( FOLLOW , "FOLLOW" ) ;
428439#endif
@@ -571,6 +582,7 @@ public void GenerateLR1()
571582 if ( shift_tokens . ContainsKey ( tuple . Item1 ) )
572583 {
573584#if true
585+ print_header ( "SHIFT-REDUCE CONFLICTS" ) ;
574586 GlobalPrinter . Append ( $ "Shift-Reduce Conflict! { ( tuple . Item1 == - 1 ? "$" : production_rules [ tuple . Item1 ] . production_name ) } \r \n ") ;
575587 GlobalPrinter . Append ( $ "States: { ms . Key } { tuple . Item2 } \r \n ") ;
576588 print_states ( ms . Key , states [ ms . Key ] ) ;
@@ -632,6 +644,7 @@ public void GenerateLR1()
632644
633645 number_of_states = states . Count ;
634646#if true
647+ print_header ( "STATES INFO" ) ;
635648 foreach ( var s in states )
636649 print_states ( s . Key , s . Value ) ;
637650#endif
@@ -689,6 +702,7 @@ public void GenerateLALR()
689702 FOLLOW [ rule . Last ( ) . index ] . Add ( r ) ;
690703
691704#if true
705+ print_header ( "FISRT, FOLLOW SETS" ) ;
692706 print_hs ( FIRST , "FIRST" ) ;
693707 print_hs ( FOLLOW , "FOLLOW" ) ;
694708#endif
@@ -773,6 +787,7 @@ public void GenerateLALR()
773787 }
774788
775789#if true
790+ print_header ( "UNMERGED STATES" ) ;
776791 foreach ( var s in states )
777792 print_states ( s . Key , s . Value ) ;
778793#endif
@@ -806,6 +821,7 @@ public void GenerateLALR()
806821 }
807822
808823#if true
824+ print_header ( "MERGED STATES WITH SOME SETS" ) ;
809825 foreach ( var s in merged_states )
810826 print_merged_states ( s . Key , states [ s . Key ] , s . Value . Select ( x => states [ x ] . Select ( y => y . Item4 . ToList ( ) ) . ToList ( ) ) . ToList ( ) ) ;
811827#endif
@@ -821,6 +837,7 @@ public void GenerateLALR()
821837 }
822838
823839#if true
840+ print_header ( "MERGED STATES" ) ;
824841 foreach ( var s in merged_states )
825842 print_states ( s . Key , states [ s . Key ] ) ;
826843#endif
@@ -866,6 +883,7 @@ public void GenerateLALR()
866883 if ( shift_tokens . ContainsKey ( tuple . Item1 ) )
867884 {
868885#if true
886+ print_header ( "SHIFT-REDUCE CONFLICTS" ) ;
869887 GlobalPrinter . Append ( $ "Shift-Reduce Conflict! { ( tuple . Item1 == - 1 ? "$" : production_rules [ tuple . Item1 ] . production_name ) } \r \n ") ;
870888 GlobalPrinter . Append ( $ "States: { ms . Key } { tuple . Item2 } \r \n ") ;
871889 print_states ( ms . Key , states [ ms . Key ] ) ;
@@ -931,6 +949,7 @@ public void GenerateLALR()
931949
932950 public void PrintStates ( )
933951 {
952+ print_header ( "FINAL STATES" ) ;
934953 for ( int i = 0 ; i < number_of_states ; i ++ )
935954 {
936955 var builder = new StringBuilder ( ) ;
@@ -1042,8 +1061,8 @@ public void PrintTable()
10421061 builder . Append ( "\r \n " ) ;
10431062 }
10441063 builder . Append ( split_line ) ;
1045-
1046-
1064+
1065+ print_header ( "PARSING TABLE" ) ;
10471066 GlobalPrinter . Append ( builder . ToString ( ) + "\r \n " ) ;
10481067 }
10491068
0 commit comments