If any conflict (either shift/reduce or reduce/reduce) is found during LALR(k) construction, then the grammar is not LALR(k).
State merging from LR(1) to LALR(1) cannot produce a shift/reduce conflict, so if there is one, the grammar isn't LR(1) either. But it can produce a reduce/reduce conflict. If it does, the grammar is not LALR(1), even though it is LR(1). (It's not really a question of "validity"; it's a question of parsability by a particular algorithm.)
Yes, precedence (and associativity, which is just a subcase of precedence) allow resolution of shift/reduce conflicts.
Precedence is a comparison between a production (on the left) and a lookahead token (on the right). Associativity affects the comparison operator which is used: either ≤ or < (or, in the case of
%nonassoc
, error-on-equal).
There is an excellent discussion of the algorithm in the Dragon book. However, it's not very complicated: if the production "wins", the parser reduces; otherwise it shifts.
Bonus question: Precedence rules are only applied if there is a precedence defined for both the production (either through %prec
or, by default, the precedence of the last terminal in the production) and the lookahead token. If either of these is missing a precedence declaration, then shift wins. That might not seem logical, but it's the way it is.