Skip to content

Changing first set generator break grammar parser #159

@MammarDr

Description

@MammarDr

The current first set generator has too many flaws and can't handle to many edge cases (changing start symbol, multiple non-terminals inherit from each other, etc...)

I decided to implement a new approach and i believe it handle all possible cases, i was going to commit it yesterday until i met with hell of an exception. making changes in first set generator somehow break the functionality of the grammar parsing the string inside the unit tests.

you recreate this problem by going to 'sets-generator.js' and edit 'firstSet[symbol] = true;' into 'firstSet[symbol + "x"] = true;'

suddenly you get errors like :
Unexpected token: "%%" at 2:8.
throw new SyntaxError()

mind you that the code never reaches the code that you changed(throw in parsing phase) so this behavior has no logical sense (in my point of view)

i had to use copilot and found this change solve the issue for my version of code

in build.js change the mode from lalr1 to slr1

exec(
  `node "./bin/syntax" -g src/generated/bnf.g -m slr1 -o src/generated/bnf-parser.gen.js`
);

after this my code run smoothly and succeed in all unit tests i gathered. i fought with this error for 4 hours and couldn't find an answer why is this happening, so i hope you have an answer for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions