1 module gamma.parsgen.lalr1.LR1ConflictResolver;
2 
3 import gamma.grammar.Alternative;
4 import gamma.grammar.Terminal;
5 
6 /**
7  * Controls how shift/reduce and reduce/reduce nondeterminisms in a *LR(1)
8  * parser are resolved.
9  */
10 public interface LR1ConflictResolver
11 {
12     /**
13      * Calls for resolution of a shift/reduce parser conflict:
14      * The parser sees a conflict at state <code>state</code> whether to
15      * shift a <code>terminal</code> or reduce an <code>alternative</code>
16      * (the underlying grammar being understood).
17      * @param terminal
18      * @param alternative
19      * @param state
20      * @return <code>terminal</code> if the shift is favored; <code>alternative</code>
21      *     if the reduce is favored; <code>null</code> if neither is accepted.
22      */
23     Object resolveShiftReduceConflict(
24         Terminal terminal,
25         Alternative alternative,
26         size_t state);
27 
28     /**
29      * Calls for resolution of a reduce/reduce parser conflict:
30      * The parser sees a conflict at state <code>state</code> whether to
31      * reduce an <code>alternative1</code> or reduce an <code>alternative2</code>
32      * (the underlying grammar being understood).
33      * @param alternative1
34      * @param alternative2
35      * @param terminal Look-ahead
36      * @param state
37      * @return <code>alternative1</code> if reducing it is favored;
38      *     <code>alternative2</code> if reducing it is favored;
39      *     or <code>null</code> if neither is accepted.
40      */
41     Object resolveReduceReduceConflict(
42         Alternative alternative1,
43         Alternative alternative2,
44         Terminal terminal,
45         size_t state);
46 
47     /**
48      * Notifies that there is a parser conflict at state <code>state</code>
49      * whether to halt or to reduce an <code>alternative</code>
50      * (the underlying grammar being understood).
51      * This indicates an ambiguity of the grammar.
52      * @param alternative
53      * @param state
54      */
55     void noteHaltConflictOn(Alternative alternative, size_t state);
56 }