Skip to content

Commit

Permalink
ANYCC 47
Browse files Browse the repository at this point in the history
- Modify print
  • Loading branch information
Bazina committed Dec 25, 2023
1 parent cf09ef7 commit 1f60051
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/Parser/PredictiveTopDownParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ bool PredictiveTopDownParser::handleMatchOrError(const StackItem &top, Token *&c
if (top.isTerminal) {
if (top.token == *(curr_token->getKey())) {
handleMatch(top, curr_token);
}
else if (top.token == "$") {
} else if (top.token == "$") {
handleEndOfStack(curr_token);
}
else {
} else {
handleMissingTerminal(top, curr_token);
}
return true;
Expand All @@ -79,7 +77,7 @@ void PredictiveTopDownParser::handleEndOfStack(Token *&curr_token) {
curr_token = lex.getNextToken();
while (*(curr_token->getKey()) != "$") {
parsingFile << "| $ | " << *(curr_token->getKey())
<< " | Error: ``" << *(curr_token->getKey()) << "`` discarded |";
<< " | Error: ``" << *(curr_token->getKey()) << "`` discarded |";

std::cerr << "Error: " << *(curr_token->getKey()) << " discarded" << std::endl;
curr_token = lex.getNextToken();
Expand Down Expand Up @@ -110,10 +108,6 @@ void PredictiveTopDownParser::handleNonTerminal(const StackItem &top, Token *&cu

// Helper functions for error handling and stack operations
void PredictiveTopDownParser::handleMissingTerminal(const StackItem &top, Token *&curr_token) {
if (*(curr_token->getKey()) == "$") {
handleEndOfInput(top); // report error and pop stack
return;
}
parsingFile << "Error: missing ``" << top.token << "`` inserted" << " |";

std::cerr << "Error: missing '" << top.token << "' inserted" << std::endl;
Expand Down

0 comments on commit 1f60051

Please sign in to comment.