AT cpanMarpa :: R2 page , I understand BNF (Backus-Naur form), but I completely lost the effect of callbacks.
In this example below, I understand that the two, left and right members are passed on do_multiply. I have no problem with this. The problem is that I can’t find the documentation about what these arguments are?
my $dsl = <<'END_OF_DSL';
:default ::= action => [name,values]
lexeme default = latm => 1
Calculator ::= Expression action => ::first
...
Term '*' Factor action => do_multiply
...
END_OF_DSL
my $grammar = Marpa::R2::Scanless::G->new( { source => \$dsl } );
sub do_multiply { $_[1] * $_[2] }
What is $_[0]or even $_[3]? Where is this documented? Even on the official marpa website I do not see any documentation.
In another example, here is the answer of chobora , we see what pairapplies to $_[2]and $_[3]:
Fragment of BNF:
Hash ::= '(' Pairs ')' action => hash
Pairs ::= Pair+ action => pairs
Pair ::= '(' Key Value ')' action => pair
Key ::= String
Kernel Code:
$recce->read(\$input);
print Dumper $recce->value;
sub hash { $_[2] }
sub pairs { shift; +{ map @$_, @_ } }
sub pair { [ @_[2, 3] ] }
sub itself { $_[1] }
source
share