Add support Start-Symbol: %start - #576
Conversation
|
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 |
e42b5b7 to
2133a0f
Compare
This is because Bison did not generate an error, so I made the same behavior. I don't know any particular use cases. |
d15c656 to
8c43e68
Compare
|
@yui-knk An error is now raised if more than one |
| end | ||
|
|
||
| # Add $accept rule to the top of rules | ||
| def add_accept_rules |
There was a problem hiding this comment.
This method adds single accept rule then it's better to use add_accept_rule (without "s") or something like that.
| def set_start_nterm(id) | ||
| if @start_nterm.nil? | ||
| @start_nterm = id | ||
| else |
There was a problem hiding this comment.
I agree to the idea to not support multiple start symbols until we think it's use case is reasonable for us.
By the way, could you comment the fact that Lrama's %start behaves differently when multiple symbols are passed to %start?
There was a problem hiding this comment.
I added the following comments. What do you think?
yui-knk
left a comment
There was a problem hiding this comment.
Left comments. The direction looks good to me.
…n `set_start_nterm`
Fixes: #568