kaby76 / one-parser

0 stars 2 forks source link

Grammar has large number of full-stack context fallbacks #4

Open kaby76 opened 2 weeks ago

kaby76 commented 2 weeks ago

The main issue is that there are fallbacks to full context associated with expressions. Consider the example from the ALL(*) Tech paper.

S → xB | yC ; B → Aa ; C → Aba ; A → b | ε

This in Antlr4 syntax is:

grammar Check;
start : ('x' b | 'y' c) EOF;
b : a 'a';
c : a 'b' 'a';
a : 'b' | ;

As stated in the paper, [w]ithout the parser stack, no amount of lookahead can uniquely distinguish between A’s productions. Lookahead ba predicts A → b when B invokes A but predicts A → ε when C invokes A. If prediction ignores the parser call stack, there is a prediction conflict upon ba.

If you then try parsing 'xba' using trperf, you see the fallback an large k.

$ echo -n xba | trperf -h | column -t
Time to parse: 00:00:00.0280765
File   Decision  Rule   Invocations  Time      Total-k  Max-k  Fallback  Ambiguities  Errors  Transitions  Input
stdin  0         start  0            0         0        0      0         0            0       0
stdin  1         a      1            0.102433  3        2      1         0            0       3            ba

This can be fixed by not trying to "share" the rule A over different rules.

grammar Check;
start : ('x' b | 'y' c) EOF;
b : ap 'a';
c : a 'b' 'a';
a : 'b' | ;
ap : 'b' | ;
$ echo -n xba | trperf -h | column -t
Time to parse: 00:00:00.0176862
File   Decision  Rule   Invocations  Time  Total-k  Max-k  Fallback  Ambiguities  Errors  Transitions  Input
stdin  0         start  0            0     0        0      0         0            0       0
stdin  1         a      0            0     0        0      0         0            0       0
stdin  2         ap     0            0     0        0      0         0            0       0

Here is the trperf for Pattern

$ trperf ../examples/PatternTest.on -h | column -t
Time to parse: 00:00:18.3212021
File                        Decision  Rule                                                Invocations  Time       Total-k  Max-k  Fallback  Ambiguities  Errors  Transitions  Input
../examples/PatternTest.on  0         compilation_unit                                    1            0.135335   1        1      0         0            0       1            import
../examples/PatternTest.on  1         compilation_unit                                    1            0.038472   1        1      0         0            0       1            import
../examples/PatternTest.on  2         compilation_unit                                    1            0.034105   1        1      0         0            0       1            import
../examples/PatternTest.on  3         compilation_unit                                    1            0.073516   3        3      0         0            0       2            import                  System
../examples/PatternTest.on  4         compilation_unit                                    3            0.035181   3        1      0         0            0       2            import
../examples/PatternTest.on  5         compilation_unit                                    1            0.03414    1        1      0         0            0       1            namespace
../examples/PatternTest.on  6         compilation_unit                                    9            0.015476   9        1      0         0            0       2            namespace
../examples/PatternTest.on  7         compilation_unit                                    10           0.034038   10       1      0         0            0       2            namespace
../examples/PatternTest.on  8         indented_extern_alias_block                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  9         indented_extern_alias_block                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  10        using_section                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  11        using_section                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  12        indented_using_block                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  13        indented_using_block                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  14        using_directive                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  15        using_directive                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  16        using_directive                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  17        using_directive                                     3            0.051017   6        2      0         0            0       3            System\n
../examples/PatternTest.on  18        indented_using_directive                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  19        indented_using_directive                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  20        indented_using_directive                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  21        indented_using_directive                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  22        identifier_name                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  23        name                                                240          0.24424    513      3      0         0            0       19           greeting                is
../examples/PatternTest.on  24        name                                                308          12.325373  880      23     51        0            0       251          .Write(x[0]             +                                 x[1]                              +                                 x[2])\n\n                                    
../examples/PatternTest.on  25        indented_cascade_name_block                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  26        indented_cascade_name_block                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  27        name_element                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  28        simple_name                                         314          1.514066   770      20     2         0            0       66           List<char>              {                                 'a',                              'b',                              'c',                                         'd'         }\n           
../examples/PatternTest.on  29        type_argument_list                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  30        type_argument_list                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  31        attribute_list                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  32        attribute_list                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  33        attribute_list                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  34        attribute                                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  35        attribute_argument_list                             0            0          0        0      0         0            0       0            
../examples/PatternTest.on  36        attribute_argument_list                             0            0          0        0      0         0            0       0            
../examples/PatternTest.on  37        attribute_argument                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  38        attribute_argument                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  39        attribute_argument                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  40        member_declaration                                  77           9.588495   2372     666    1         0            0       632          TestArray():\n\n        //                                Array                             declaration\n                     o                                            int[]       =             new         int[5]\n     o[0]                   =           1\n\n        //     Array      allocation\n  x      int[]  =    new   int[3]\n\n  //  Array  assignment\n  x[0]  =         1\n     x[1]  =   2\n  x[2]   =          3\n\n     y             int[]  =  new  int[]  {  1,  2,  3,  6  }\n\n  z  int[]  =  {  1,  2,  3  }\n\n  Console.Write(x[0]  +  x[1]  +  x[2])\n\n  a  string[,]  =  new  string[2,2]\n\n  a[0,  0]  =  '00';  a[0,  1]  =  '01'\n  a[1,  0]  =  '10';  a[1,  1]  =  '11'\n\n  b  string[,]  =  {  {  '00',  '01'  },  {  '10',  '11'  }  }\n\n  c  string[][]  =  new  string[2][]\n\n  c[0]  =  new  string[1];  c[0][0]  =  '00'\n  c[1]  =  new  string[2];  c[1][0]  =  '10';  c[1][1]  =  '11'\n\n  d  string[][]  =  {  new  string[]  {  '00',  '01'  },  new  string[]  {  '10',  '11'  }  }\n\n  xs  var  =  new[]  {  4,  7,  9  }\n  bs  var  =  new[]  {  \"hello\",  null,  \"world\"  }\n\n  x2  var  =  new[,]  {  {  4,  7  },  {  10,  11  }  }\n  x4  var  =  new[,,]  {  {  {  1,  2,  3  },  {  4,  5,  6  }  },\n  {  {  7,  8,  9  },  {  10,  11,  12  }  }  }\n\n  array  var  =  new  int[]  {  1,  2,  3,  4,  5  }\n  slice1  var  =  array[2..^3]  //  array[new  Range(2,  new  Index(3,  fromEnd:  true))]\n  slice2  var  =  array[..^3]  //  array[Range.EndAt(new  Index(3,  fromEnd:  true))]\n  slice3  var  =  array[2..]  //  array[Range.StartAt(2)]\n  slice4  var  =  array[..]  //  array[Range.All]\n\n  //  stackalloc\n  storage  Span<int>  =  stackalloc  int[10]\n  storage  =  stackalloc[]  {  1,  2,  3,  4,  5,  6  }\n\n\n
../examples/PatternTest.on  41        base_field_declaration                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  42        event_field_declaration                             0            0          0        0      0         0            0       0            
../examples/PatternTest.on  43        event_field_declaration                             0            0          0        0      0         0            0       0            
../examples/PatternTest.on  44        event_field_declaration                             0            0          0        0      0         0            0       0            
../examples/PatternTest.on  45        modifier                                            63           0.001025   63       1      0         0            0       7            public
../examples/PatternTest.on  46        extended_modifier                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  47        variable_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  48        variable_declaration                                37           0.272985   37       1      0         0            0       1            =
../examples/PatternTest.on  49        variable_declarator                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  50        bracketed_argument_list                             0            0          0        0      0         0            0       0            
../examples/PatternTest.on  51        argument                                            174          1.368398   244      4      2         0            0       24           paramName:              nameof
../examples/PatternTest.on  52        argument                                            174          0.003216   174      1      0         0            0       11           message
../examples/PatternTest.on  53        argument                                            174          7.031908   925      31     0         0            0       182          TakeFive(new[]          {                                 '1',                              '2',                              '3',                                         '4',        '5',          '6',        '7'          }))
../examples/PatternTest.on  54        one_argument                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  55        equals_multiple_value_clause                        38           0.505058   42       5      0         0            0       6            ,                       0\n                               foreach
../examples/PatternTest.on  56        field_declaration                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  57        field_declaration                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  58        field_declaration                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  59        access_level_section                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  60        base_method_declaration                             33           0.007088   136      9      0         0            0       11           private                 static                            GetSourceLabel<T>(
../examples/PatternTest.on  61        parameter_list                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  62        parameter_list                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  63        parameter                                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  64        parameter                                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  65        parameter                                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  66        parameter                                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  67        parameter                                           34           0.001129   94       3      0         0            0       8            source                  IEnumerable
../examples/PatternTest.on  68        one_parameter                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  69        one_parameter                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  70        one_parameter                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  71        one_parameter                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  72        argument_list                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  73        argument_list                                       112          0.007817   112      1      0         0            0       11           message
../examples/PatternTest.on  74        block                                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  75        block                                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  76        statement_block                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  77        statement_block                                     23           0.005214   49       3      0         0            0       4            :                       Console
../examples/PatternTest.on  78        labeled_statement_block                             0            0          0        0      0         0            0       0            
../examples/PatternTest.on  79        labeled_statement_block                             0            0          0        0      0         0            0       0            
../examples/PatternTest.on  80        unindented_statement_block                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  81        unindented_statement_block                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  82        statement_block_without_colon                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  83        statement_block_without_colon                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  84        small_statements                                    2            0.326029   2        1      0         0            0       1            
../examples/PatternTest.on  85        small_statements                                    2            0.930965   6        2      2         0            0       5            else
../examples/PatternTest.on  86        small_statement                                     2            1.004016   27       20     1         0            0       21           throw                   new                               ArgumentNullException(paramName:  nameof(car),\n                    message:                                     'Car        should        not         be           null')\n\n             
../examples/PatternTest.on  87        small_expression_statement                          1            0.001642   1        1      0         0            0       1            Console
../examples/PatternTest.on  88        indented_statement_block                            92           0.008459   92       1      0         0            0       6            if
../examples/PatternTest.on  89        indented_statement_block                            92           0.006711   92       1      0         0            0       5            if
../examples/PatternTest.on  90        conversion_operator_declaration                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  91        conversion_operator_declaration                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  92        conversion_operator_declaration                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  93        conversion_operator_declaration                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  94        conversion_operator_declaration                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  95        conversion_operator_declaration                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  96        conversion_operator_declaration                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  97        destructor_declaration                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  98        destructor_declaration                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  99        destructor_declaration                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  100       destructor_declaration                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  101       method_or_constructor_declaration                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  102       method_or_constructor_declaration                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  103       method_or_constructor_declaration                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  104       method_or_constructor_declaration                   33           0.001219   70       5      0         0            0       6            GetSourceLabel<T>(
../examples/PatternTest.on  105       method_or_constructor_declaration                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  106       method_or_constructor_declaration                   33           1.625321   149      94     0         0            0       64           Point\n\n               =>                                point                             switch:\n                         (x,                                          y)          var           when        x            <                      y           =>           new    Point(-x,  y),\n         (x,    y)     var  when  x           >   y      =>            new   Point(x,  -y),\n  (x,   y)  var  =>     new        Point(x,  y)\n\n\n
../examples/PatternTest.on  107       method_or_constructor_declaration                   33           0.471052   33       1      0         0            0       2            :
../examples/PatternTest.on  108       method_or_constructor_declaration                   33           0.334656   51       3      0         0            0       3            :\n\n                   //                                Array                             declaration\n                     
../examples/PatternTest.on  109       method_or_constructor_declaration                   33           0.342976   33       1      0         0            0       2            :
../examples/PatternTest.on  110       type_parameter_list                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  111       type_parameter                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  112       type_parameter                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  113       type_parameter_constraint_clause                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  114       type_parameter_constraint                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  115       class_or_struct_constraint                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  116       class_or_struct_constraint                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  117       class_or_struct_constraint                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  118       operator_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  119       operator_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  120       operator_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  121       operator_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  122       operator_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  123       operator_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  124       base_namespace_declaration                          9            0.08369    70       8      0         0            0       6            namespace               ONE.Test.DeclarationPattern:
../examples/PatternTest.on  125       file_scoped_namespace_declaration                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  126       file_scoped_namespace_declaration                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  127       file_scoped_namespace_declaration                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  128       file_scoped_namespace_declaration                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  129       file_scoped_namespace_declaration                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  130       file_scoped_namespace_declaration                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  131       file_scoped_namespace_declaration                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  132       file_scoped_namespace_declaration                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  133       indented_namespace_declaration                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  134       indented_namespace_declaration                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  135       indented_namespace_block                            9            0.037932   9        1      0         0            0       3            public
../examples/PatternTest.on  136       indented_namespace_block                            9            0.034839   9        1      0         0            0       3            public
../examples/PatternTest.on  137       indented_namespace_block                            9            0.043983   11       3      0         0            0       4            import                  System
../examples/PatternTest.on  138       indented_namespace_block                            10           0.03564    10       1      0         0            0       3            public
../examples/PatternTest.on  139       indented_namespace_block                            13           0.011701   13       1      0         0            0       3            \n
../examples/PatternTest.on  140       indented_namespace_block                            22           0.034871   22       1      0         0            0       3            public
../examples/PatternTest.on  141       base_property_declaration                           2            0.000864   6        3      0         0            0       2            X                       int
../examples/PatternTest.on  142       event_declaration                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  143       event_declaration                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  144       event_declaration                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  145       event_declaration                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  146       accessor_list                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  147       accessor_block                                      2            0.125195   2        1      0         0            0       1            
../examples/PatternTest.on  148       accessor_block                                      2            0.004126   6        3      0         0            0       2            :                       get
../examples/PatternTest.on  149       indented_accessor_list                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  150       indented_accessor_list                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  151       accessors                                           2            0.120186   2        1      0         0            0       1            
../examples/PatternTest.on  152       accessor_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  153       accessor_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  154       accessor_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  155       accessor_declaration                                2            0.129415   2        1      0         0            0       1            
../examples/PatternTest.on  156       indexer_declaration                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  157       indexer_declaration                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  158       indexer_declaration                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  159       indexer_declaration                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  160       bracketed_parameter_list                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  161       property_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  162       property_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  163       property_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  164       property_declaration                                2            0.00042    6        3      0         0            0       2            X                       int
../examples/PatternTest.on  165       property_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  166       property_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  167       interface_accessor                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  168       interface_accessor                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  169       interface_accessor                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  170       base_type_declaration                               19           0.010983   43       5      0         0            0       9            public                  static                            class
../examples/PatternTest.on  171       enum_declaration                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  172       enum_declaration                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  173       enum_declaration                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  174       enum_block                                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  175       enum_members                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  176       enum_members                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  177       enum_members                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  178       enum_members                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  179       base_list                                           2            0.133795   2        1      0         0            0       1            :
../examples/PatternTest.on  180       enum_base_list                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  181       base_type                                           2            0.059801   4        2      0         0            0       2            Vehicle:
../examples/PatternTest.on  182       enum_member_declaration                             0            0          0        0      0         0            0       0            
../examples/PatternTest.on  183       enum_member_declaration                             0            0          0        0      0         0            0       0            
../examples/PatternTest.on  184       enum_member_declaration                             0            0          0        0      0         0            0       0            
../examples/PatternTest.on  185       type_declaration                                    19           0.005659   43       5      0         0            0       9            public                  static                            class
../examples/PatternTest.on  186       class_declaration                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  187       class_declaration                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  188       class_declaration                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  189       class_declaration                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  190       class_declaration                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  191       class_declaration                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  192       class_declaration                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  193       interface_declaration                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  194       interface_declaration                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  195       interface_declaration                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  196       interface_declaration                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  197       interface_declaration                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  198       interface_declaration                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  199       interface_declaration                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  200       record_declaration                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  201       record_declaration                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  202       record_declaration                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  203       record_declaration                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  204       record_declaration                                  6            0.168276   6        1      0         0            0       1            (
../examples/PatternTest.on  205       record_declaration                                  6            0.484258   82       17     0         0            0       19           (FName                  string,                           LName                             string,                           Age                                          int)\n      record
../examples/PatternTest.on  206       record_declaration                                  6            0.14558    6        1      0         0            0       1            
../examples/PatternTest.on  207       record_declaration                                  6            0.123073   6        1      0         0            0       1            
../examples/PatternTest.on  208       record_declaration                                  6            0.123812   6        1      0         0            0       1            
../examples/PatternTest.on  209       struct_declaration                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  210       struct_declaration                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  211       struct_declaration                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  212       struct_declaration                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  213       struct_declaration                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  214       struct_declaration                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  215       struct_declaration                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  216       indented_member_block                               55           0.012769   55       1      0         0            0       6            static
../examples/PatternTest.on  217       indented_member_block                               55           0.011874   55       1      0         0            0       7            static
../examples/PatternTest.on  218       indented_member_block                               27           0.032535   54       2      0         0            0       3            :\n\n                   
../examples/PatternTest.on  219       functionblock_declaration                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  220       functionblock_declaration                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  221       functionblock_declaration                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  222       functionblock_declaration                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  223       functionblock_declaration                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  224       functionblock_declaration                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  225       indented_functionblock_member_block                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  226       indented_functionblock_member_block                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  227       indented_functionblock_member_block                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  228       functionblock_properties                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  229       functionblock_properties                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  230       functionblock_properties                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  231       functionblock_properties                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  232       functionblock_member_declaration                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  233       functionblock_property                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  234       functionblock_valid_runmodes                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  235       indented_connector_block                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  236       indented_connector_block                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  237       connector_declaration                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  238       connector_declaration                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  239       connector_block                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  240       connector_properties                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  241       connector_row_property                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  242       functionblock_connector_properties                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  243       functionblock_connector_properties                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  244       truth_table_statement                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  245       indented_truth_table_block                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  246       indented_truth_table_block                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  247       truth_table_element                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  248       conditions                                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  249       conditions                                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  250       indented_condition_block                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  251       indented_condition_block                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  252       condition_element                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  253       condition_row                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  254       condition_row                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  255       condition_values                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  256       decisions                                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  257       indented_decision_block                             0            0          0        0      0         0            0       0            
../examples/PatternTest.on  258       indented_decision_block                             0            0          0        0      0         0            0       0            
../examples/PatternTest.on  259       decision_element                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  260       action_values                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  261       indented_action_block                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  262       indented_action_block                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  263       action_element                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  264       expression_row_types                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  265       expression_row_type                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  266       trigger_block                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  267       trigger_members                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  268       trigger_members                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  269       trigger_members                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  270       trigger_members                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  271       on_trigger_statement                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  272       statemachine_statement                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  273       statemachine_statement                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  274       indented_statemachine_block                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  275       indented_statemachine_block                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  276       statemachine_element                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  277       state                                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  278       indented_state_block                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  279       indented_state_block                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  280       indented_state_block                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  281       state_element                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  282       state_modifier_section                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  283       indented_state_element_block                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  284       indented_state_element_block                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  285       counter_declaration                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  286       counter_block                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  287       counter_members                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  288       counter_members                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  289       counter_members                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  290       counter_members                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  291       indented_cascade_block                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  292       indented_cascade_block                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  293       delegate_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  294       delegate_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  295       delegate_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  296       delegate_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  297       delegate_declaration                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  298       global_statement                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  299       global_statement                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  300       incomplete_member                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  301       incomplete_member                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  302       array_type                                          30           9.505499   274      63     4         0            0       154          []                      =                                 {                                 new                               string[]                                     {           '00',         '01'        },           new                    string[]    {            '10',  '11'       }             }\n\n  xs     var  =     new[]       {   4,     7,            9     }\n       bs
../examples/PatternTest.on  303       type                                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  304       type                                                151          24.147917  1087     67     13        0            0       383          int[]                   =                                 [..                               row0,                             ..                                           row1,       ..            row2]\n\n   twoD         int[][]                =           [[1,         2,     3],        [4,           5,     6],    [7,  8,    9]]\n
../examples/PatternTest.on  305       type                                                152          0.61045    154      3      0         0            0       13           ?                       =
../examples/PatternTest.on  306       basic_type                                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  307       array_rank_specifier                                30           0.002376   60       2      0         0            0       4            []
../examples/PatternTest.on  308       standard_rank                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  309       standard_rank                                       28           0.001699   28       1      0         0            0       2            ]
../examples/PatternTest.on  310       multi_dim_rank                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  311       function_pointer_type                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  312       function_pointer_calling_convention                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  313       function_pointer_calling_convention                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  314       function_pointer_calling_convention                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  315       function_pointer_unmanaged_calling_convention_list  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  316       function_pointer_parameter_list                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  317       function_pointer_parameter                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  318       function_pointer_parameter                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  319       ref_type                                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  320       tuple_type                                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  321       tuple_element                                       2            0.000828   6        3      0         0            0       3            Sum                     double
../examples/PatternTest.on  322       basic_statement                                     92           17.771133  2545     75     35        0            0       962          x4                      var                               =                                 new[,,]                           {                                            {           {             1,          2,           3                      },          {            4,     5,         6             }      },\n   {    {     7,          8,  9      },            {     10,       11,     12    }   }    }\n\n  array
../examples/PatternTest.on  323       indented_const_variable_block                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  324       indented_const_variable_block                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  325       break_statement                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  326       checked_statement                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  327       common_for_each_statement                           1            0.569674   44       22     1         0            0       32           foreach                 number                            int                               in                                numbers:\n                                   sum         +=            number\n    count++\n\n  
../examples/PatternTest.on  328       for_each_statement                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  329       for_each_statement                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  330       for_each_statement                                  1            0.751795   15       15     0         0            0       13           numbers:\n              sum                               +=                                number\n                          count++\n\n                                  return
../examples/PatternTest.on  331       for_each_statement                                  1            0.225519   1        1      0         0            0       1            :
../examples/PatternTest.on  332       for_each_variable_statement                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  333       for_each_variable_statement                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  334       for_each_variable_statement                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  335       continue_statement                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  336       do_statement                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  337       do_statement                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  338       do_statement                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  339       do_statement                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  340       empty_statement                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  341       expression_statement                                49           0.002611   49       1      0         0            0       1            Console
../examples/PatternTest.on  342       fixed_statement                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  343       for_statement_basic                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  344       for_statement_basic                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  345       for_statement_basic                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  346       for_statement_basic                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  347       for_statement_basic                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  348       for_colon_extension                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  349       for_colon_extension                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  350       for_colon_extension                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  351       for_colon_extension                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  352       for_to_extension                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  353       for_to_extension                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  354       for_to_extension                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  355       for_while_extension                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  356       for_while_extension                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  357       for_while_extension                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  358       expressions                                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  359       goto_statement                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  360       goto_statement                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  361       goto_statement                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  362       if_statement                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  363       if_statement                                        4            1.50843    58       24     0         0            0       31           SumAndCount(numbers)    is                                (Sum:                             sum                               var,                                         Count:      >             0):
../examples/PatternTest.on  364       if_statement                                        4            0.242398   4        1      0         0            0       1            :
../examples/PatternTest.on  365       if_statement                                        4            1.23294    30       26     1         0            0       23           else:                   throw                             new                               ArgumentNullException(paramName:  nameof(car),\n                               message:    'Car          should      not          be                     null')\n\n  private
../examples/PatternTest.on  366       else_clause                                         1            0.165686   1        1      0         0            0       1            :
../examples/PatternTest.on  367       else_clause                                         1            0.169388   1        1      0         0            0       1            :
../examples/PatternTest.on  368       labeled_statement                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  369       local_declaration_statement                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  370       local_declaration_statement                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  371       local_declaration_statement                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  372       local_declaration_statement                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  373       local_declaration_statement                         37           1.0128     73       1      36        0            0       38           
../examples/PatternTest.on  374       local_function_statement                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  375       local_function_statement                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  376       local_function_statement                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  377       local_function_statement                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  378       local_function_statement                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  379       local_function_statement                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  380       lock_statement                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  381       return_statement                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  382       return_statement                                    1            1.650831   15       8      1         0            0       13           (sum,                   count)\n\n                        
../examples/PatternTest.on  383       switch_statement                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  384       switch_statement                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  385       switch_statement                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  386       switch_section                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  387       switch_section                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  388       switch_label                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  389       case_pattern_switch_label                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  390       case_pattern_switch_label                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  391       one_switch_statement                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  392       one_switch_statement                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  393       one_switch_statement                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  394       switch_sections                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  395       switch_sections                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  396       one_switch_section                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  397       one_case_section                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  398       one_switch_label                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  399       one_case_switch_label                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  400       one_case_pattern_switch_label                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  401       one_case_pattern_switch_label                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  402       one_case_section_element                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  403       one_case_section_element                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  404       with_expression                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  405       with_expression                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  406       left_with_expressions                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  407       right_with_expressions                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  408       left_with_expression                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  409       right_with_expression                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  410       right_with_expression                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  411       alias_expression                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  412       pattern                                             116          8.439723   674      24     41        0            0       306          _                       =>                                throw                             new                               ArgumentOutOfRangeException(nameof(date),\n  $\"Date     with          unexpected  month:       {date.Month}.\"),
../examples/PatternTest.on  413       pattern                                             133          0.932647   150      1      17        0            0       32           =>
../examples/PatternTest.on  414       variable_designation                                24           0.177477   26       1      2         0            0       5            message
../examples/PatternTest.on  415       parenthesized_variable_designation                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  416       parenthesized_variable_designation                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  417       list_pattern                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  418       list_pattern                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  419       list_pattern                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  420       list_pattern                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  421       recursive_pattern                                   21           0.013817   44       6      0         0            0       14           (_,                     DayOfWeek.
../examples/PatternTest.on  422       recursive_positional_pattern                        12           0.028237   27       6      0         0            0       11           (_,                     DayOfWeek.
../examples/PatternTest.on  423       recursive_positional_pattern                        12           1.302662   28       8      2         0            0       10           Point2D                 =>                                p.ToString(
../examples/PatternTest.on  424       recursive_property_pattern                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  425       recursive_property_pattern                          9            1.392678   28       11     2         0            0       21           ICollection<char>       =>                                new                               string(
../examples/PatternTest.on  426       positional_pattern_clause                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  427       positional_pattern_clause                           12           0.008672   12       1      0         0            0       6            Sum
../examples/PatternTest.on  428       subpattern                                          36           0.043457   69       5      0         0            0       15           DayOfWeek.Saturday      or
../examples/PatternTest.on  429       base_expression_colon                               13           0.265394   52       2      13        0            0       28           LName:
../examples/PatternTest.on  430       property_pattern_clause                             11           0.007384   15       3      0         0            0       3            ,                       Month
../examples/PatternTest.on  431       property_pattern_clause                             0            0          0        0      0         0            0       0            
../examples/PatternTest.on  432       property_pattern_clause                             9            0.008595   9        1      0         0            0       1            LName
../examples/PatternTest.on  433       relational_pattern                                  25           0.259673   25       1      0         0            0       5            =>
../examples/PatternTest.on  434       const_expression                                    28           0.000549   28       1      0         0            0       3            -
../examples/PatternTest.on  435       const_expression                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  436       const_expression                                    28           0.591537   28       1      0         0            0       7            =>
../examples/PatternTest.on  437       slice_pattern                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  438       case_switch_label                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  439       throw_statement                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  440       throw_statement                                     1            2.22343    38       20     1         0            0       32           new                     ArgumentNullException(paramName:  nameof(car),\n                    message:                          'Car                                         should      not           be          null')\n\n   
../examples/PatternTest.on  441       try_statement                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  442       try_statement                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  443       try_statement                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  444       catch_clause                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  445       catch_clause                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  446       catch_declaration                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  447       unsafe_statement                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  448       using_statement                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  449       using_statement                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  450       using_statement                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  451       while_statement                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  452       while_statement                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  453       while_statement                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  454       yield_statement                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  455       yield_statement                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  456       expression                                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  457       expression                                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  458       expression                                          2            0.632738   5        2      1         0            0       5            ^3
../examples/PatternTest.on  459       expression                                          577          11.909681  2142     34     35        0            0       535          [[1,                    2,                                3],                               [4,                               5,                                           6],         [7,           8,          9]]\n
../examples/PatternTest.on  460       expression                                          13           0.871775   106      13     0         0            0       38           :\n                     array                             System.Array                      =>                                1,
../examples/PatternTest.on  461       expression                                          2            1.215998   5        2      1         0            0       5            ^3
../examples/PatternTest.on  462       expression                                          155          1.020367   221      16     3         0            0       46           is                      a                                 int                               &&                                yBoxed                                       is          b             int:
../examples/PatternTest.on  463       expression                                          732          26.140347  1908     32     155       0            0       498          (TakeFive(new[]         {                                 '1',                              '2',                              '3',                                         '4',        '5',          '6',        '7'          }))
../examples/PatternTest.on  464       anonymous_function_expression                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  465       anonymous_method_expression                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  466       anonymous_method_expression                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  467       lambda_expression                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  468       parenthesized_lambda_expression                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  469       parenthesized_lambda_expression                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  470       parenthesized_lambda_expression                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  471       parenthesized_lambda_expression                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  472       lambda_statement_block                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  473       simple_lambda_expression                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  474       simple_lambda_expression                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  475       simple_lambda_expression                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  476       anonymous_object_creation_expression                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  477       anonymous_object_creation_expression                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  478       anonymous_object_creation_expression                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  479       anonymous_object_member_declarator                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  480       array_creation_expression                           11           4.883024   177      36     3         0            0       81           {                       1,                                2,                                3,                                6                                            }\n\n       z             int[]       =            {                      1,          2,           3      }\n\n      Console
../examples/PatternTest.on  481       initializer_expression                              80           0.002057   185      3      0         0            0       9            ,                       20
../examples/PatternTest.on  482       initializer_expression                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  483       initializer_expression                              27           0.00199    27       1      0         0            0       6            10
../examples/PatternTest.on  484       base_object_creation_expression                     35           0.003322   106      4      0         0            0       5            new                     (\"John\"
../examples/PatternTest.on  485       implicit_object_creation_expression                 1            0.314668   1        1      0         0            0       1            
../examples/PatternTest.on  486       object_creation_expression                          34           8.872461   505      22     32        0            0       309          (new                    Point(0,                          5),                               new                               Point(1,                                     0))
../examples/PatternTest.on  487       object_creation_expression                          34           1.336232   91       17     2         0            0       35           {                       'a',                              'b',                              'c',                              'd'                                          }\n         Console.
../examples/PatternTest.on  488       checked_expression                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  489       collection_expression                               47           0.001596   119      3      0         0            0       8            ,                       2
../examples/PatternTest.on  490       collection_expression                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  491       collection_expression                               11           0.001718   11       1      0         0            0       5            1
../examples/PatternTest.on  492       collection_element                                  47           0.026227   65       4      3         0            0       16           ..                      row0,
../examples/PatternTest.on  493       declaration_expression                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  494       element_access_or_binding                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  495       implicit_array_creation_expression                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  496       instance_expression                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  497       raw_string_literal                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  498       interpolated_string_expression                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  499       interpolated_regular_string                         26           0.00174    26       1      0         0            0       4            Truck                   toll:                             
../examples/PatternTest.on  500       interpolated_regular_string_content                 18           0.001481   18       1      0         0            0       3            Truck                   toll:                             
../examples/PatternTest.on  501       interpolated_verbatim_string                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  502       interpolated_verbatim_string_content                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  503       interpolated_implicit_regular_string                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  504       interpolated_implicit_regular_string_content        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  505       interpolated_raw_string                             0            0          0        0      0         0            0       0            
../examples/PatternTest.on  506       interpolated_raw_string_content                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  507       interpolation                                       9            0.0093     9        1      0         0            0       2            \"
../examples/PatternTest.on  508       interpolation                                       9            0.018657   9        1      0         0            0       2            \"
../examples/PatternTest.on  509       interpolation_format_clause                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  510       literal_expression                                  311          0.001893   311      1      0         0            0       6            \"Hello,                World!\"
../examples/PatternTest.on  511       from_clause                                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  512       query_body                                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  513       query_body                                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  514       query_clause                                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  515       join_clause                                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  516       join_clause                                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  517       order_by_clause                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  518       ordering                                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  519       select_or_group_clause                              0            0          0        0      0         0            0       0            
../examples/PatternTest.on  520       stack_alloc_array_creation_expression               1            0.267955   1        1      0         0            0       1            
../examples/PatternTest.on  521       indented_switch_expression_block                    58           0.006307   58       1      0         0            0       1            
../examples/PatternTest.on  522       indented_switch_expression_block                    58           0.012802   58       1      0         0            0       10           collection
../examples/PatternTest.on  523       switch_expression_arm                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  524       switch_expression_arm                               58           0.006417   58       1      0         0            0       2            ,
../examples/PatternTest.on  525       one_switch_argument                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  526       one_switch_argument                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  527       indented_one_switch_expression_block                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  528       indented_one_switch_expression_block                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  529       one_switch_expression_arm                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  530       condition_types                                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  531       condition_type                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  532       range                                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  533       closed_or_one_sided_range                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  534       closed_or_one_sided_range                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  535       half_open_or_one_sided_range                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  536       tuple_expression                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  537       xml_node                                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  538       xml_c_data_section                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  539       xml_comment                                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  540       xml_element                                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  541       xml_element_start_tag                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  542       xml_name                                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  543       xml_attribute                                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  544       cref                                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  545       member_cref                                         0            0          0        0      0         0            0       0            
../examples/PatternTest.on  546       conversion_operator_member_cref                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  547       conversion_operator_member_cref                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  548       conversion_operator_member_cref                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  549       conversion_operator_member_cref                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  550       conversion_operator_member_cref                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  551       cref_parameter_list                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  552       cref_parameter_list                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  553       cref_parameter                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  554       cref_parameter                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  555       cref_parameter                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  556       cref_parameter                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  557       cref_parameter                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  558       cref_parameter                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  559       cref_parameter                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  560       indexer_member_cref                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  561       cref_bracketed_parameter_list                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  562       name_member_cref                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  563       operator_member_cref                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  564       operator_member_cref                                0            0          0        0      0         0            0       0            
../examples/PatternTest.on  565       xml_text_attribute                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  566       xml_empty_element                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  567       xml_processing_instruction                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  568       xml_text                                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  569       structured_trivia                                   0            0          0        0      0         0            0       0            
../examples/PatternTest.on  570       directive_trivia                                    0            0          0        0      0         0            0       0            
../examples/PatternTest.on  571       branching_directive_trivia                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  572       conditional_directive_trivia                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  573       line_or_span_directive_trivia                       0            0          0        0      0         0            0       0            
../examples/PatternTest.on  574       line_directive_trivia                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  575       line_directive_trivia                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  576       line_span_directive_trivia                          0            0          0        0      0         0            0       0            
../examples/PatternTest.on  577       nullable_directive_trivia                           0            0          0        0      0         0            0       0            
../examples/PatternTest.on  578       pragma_warning_directive_trivia                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  579       pragma_warning_directive_trivia                     0            0          0        0      0         0            0       0            
../examples/PatternTest.on  580       documentation_comment_trivia                        0            0          0        0      0         0            0       0            
../examples/PatternTest.on  581       skipped_tokens_trivia                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  582       base_argument_list                                  0            0          0        0      0         0            0       0            
../examples/PatternTest.on  583       base_cref_parameter_list                            0            0          0        0      0         0            0       0            
../examples/PatternTest.on  584       base_parameter_list                                 0            0          0        0      0         0            0       0            
../examples/PatternTest.on  585       base_parameter                                      0            0          0        0      0         0            0       0            
../examples/PatternTest.on  586       expression_or_pattern                               0            0          0        0      0         0            0       0            
../examples/PatternTest.on  587       string_literal_token                                0            0          0        0      0         0            0       0            

I am still trying to find out how to "unshare" certain rules, but it would be best if implemented using Trash to make copies and rename rules.

kaby76 commented 1 week ago

No question. The grammar has poor performance because of fallbacks. This script transforms the grammar into a significantly faster one.

trparse -t ANTLRv4 ONEParser.g4 \
    | trquery -c /c/Users/Kenne/Documents/GitHub/g4-scripts/strip-labels.xq \
    | trsponge -o xxxdir -c
trparse -t ANTLRv4 xxxdir/ONEParser.g4 \
    | trunfold ' //parserRuleSpec[RULE_REF/text() = "identifier_name"]//labeledAlt//RULE_REF[text() = "identifier_token"]' \
    | trsponge -o xxxdir -c
trparse -t ANTLRv4 xxxdir/ONEParser.g4 \
    | trunfold ' //ruleBlock//labeledAlt//RULE_REF[text() = "identifier_name"]' \
    | trsponge -o xxxdir -c

The script removes all labels, which interferes in rule unfolding (you cannot say foobar=( a b c ...)), then unfolds identifier_token in rule identifier_name, then unfolds identifier_name throughout the grammar. (Personally, I do not like labeling because it "muddies up" a grammar up with needless syntax.)

ONEParser.g4.txt

Here's the comparison (N = 36).

untitled

This is only one such fallback, there are many, many more. It's caused by very deep parse trees using rules that reference shared non-terminals.

kaby76 commented 1 week ago

@XzuluX

There are a large number of fallbacks to LL() from SLL(). This is one example, but I think it also happens because there are a large number of unused parser rules in the grammar, which likely affects SLL(*) computations. https://github.com/kaby76/one-parser/issues/6. I think the combo of the change here, and the delete unused parser rules cuts ~1/4 of the time. But, there is more to do..

XzuluX commented 1 week ago

@kaby76 Great work on what you have found so far, thank you for that! That sounds promising. I will try to perform an unfolding for each candidate who has a large value in the fallback column. That should hopefully significantly improve the performance.

I used labels because they make accessing tokens in the Visitor easier. I think that labels do not generally affect performance negatively, right? Is there a way to keep the labels that are not directly involved in rule unfolding?

kaby76 commented 1 week ago

Yes, there is a way to keep most of the labeling, but it requires a change to the script to do the deletions of selected labels in the right order. Otherwise, if I do the unfolding first, the resulting file is not valid Antlr, so cannot be parsed. (Antlr should allow a label for any sub-expression on the RHS of a rule. I'll make a note somewhere.)

Here are the rules/labels with the problems.

rule label
counter_member_declaration id
counter_declaration id
state id
statemachine_statement id
send_trigger_statement id
send_trigger_statement to
on_trigger_statement id
trigger_member_declaration id
action_method id
action_expression_row id
decision_element id
condition_row id
conditions group
XzuluX commented 1 week ago

@kaby76 I played around with your trparse commands. Strangely the modified ONEParser.g4 in outDir is exactly the same as the original. The file is apparantly generated but there is no modification. I'm using powershell on Win10.

This is my command:

 trparse -t ANTLRv4  .\ONEParser.g4  -p .\Generated-CSharp\ | trunfold ' //parserRuleSpec[RULE_REF/text() = "identifier_name"]//labeledAlt//RULE_REF[text() = "identifier_token"]' | trsponge -o .\outDir\ -c

Output:

Using built-in parser.
CSharp 0 .\ONEParser.g4 success 0,1232364
Writing to .\outDir\ONEParser.g4

It seems built-in parser is used but -p is set to CSharp parser.

XzuluX commented 1 week ago

Could you please also provide your script strip-labels.xq. Could not found it at https://github.com/kaby76/g4-scripts/tree/main

kaby76 commented 1 week ago

Strangely the modified ONEParser.g4 in outDir is exactly the same as the original.

That can happen if the XPath expression doesn't match anything. That can happen if the spellings are incorrect. Or, it can happen if the structure of the parse tree has changed from a previous edit, and then the next pattern can't match. In that case, the file needs to be written out, then reparsed with trparse.

I haven't added an option to fail if a pattern doesn't match. It could be global, such as on the command line, or per pattern. I'll try to add something in the next release this week.

Could you please also provide your script strip-labels.xq.

I checked in the scripts. It's here: https://github.com/kaby76/g4-scripts/blob/main/strip-labels.xq. Note, the script moves around some of the white spacing that's attached to the parse tree to another location so deleting nodes preserves some kind of white spacing with text in the nodes following the deleted tree.

kaby76 commented 1 week ago

The script to do the selective delabeling and unfolding is this:


# set -e
# set -x

# table of { parser rule name, label name } that requires deletion.
table=(
    counter_member_declaration id
    counter_declaration id
    state id
    statemachine_statement id
    send_trigger_statement id
    send_trigger_statement to
    on_trigger_statement id
    trigger_member_declaration id
    action_method id
    action_expression_row id
    decision_element id
    condition_row id
    conditions group
)

cols=2
rows="$(( ${#table[@]} / $cols))"

for ((r=0; r<$rows; r++))
do
    cp ONEParser.g4 before.g4
    rule=${table[$r*$cols]}
    label=${table[$r*$cols + 1]}
    echo "$r $rule $label"
    cp ONEParser.g4 before.g4
    trparse -t ANTLRv4 ONEParser.g4 | \
    trquery move ' //parserRuleSpec[RULE_REF/text() = "'$rule'"]//labeledElement/identifier[RULE_REF/text() = "'$label'"]/@WS ./ancestor::labeledElement;
         delete //parserRuleSpec[RULE_REF/text() = "'$rule'"]//labeledElement[identifier/RULE_REF/text() = "'$label'"]/(identifier | ASSIGN | PLUS_ASSIGN);' | \
    trsponge -c
    diff before.g4 ONEParser.g4
    if [ $? -eq 0 ]
    then
    echo problem
    break
    fi
done
trparse -t ANTLRv4 ONEParser.g4 \
    | trunfold ' //parserRuleSpec[RULE_REF/text() = "identifier_name"]//labeledAlt//RULE_REF[text() = "identifier_token"]' \
    | trsponge -c
trparse -t ANTLRv4 ONEParser.g4 \
    | trunfold ' //ruleBlock//labeledAlt//RULE_REF[text() = "identifier_name"]' \
    | trsponge -c
trparse -t ANTLRv4 ONEParser.g4 | trquery delete ' //parserRuleSpec
    [not(doc("*")//ruleBlock//RULE_REF/text() = ./RULE_REF/text())
     and not(./ruleBlock//TOKEN_REF/text() = "EOF")]' | trsponge -c

Basically, first remove the label (e.g., id=) for the list of occurrences in a table. Then, unfold identifier_token, then identifier_name. Afterwards, delete unused parser rules.

ONEParser.g4.txt

The improvement in performance is only slightly greater than 9%, though, less than I thought.

XzuluX commented 1 week ago

@kaby76 Thanks for the script. To achieve a significant performance gain, it would likely be necessary to unfold multiple rules. Unfortunately, this complicates the visitor code unnecessarily. When a rule is removed, you can't simply call the visitor on that rule anymore. Do you think there might be another way to improve performance while still retaining the individual rules?

kaby76 commented 1 week ago

I am looking at disambiguating the conflict using semantic predicates. I can eliminate the fallback to full context parses, but I'm not sure yet if that will improve the performance.