Skip to content

Commit

Permalink
Show an error message when associativity is assigned to a non-terminal.
Browse files Browse the repository at this point in the history
  • Loading branch information
mingodad committed Jul 16, 2023
1 parent ccdca1a commit c155471
Show file tree
Hide file tree
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
Expand Up @@ -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.
};

}
Expand Down
4 changes: 4 additions & 0 deletions src/lalr/GrammarGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, "error associativity has been assigned to a non-terminal %s", non_terminal_symbol->identifier().c_str());
}
}
}

Expand Down

0 comments on commit c155471

Please sign in to comment.