Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show an error message when associativity is assigned to a non-terminal.
Browse files Browse the repository at this point in the history
mingodad committed Jul 16, 2023
1 parent ccdca1a commit 9f907f6
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lalr/ErrorCode.hpp
Original file line number Diff line number Diff line change
@@ -25,7 +25,8 @@ enum ErrorCode
PARSER_ERROR_UNDEFINED_SYMBOL, ///< A grammar symbol is referenced but not defined.
PARSER_ERROR_UNREFERENCED_SYMBOL, ///< A grammar symbol is defined but not referenced.
PARSER_ERROR_ERROR_SYMBOL_ON_LEFT_HAND_SIDE, ///< The 'error' symbol has been used on the left hand side of a production.
PARSER_ERROR_DUPLICATE_ASSOCIATION_ON_IMPLICIT_TERMINAL ///< Both implicit terminal forms specify associativity and precedence.
PARSER_ERROR_DUPLICATE_ASSOCIATION_ON_IMPLICIT_TERMINAL, ///< Both implicit terminal forms specify associativity and precedence.
PARSER_ERROR_ASSOCIATIVITY_ASSIGNED_ON_NON_TERMINAL ///< Associativity has been assigned to a non-terminal.
};

}
4 changes: 4 additions & 0 deletions src/lalr/GrammarGenerator.cpp
Original file line number Diff line number Diff line change
@@ -573,6 +573,10 @@ void GrammarGenerator::calculate_implicit_terminal_symbols()
replace_references_to_symbol( non_terminal_symbol, terminal_symbol );
i->reset();
}
else if(non_terminal_symbol->associativity() != ASSOCIATE_NULL && non_terminal_symbol->productions().size())
{
error( non_terminal_symbol->line(), PARSER_ERROR_ASSOCIATIVITY_ASSIGNED_ON_NON_TERMINAL, "associativity has been assigned to a non-terminal: %s", non_terminal_symbol->identifier().c_str());
}
}
}

0 comments on commit 9f907f6

Please sign in to comment.