Add support Start-Symbol: `%start`
Fixes: https://github.com/ruby/lrama/issues/568
I tried the grammar file below with Bison 3.8.2.
%{
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
%}
%code provides {
static int yylex(YYSTYPE *val, YYLTYPE *loc);
static int yyerror(YYLTYPE *loc, const char *str);
}
%union {
int val;
}
%token LF
%token <val> NUM
%type <val> expr
%left '+' '-'
%left '*' '/'
%locations
%start program_1 program_2 program_3 '/'
%%
program_1 : expr '+' expr;
program_2 : expr '-' expr;
program_3 : expr '*' expr;
expr : NUM
| '(' expr ')' { $$ = $2; }
;
%%
Output file says YY_PARSE_ terminals are required on state 0. Could you check how multiple start symbols are used?
State 0
0 $accept: • YY_PARSE_program_1 program_1 $end
1 | • YY_PARSE_program_2 program_2 $end
2 | • YY_PARSE_program_3 program_3 $end
3 | • YY_PARSE_(NULL) '/' $end
YY_PARSE_(NULL) shift, and go to state 1
YY_PARSE_program_1 shift, and go to state 2
YY_PARSE_program_2 shift, and go to state 3
YY_PARSE_program_3 shift, and go to state 4
JFYI: https://www.gnu.org/software/bison/manual/html_node/Multiple-start_002dsymbols.html
Output file says YY_PARSE_ terminals are required on state 0. Could you check how multiple start symbols are used?
This is because Bison did not generate an error, so I made the same behavior. I don't know any particular use cases.
@yui-knk An error is now raised if more than one %start is defined. Please point out if there is something wrong with your understanding of the sentence.