Marpa::R2::BNF(3pm)
β¨ NAME β¨
Marpa::R2::BNF β the BNF Interface, aka the obsoleted one π
So real talk, bestie: this page is Marpa::R2::BNF(3pm) from the User Contributed Perl Documentation, and it's a whole mood β but a retired one. Let's get into it π«Ά
πΈ SYNOPSIS πΈ
use Marpa::R2;
my $grammar = Marpa::R2::Grammar->new(
{
actions => 'My_Actions',
default_action => 'do_first_arg',
source => \(<<'END_OF_SOURCE'),
:start ::= Script
Script ::= Expression+ separator => <op comma> action => do_script
Expression ::=
Number
| (<op lparen>) Expression (<op rparen>) action => do_parens assoc => group
|| Expression (<op pow>) Expression action => do_pow assoc => right
|| Expression (<op times>) Expression action => do_multiply
| Expression (<op divide>) Expression action => do_divide
|| Expression (<op add>) Expression action => do_add
| Expression (<op subtract>) Expression action => do_subtract
END_OF_SOURCE
}
);
iconic snippet honestly β¨
π¦ OVERVIEW π¦
Okay so this page is the reference for Marpa's "BNF interface", which also goes by its other name, the "Stuifzand interface". Two names, one interface, very main character energy π
Now the tea: using the Stuifzand interface is discouraged these days, in favor of the SLIF interface. Basically almost everything the Stuifzand interface can do, the SLIF interface can also do β the trick is to switch immediately to external scanning, and never switch back to internal scanning. To switch immediately to external scanning in the SLIF, you specify a length of zero for its initial read(). Want the full deets? Go read the document for the SLIF itself, bestie π
π THE SOURCE STRING π
Stuifzand interface source strings get specified using the source named argument of Marpa::R2's grammars. And here's the vibe: BNF source strings do the jobs that the rules and the start named arguments of Marpa grammars do. So when you use the source named argument to specify a grammar, the rules and start named arguments should not be used, and vice versa. Pick a lane, babe π«
The syntax for the Stuifzand interface's source string is the same as the syntax for the SLIF DSL β except that features and syntax that aren't relevant to the Stuifzand interface are not supported. Periodt.
Everything related to L0 grammars is unsupported. L0 grammars literally do not exist in the Stuifzand interface. Lexemes, character classes and quoted strings all implicitly require a L0 grammar to exist, and therefore, they're also not supported. No L0, no problem (jk it's kind of a problem) π
Since the Stuifzand interface does not implement internal scanning, everything to do with internal scanning is unsupported. Events and pauses are the most visible of these features π
In most cases, when features were introduced after the SLIF replaced the Stuifzand interface as Marpa's primary interface, those features have been retro-ported if they make sense in the Stuifzand context. However, this will necessarily always be the case in the future. (yes, that's the sentence, don't @ me) π
Here's a list of some of the unsupported SLIF DSL features, bestie β read it and weep π
- Character classes β these implicitly use the L0 grammar.
- Quoted strings β these implicitly use the L0 grammar.
- Discard rules β
:discardrules control the behavior of the L0 grammar. - The lexeme and lexeme default statements β the
:lexemepseudo-rule and the lexeme default statement define the behavior of lexemes. Lexemes in the SLIF sense do not exist in the Stuifzand interface. - L0 rules β rules with the tilde declarator (
"~") defined L0 rules. - Event declarations β events exist to pause the SLIF internal scanning.
- The pause adverb β the pause adverb exists to pause the SLIF internal scanning.
- The priority adverb β the priority adverb defines lexeme priorities. Lexemes in the SLIF sense do not exist in the Stuifzand interface.
- Actions specified as array descriptors β actions specified as array descriptors, for example,
action => [start,length,value]
exist primarily to support lexeme semantics. They can also specify rule semantics, but their functionality has not been retro-ported to the Stuifzand interface, and probably never will be. rip π
Heads up: those "not supported" bits aren't vibe-killers, they're just facts. Don't try to sneak L0 grammar stuff into a Stuifzand source string, because it is genuinely not gonna work π ββοΈ
π COPYRIGHT AND LICENSE π
Copyright 2014 Jeffrey Kegler
This file is part of Marpa::R2. Marpa::R2 is free software: you can
redistribute it and/or modify it under the terms of the GNU Lesser
General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.
Marpa::R2 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser
General Public License along with Marpa::R2. If not, see
http://www.gnu.org/licenses/.
And that's the whole page, bestie! π This one came to you as part of perl v5.34.0, dated 2022-02-06 β so yeah, a lil vintage, but the lore still slaps. Go forth and use the SLIF instead, ily ππ§ββοΈ
π¦ where this page comes from
- ubuntu jammy: libmarpa-r2-perl 2.086000~dfsg-7build1 Β· LGPL-3+~Marpa
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms