Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ydah
Copy link
Member

@ydah ydah commented Dec 18, 2024

This PR add support for %type declarations using %nterm in Nonterminal Symbols. https://www.gnu.org/software/bison/manual/html_node/Type-Decl.html

@yui-knk
Copy link
Collaborator

yui-knk commented Dec 21, 2024

What should happen if terminal like tSTRING is passed to %nterm ?

In bison when a terminal symbol is passed to `%nterm` it should give an error. But it doesn't yet.
It just ignores the terminal symbol and uses the nonterminal symbol.

For example in the following code, `EOI` is a terminal symbol and `EOI` is a nonterminal symbol. When `EOI` is passed to `%nterm` it should give an error but it doesn't.

```yacc
%{
// Prologue
%}

%token EOI 0 "EOI"
%nterm EOI

%%

program: /* empty */
        ;
```

In bison, it gives the following error

```
❯ bison test.y
test.y:6.8-10: error: symbol EOI redeclared as a nonterminal
    6 | %nterm EOI
      |        ^~~
test.y:5.8-10: note: previous definition
    5 | %token EOI 0 "EOI"
      |        ^~~
```

So this PR adds an error when a terminal symbol is passed to `%nterm`.
@ydah
Copy link
Member Author

ydah commented Dec 21, 2024

Thanks for catching that. Currently, no error occurred, but when I looked at the bison behavior, the following error occurred. So, I made lrama output error messages as bison works.

Reproduce code:

%{
// Prologue
%}

%token EOI 0 "EOI"
%nterm EOI

%%

program: /* empty */
        ;

Error message:

❯ bison test.y
test.y:6.8-10: error: symbol EOI redeclared as a nonterminal
    6 | %nterm EOI
      |        ^~~
test.y:5.8-10: note: previous definition
    5 | %token EOI 0 "EOI"
      |        ^~~

@ydah ydah requested a review from yui-knk December 21, 2024 09:30
@ydah ydah merged commit e606e44 into ruby:master Dec 22, 2024
18 checks passed
@ydah ydah deleted the nterm-support branch December 22, 2024 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants