Skip to content

Conversation

@MammarDr
Copy link

@MammarDr MammarDr commented Dec 20, 2025

Issue #138
Hi this is my first github contribution and i feel honored to be help to you as you were to me in your amazing courses.

1-
I fixed the wrong generated first sets from productions that have the nullable LHS(derive ε) appear in firstOf(rhs).

Grammar:
B -> B "a" | ε

Without fix:
First(B) = { ε }

With fix:
First(B) = { "a", ε }

the solution is to register the Non-Terminals that derive epsilon directly (A->ε) before calculating the first sets.

added test case for this issue.

2-
i also spotted a function typo 'getOrignialSymbol' -> 'getOriginalSymbol'

@MammarDr MammarDr changed the title Fix Issue #138 Fixing First Set Generator Dec 22, 2025
@MammarDr MammarDr changed the title Fixing First Set Generator Fixing Wrong Generated First Set Dec 22, 2025
Copy link
Owner

@DmitrySoshnikov DmitrySoshnikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MammarDr, thanks for the contribution - glad we have this bug finally caught! Please see comments on the formatting (use tools which should be in this repo for auto-format the code to single style).

@MammarDr
Copy link
Author

MammarDr commented Jan 2, 2026

@DmitrySoshnikov
Hi demitry, if you don't like this approach i can look for another solution.

Copy link
Owner

@DmitrySoshnikov DmitrySoshnikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @MammarDr - let's stick commit only to logical change and keep formatting for cobase refactorings.

getTerminalSymbols() {
if (!this._terminalSymbols) {
this._terminalSymbols = this.getTerminals().map(symbol =>
this._terminalSymbols = this.getTerminals().map((symbol) =>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not against of any formatting styles (and we can reformat this whole codebase to the latest standard or AI-generated coding), but let's make a separate commit for formatting, and keep this change to its semantics.

@MammarDr
Copy link
Author

MammarDr commented Jan 23, 2026

@DmitrySoshnikov
I have implemented a new way to calculate first and follow sets -- it solves all the opened issues :)
In my approach, I call a single function that computes all the sets at once (build first -> build follow) then when you demand a set of a symbol it will be ready.
In your method, the sets are calculated on demand one by one
Should I follow your pattern or is it acceptable to compute everything in one go?

(not doing it all in one go will complicate the code and maybe become less efficient)

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