Handling conflicts

Although APaGeD generates generic LR parsers, that can parse any context free grammar regardless of the conflicts, that the underlying LR tables may have, it may be useful to resolve conflicts to improve the parser's performance.

APaGeD lists details for all conflicts when given the -c command line option.

Conflict resolution can be controlled with three precedence attributes force, deny and prefer. These attributes can follow the header of a non-terminal or the symbols of a rule. If applied to the non-terminal, all rules will use the specified precedence attributes. The precedence attributes specify the parser's behaviour when it encounters a conflict that involves the non-terminal or rule for which the precedence attribute has been specified.

force makes the parser ignore the other branches in a conflict, making this non-terminal or rule the only choice.

deny makes the parser ignore the branch for this non-terminal or rule and only consider the remaining ones.

prefer makes the parser prefer this branch over the others. It will still try all of them, but the order changes. This is useful since many conflicts have branches that are statistically more likely to be correct than others.

Each of the precedence attributes can be followed by a list of symbols. The precedence rules will only consider those branches of the conflict, that

To utilize the prefer attribute, it is useful to measure the performance of conflicts and create the statistic of their branches' success. When the parser is compiled with -version=ProfileConflicts, the parser will count how often a conflicts was encountered and how often on of the branches failed. In examples/profile_conflicts.d is a code snippet, that will extract that data frmo a GLRParser object and print the results.