sum ::= term (op_add) term action => do_additiondo_addition {
my (undef, $a, $b) = @_;
return $a + $b;
}sum ::= term op_add term action => do_additiondo_addition {
my (undef, $a, undef, $b) = @_;
return $a + $b;
}x ::= {a b c} d {e}<[
... ]>. That seems to me a bit heavy weight, since I expect
in future versions of Marpa users will use character classes a lot.@rns: The notation you cite is an example of why I characterized Perl 5 regex parens as ugly, overloaded and confusing. Perl 5 was a victim of its own success and the need for compatibility, and had very little choice except to extend its syntax via its paren operators. Hopefully, we'll avoid that here.
Yes, eventually I expect to add quantifiers like '?', '*' and '+' for parens.
You can use quoting with -,_,`,',", for example -xxx-
x ::= a (b|c|(d e)*) f(b|c|(d e)*) ?
Best for it to have no value by default, so that in something like.x ::= a -(b|c|(d e)*) f
the minus sign is really redundant.Re usefulness: I'm going somewhere I think is worthwhile, and it is a necessary step on the way. For now, you'll have to trust me._,'," are needed for other purposes. minus signs and back ticks would be unreadable for bracketing, but minus signs might work as prefixes, as in -(x).
You can use quoting with -,_,`,',", for example -xxx-
The reason I connect grouping and semantic visibility is that, once I have complex grouping, its semantics become hard to define. Consider
x ::= a (b|c|(d e)*) f
What value is passed to the semantics for(b|c|(d e)*)?
x ::= a (b|c|(d e)*) f
x ::= a SR1 fSR1 ::= b|c|(d e)*
x ::= a (b|c|(d e)*) f
will probably be rewritten as
x ::= a SR1 fSR1 ::= b|c|(d e)*
@Ruslan: Yes. I just sent one thought.
Of the choices for prefix,
# is taken, for comments.
! and ~ are traditionally toggles, and I'd like direct indicators, for those who've forgotten the default hidden/visible category. That way if you can't remember what I decided about parentheses, hidden or visible, you just do -(x) and you know x is hidden. Or +(x) and you know x is visible.
^ -- caret is nice, but there is no opposite, as in the case with + and -.
Prefix + and - also have the advantage that, in this context, they aren't overloaded -- none of the other traditional meanings really conflict.
[1] A - BA but does not match B.Yes, exactly. If your parenthesized expression has semantics, you'd really be pretty much forced to break it out into a separate rule in order to write those semantics reasonably. So, therefore, I want parentheses to mean "hidden from the semantics", and rule-broken-out-separately to mean "visible to the semantics". When used for grouping, parentheses pretty much have to imply "hidden" anyway, so they might as well actually indicate "hidden".x ::= a (b|c|(d e)*) f
will probably be rewritten as
x ::= a SR1 fSR1 ::= b|c|(d e)*
On Tue, Nov 6, 2012 at 12:47 PM, Jeffrey Kegler <jeffre...@jeffreykegler.com> wrote:
Right. I really like the idea of named arguments, but I can't figure out how to implement them efficiently in the Perl context. I'd practically have to call one method in order to unpack the arguments of another, which is kind of ridiculous. And this is one place where efficiency becomes quite visible -- most of the time in Marpa::R2 applications is typically *not* spent parsing, which is done in highly efficient Perl. Most of the time, in some cases almost all, is spent in the semantics.
$rules => q{
S ::= s1 s2 | s3 s4
%{ action(S) %}
s1 ::=
s2
%{
# action(s1 -> s2)... application code here ...
%}
|(s3 s5)+
%{
# action(s1 -> s3 s5)... application code here ...
%}
},
$input
If you're tackling issues like interfacing with a semantics, you might consider writing a BNF-to-C Marpa compiler. That is, take the BNF and, instead of running it in Perl, compile it into C that uses the libmarpa library directly. It'd run several times as fast as the Perl. Here is what a pure C/libmarpa program looks like -- it's something I created for memory leak checking, and has only stub semantics.
Another possibility, as a first step, is a BNF to Marpa::R2::Thin interface compiler. Much of the benefit of the BNF-to-C, but easier to do. I use a very simple prototype of one to create the code that compiles the Stuifzand interface -- the code is in Marpa::R2's lib/Marpa/R2/meta directory.
Of course, the easiest way to approach may be to get it working in the main Marpa::R2 interface first. That's the way I did it.