@@ -151,6 +151,15 @@ private void print_hs(List<HashSet<int>> lhs, string prefix)
151
151
$ "{ prefix } ({ production_rules [ i ] . production_name } )={{{string.Join(", ", lhs[i].ToList().Select(x => x == -1 ? " $" : production_rules[ x ] . production_name ) ) } } } \r \n ") ;
152
152
}
153
153
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
+
154
163
private void print_states ( int state , List < Tuple < int , int , int , HashSet < int > > > items )
155
164
{
156
165
var builder = new StringBuilder ( ) ;
@@ -275,6 +284,7 @@ public void Generate()
275
284
FOLLOW [ rule . Last ( ) . index ] . Add ( r ) ;
276
285
277
286
#if true
287
+ print_header ( "FISRT, FOLLOW SETS" ) ;
278
288
print_hs ( FIRST , "FIRST" ) ;
279
289
print_hs ( FOLLOW , "FOLLOW" ) ;
280
290
#endif
@@ -423,6 +433,7 @@ public void GenerateLR1()
423
433
FOLLOW [ rule . Last ( ) . index ] . Add ( r ) ;
424
434
425
435
#if true
436
+ print_header ( "FISRT, FOLLOW SETS" ) ;
426
437
print_hs ( FIRST , "FIRST" ) ;
427
438
print_hs ( FOLLOW , "FOLLOW" ) ;
428
439
#endif
@@ -571,6 +582,7 @@ public void GenerateLR1()
571
582
if ( shift_tokens . ContainsKey ( tuple . Item1 ) )
572
583
{
573
584
#if true
585
+ print_header ( "SHIFT-REDUCE CONFLICTS" ) ;
574
586
GlobalPrinter . Append ( $ "Shift-Reduce Conflict! { ( tuple . Item1 == - 1 ? "$" : production_rules [ tuple . Item1 ] . production_name ) } \r \n ") ;
575
587
GlobalPrinter . Append ( $ "States: { ms . Key } { tuple . Item2 } \r \n ") ;
576
588
print_states ( ms . Key , states [ ms . Key ] ) ;
@@ -632,6 +644,7 @@ public void GenerateLR1()
632
644
633
645
number_of_states = states . Count ;
634
646
#if true
647
+ print_header ( "STATES INFO" ) ;
635
648
foreach ( var s in states )
636
649
print_states ( s . Key , s . Value ) ;
637
650
#endif
@@ -689,6 +702,7 @@ public void GenerateLALR()
689
702
FOLLOW [ rule . Last ( ) . index ] . Add ( r ) ;
690
703
691
704
#if true
705
+ print_header ( "FISRT, FOLLOW SETS" ) ;
692
706
print_hs ( FIRST , "FIRST" ) ;
693
707
print_hs ( FOLLOW , "FOLLOW" ) ;
694
708
#endif
@@ -773,6 +787,7 @@ public void GenerateLALR()
773
787
}
774
788
775
789
#if true
790
+ print_header ( "UNMERGED STATES" ) ;
776
791
foreach ( var s in states )
777
792
print_states ( s . Key , s . Value ) ;
778
793
#endif
@@ -806,6 +821,7 @@ public void GenerateLALR()
806
821
}
807
822
808
823
#if true
824
+ print_header ( "MERGED STATES WITH SOME SETS" ) ;
809
825
foreach ( var s in merged_states )
810
826
print_merged_states ( s . Key , states [ s . Key ] , s . Value . Select ( x => states [ x ] . Select ( y => y . Item4 . ToList ( ) ) . ToList ( ) ) . ToList ( ) ) ;
811
827
#endif
@@ -821,6 +837,7 @@ public void GenerateLALR()
821
837
}
822
838
823
839
#if true
840
+ print_header ( "MERGED STATES" ) ;
824
841
foreach ( var s in merged_states )
825
842
print_states ( s . Key , states [ s . Key ] ) ;
826
843
#endif
@@ -866,6 +883,7 @@ public void GenerateLALR()
866
883
if ( shift_tokens . ContainsKey ( tuple . Item1 ) )
867
884
{
868
885
#if true
886
+ print_header ( "SHIFT-REDUCE CONFLICTS" ) ;
869
887
GlobalPrinter . Append ( $ "Shift-Reduce Conflict! { ( tuple . Item1 == - 1 ? "$" : production_rules [ tuple . Item1 ] . production_name ) } \r \n ") ;
870
888
GlobalPrinter . Append ( $ "States: { ms . Key } { tuple . Item2 } \r \n ") ;
871
889
print_states ( ms . Key , states [ ms . Key ] ) ;
@@ -931,6 +949,7 @@ public void GenerateLALR()
931
949
932
950
public void PrintStates ( )
933
951
{
952
+ print_header ( "FINAL STATES" ) ;
934
953
for ( int i = 0 ; i < number_of_states ; i ++ )
935
954
{
936
955
var builder = new StringBuilder ( ) ;
@@ -1042,8 +1061,8 @@ public void PrintTable()
1042
1061
builder . Append ( "\r \n " ) ;
1043
1062
}
1044
1063
builder . Append ( split_line ) ;
1045
-
1046
-
1064
+
1065
+ print_header ( "PARSING TABLE" ) ;
1047
1066
GlobalPrinter . Append ( builder . ToString ( ) + "\r \n " ) ;
1048
1067
}
1049
1068
0 commit comments