lrama icon indicating copy to clipboard operation
lrama copied to clipboard

Add support Start-Symbol: `%start`

Open ydah opened this issue 9 months ago • 2 comments

Fixes: https://github.com/ruby/lrama/issues/568

ydah avatar Mar 01 '25 09:03 ydah

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

yui-knk avatar Apr 29 '25 03:04 yui-knk

JFYI: https://www.gnu.org/software/bison/manual/html_node/Multiple-start_002dsymbols.html

yui-knk avatar Apr 29 '25 04:04 yui-knk

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.

ydah avatar Aug 01 '25 15:08 ydah

@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.

ydah avatar Aug 04 '25 02:08 ydah