Allow to define parameterizing rule by %rule
directive.
%rule pair(X, Y): X Y { $$ = $1 + $2; }
;
%%
program: stmt
;
stmt: pair(ODD, EVEN) <num>
| pair(EVEN, ODD) <num>
;
Allow to specify type of rules by specifying tag, <i>
in below example.
Tag is post-modification style.
%union {
int i;
}
%%
program : option(number) <i>
| number_alias? <i>
;
Support function call style parameterizing rules for option
, nonempty_list
and list
.
Support separated_list
and separated_nonempty_list
parameterizing rules.
program: separated_list(',', number)
// Expanded to
program: separated_list_number
separated_list_number: ε
separated_list_number: separated_nonempty_list_number
separated_nonempty_list_number: number
separated_nonempty_list_number: separated_nonempty_list_number ',' number
program: separated_nonempty_list(',', number)
// Expanded to
program: separated_nonempty_list_number
separated_nonempty_list_number: number
separated_nonempty_list_number: separated_nonempty_list_number ',' number
Parameterizing rules are template of rules. It's very common pattern to write "list" grammar rule like:
opt_args: /* none */
| args
;
args: arg
| args arg
Lrama supports these suffixes:
?
: option+
: nonempty list*
: list
Idea of Parameterizing rules comes from Menhir LR(1) parser generator (https://gallium.inria.fr/~fpottier/menhir/manual.html#sec32).
Replace Lrama's parser from hand written parser to LR parser generated by Racc.
Lrama uses --embedded
option to generate LR parser because Racc is changed from default gem to bundled gem by Ruby 3.3 (#132).
Meke error recovery function configurable on runtime by two new macros.
YYMAXREPAIR
: Expected to return max length of repair operations.%parse-param
is passed to this function.YYERROR_RECOVERY_ENABLED
: Expected to return bool value to determine error recovery is enabled or not.%parse-param
is passed to this function.
Support token insert base Error Recovery.
-e
option is needed to generate parser with error recovery functions.
Instead of positional references like $1
or $$
,
named references allow to access to symbol by name.
primary: k_class cpath superclass bodystmt k_end
{
$primary = new_class($cpath, $bodystmt, $superclass);
}
Alias name can be declared.
expr[result]: expr[ex-left] '+' expr[ex.right]
{
$result = $[ex-left] + $[ex.right];
}
Bison supports this feature from 2.5.
%parse-param
are added to these macros and functions to remove ytab.sed hack from Ruby.
YY_LOCATION_PRINT
YY_SYMBOL_PRINT
yy_stack_print
YY_STACK_PRINT
YY_REDUCE_PRINT
yysyntax_error
See also: ruby/ruby#7807
When -
is given as grammar file name, reads the grammar source from STDIN, and takes the next argument as the input file name. This mode helps pre-process a grammar source.
This is the first version migrated to Ruby. This version generates "parse.c" compatible with Bison 3.8.2.