This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Define the grammar | |
| const grammar = { | |
| nonTerminals: ['S', 'A'], | |
| terminals: ['a', 'b'], | |
| productions: [ | |
| { left: 'S', right: ['A', 'a'] }, | |
| { left: 'S', right: ['b'] }, | |
| { left: 'A', right: ['a', 'A'] }, | |
| { left: 'A', right: [] } | |
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class LL1Parser { | |
| constructor() { | |
| this.index = 0; | |
| } | |
| parse(input) { | |
| this.tokens = input.split(' '); | |
| this.index = 0; | |
| try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class State { | |
| constructor(name) { | |
| this.name = name; | |
| this.transitions = {}; // Holds the transitions from this state | |
| this.isFinal = false; // Indicates whether this state is a final state | |
| } | |
| } | |
| class DFA { | |
| constructor() { |