in reply to Re: First steps with Marpa::R2 and BNF
in thread First steps with Marpa::R2 and BNF
I really appreciate your code example as it seems to me a good starting point. I really like the use of $self you exploit to add optional terms to the expression. Now prehaps I understand it better.
I still do not fully understand your:
> which makes the convenient default ::= action => ::first work for the Dice_Expression rule
If you have the patience to expand this further it will help me in the understanding the ::first (see also below my answer to GrandFather).
So the only way to specify somenthing optional is:
Dice_with_modifier_r ::= Simple_Dice 'r' Die_Modifier_Val action => mo +difier_r |Simple_Dice 'r' Die_Modifier_Comp Die_Modifie +r_Val action => modifier_r
Right? there is no <Optional> syntax to play with?
I tried a single rule like:
Dice_with_modifier_r ::= Simple_Dice 'r' <Die_Modifier_Comp>* Die_Modifier_Val action => modifier_r
as found at the end of this post but it throws the error:
Parse of BNF/Scanless source failed Error in SLIF parse: No lexeme found at line 11, column 61 * String before error: modifier_r ::= Simple_Dice 'r' <Die_Modifier_Co +mp> * The error was at line 11, column 61, and at character 0x002a '*', .. +. * here: * Die_Modifier_Val action => modifier_r\n\n\nSimpl Marpa::R2 exception at marpa07.pl line 41. Marpa::R2 exception at marpa07.pl line 41.
Why on marpa-for-building-parsers there is: declaration ::= assignment* action => doResult
and I cannot do
Dice_with_modifier_r ::= Simple_Dice 'r' Die_Modifier_Comp* Die_Modifi +er_Val action => modifier_r Die_Modifier_Comp ~ 'gt' | 'lt'
L*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: First steps with Marpa::R2 and BNF
by duelafn (Parson) on Jan 17, 2021 at 19:04 UTC |