Compiler Answer
Compiler Answer
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <string>
if (firstSet.find(nonTerminal) != firstSet.end()) {
unordered_set<char> first;
if (isupper(production[0])) {
computeFirst(production); // Recursively compute First for non-
terminals
first.insert(firstSet[production].begin(), firstSet[production].end());
} else {
firstSet[nonTerminal] = first;
if (followSet.find(nonTerminal) != followSet.end()) {
unordered_set<char> follow;
if (nonTerminal == "S") {
follow.insert('$');
if (isupper(nextSymbol)) {
follow.insert(firstSet[string(1, nextSymbol)].begin(),
firstSet[string(1, nextSymbol)].end());
} else {
} else {
if (left != nonTerminal) {
follow.insert(followSet[left].begin(), followSet[left].end());
followSet[nonTerminal] = follow;
if (production == "ε") {
} else {
if (isupper(firstSymbol)) {
} else {
return parseTable;
int main() {
computeFirst("S");
computeFollow("S");
displayParseTable(parseTable);
return 0;
}
Bash
./parse_table
#include <iostream>
#include <unordered_map>
#include <string>
void displayParseTable() {
int main() {
return 0;
Step-by-Step Guide:
bash
Copy
cd path/to/your/file
bash
Copy
On Linux/macOS:
bash
Copy
./parse_table
On Windows:
bash
Copy
parse_table.exe
Expected Output:
If everything is set up correctly, after running the program, you should see
the following output in the terminal:
markdown
Copy
Non-terminal a b $
----------------------------------------
S S → aSb S → ε S → ε
This indicates that the LL(1) parse table has been generated correctly,
showing the production rules for the S non-terminal based on the input
symbols.
Troubleshooting:
If you see errors during compilation, check that you have g++
installed and properly configured.
Attach
Search
Reason