-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing end of input while parsing stack not empty (#39)
* ANYCC 29 - Fix 'dash' print. * handle end of input while stack not empty * ANYCC 29 - Generate First & Follow Markdown files * ANYCC 29 - Printing Grammar * handle end of input and adjust readme output * ANYCC 47 - Fix prioritize direct production for each first in first set * ANYCC 47 - Fix Predictive Table MD * ANYCC 47 - Put project program * ANYCC 47 - Put test program * fix end of input or end of stack * ANYCC 47 - Modify print * ANYCC 47 - Add Default test --------- Co-authored-by: bazina <youssefbazina7@gmail.com>
- Loading branch information
1 parent
6a424aa
commit 14ce0f4
Showing
9 changed files
with
182 additions
and
103 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
int x; | ||
x = 5; | ||
if (x > 2) | ||
{ | ||
x = 0; | ||
int x; | ||
x = 5; | ||
if (x > 2) | ||
{ | ||
x = 0; | ||
} | ||
else | ||
{ | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,71 @@ | ||
|
||
#include "Parser/FirstAndFollowGeneratorUtility.h" | ||
#include <algorithm> | ||
#include <fstream> | ||
|
||
std::vector<SubstringInfo> findAllLongestSubstringIndices(const std::string& input, const std::set<std::string>& substrings) { | ||
std::vector<SubstringInfo> substringInfoVec; | ||
std::vector<SubstringInfo> | ||
findAllLongestSubstringIndices(const std::string &input, const std::set<std::string> &substrings) { | ||
std::vector<SubstringInfo> substringInfoVec; | ||
|
||
for (const std::string& substring : substrings) { | ||
size_t pos = input.find(substring); | ||
while (pos != std::string::npos) { | ||
int endIndex = static_cast<int>(pos + substring.length()); | ||
bool found = false; | ||
for (const std::string &substring: substrings) { | ||
size_t pos = input.find(substring); | ||
while (pos != std::string::npos) { | ||
int endIndex = static_cast<int>(pos + substring.length()); | ||
bool found = false; | ||
|
||
for (auto& info : substringInfoVec) { | ||
if (info.start == static_cast<int>(pos) && endIndex > info.end) { | ||
info.end = endIndex; | ||
found = true; | ||
break; | ||
} | ||
} | ||
for (auto &info: substringInfoVec) { | ||
if (info.start == static_cast<int>(pos) && endIndex > info.end) { | ||
info.end = endIndex; | ||
found = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!found) { | ||
substringInfoVec.push_back({static_cast<int>(pos), endIndex}); | ||
} | ||
if (!found) { | ||
substringInfoVec.push_back({static_cast<int>(pos), endIndex}); | ||
} | ||
|
||
pos = input.find(substring, pos + 1); // Move to the next occurrence | ||
pos = input.find(substring, pos + 1); // Move to the next occurrence | ||
} | ||
} | ||
} | ||
std::sort(substringInfoVec.begin(), substringInfoVec.end(), compareSubstringInfo); | ||
std::sort(substringInfoVec.begin(), substringInfoVec.end(), compareSubstringInfo); | ||
|
||
return substringInfoVec; | ||
return substringInfoVec; | ||
} | ||
|
||
bool isNT(const std::string& s, std::set<std::string>& nonTerminals) { | ||
return nonTerminals.find(s) != nonTerminals.end(); | ||
bool isNT(const std::string &s, std::set<std::string> &nonTerminals) { | ||
return nonTerminals.find(s) != nonTerminals.end(); | ||
} | ||
|
||
std::set<std::string> collectNonTerminals(const std::vector<Production>& grammar) { | ||
std::set<std::string> nonTerminals; | ||
for (const Production& rule : grammar) { | ||
nonTerminals.insert(rule.nonTerminal); | ||
} | ||
return nonTerminals; | ||
std::set<std::string> collectNonTerminals(const std::vector<Production> &grammar) { | ||
std::set<std::string> nonTerminals; | ||
for (const Production &rule: grammar) { | ||
nonTerminals.insert(rule.nonTerminal); | ||
} | ||
return nonTerminals; | ||
} | ||
|
||
std::string getLongestUpperCaseSequence(const std::string& str) { | ||
std::string currentSequence; | ||
std::string longestSequence; | ||
std::string getLongestUpperCaseSequence(const std::string &str) { | ||
std::string currentSequence; | ||
std::string longestSequence; | ||
|
||
for (char ch : str) { | ||
if (isupper(ch)) { | ||
currentSequence += ch; | ||
} else { | ||
// Check if the current sequence is longer than the longest | ||
if (currentSequence.length() > longestSequence.length()) { | ||
longestSequence = currentSequence; | ||
} | ||
// Reset the current sequence | ||
currentSequence.clear(); | ||
for (char ch: str) { | ||
if (isupper(ch)) { | ||
currentSequence += ch; | ||
} else { | ||
// Check if the current sequence is longer than the longest | ||
if (currentSequence.length() > longestSequence.length()) { | ||
longestSequence = currentSequence; | ||
} | ||
// Reset the current sequence | ||
currentSequence.clear(); | ||
} | ||
} | ||
} | ||
|
||
// Check if the last sequence is longer than the longest | ||
if (currentSequence.length() > longestSequence.length()) { | ||
longestSequence = currentSequence; | ||
} | ||
// Check if the last sequence is longer than the longest | ||
if (currentSequence.length() > longestSequence.length()) { | ||
longestSequence = currentSequence; | ||
} | ||
|
||
return longestSequence; | ||
return longestSequence; | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.