1 module gamma.parsgen.lalr1.OrderedLR1Tables; 2 3 import gamma.grammar.Alternative; 4 import gamma.grammar.Grammar; 5 import gamma.grammar.Nonterminal; 6 import gamma.grammar.Terminal; 7 8 /** 9 * Abstract view on the parse tables for a deterministic ordered LR-like parser 10 * with 1-symbol lookahead. The information provided also indicates a continuation 11 * automaton for Röhrich's error repair method. Note that the represented parser 12 * may well be a <emph>nondeterministic</emph> one. 13 * 14 * @author SöKa 15 */ 16 public interface OrderedLR1Tables 17 { 18 public static abstract class Action 19 { 20 public bool isContinuationAction; 21 22 public Terminal lookahead; 23 24 public this(Terminal lookahead) 25 { 26 this.lookahead = lookahead; 27 this.isContinuationAction = false; 28 } 29 } 30 31 public static class Shift : Action 32 { 33 public size_t state; // LRMachine.State.index 34 35 public this(Terminal lookahead, size_t state) 36 { 37 super(lookahead); 38 this.state = state; 39 } 40 } 41 42 public static class Halt : Action 43 { 44 public this(Terminal lookahead) 45 { 46 super(lookahead); 47 } 48 } 49 50 public static class Reduce : Action 51 { 52 public Alternative alternative; 53 54 public this(Terminal lookahead, Alternative alternative) 55 { 56 super(lookahead); 57 this.alternative = alternative; 58 } 59 } 60 61 public static class Goto 62 { 63 public Nonterminal lhs; 64 65 public size_t state; // LRMachine.State.index 66 67 public this(Nonterminal lhs, size_t state) 68 { 69 this.lhs = lhs; 70 this.state = state; 71 } 72 } 73 74 /** 75 * Returns the (extended) grammar that underlies the ordered LR tables. 76 */ 77 Grammar grammar(); 78 79 /** 80 * Returns the number of states in the parser. 81 */ 82 size_t stateCount(); 83 84 /** 85 * Returns the end-of-file Terminal symbol that has been added to the original 86 * grammar to generate the parser. 87 */ 88 Terminal eof(); 89 90 /** 91 * Returns a List of the Shift, Halt, and Reduce entries for the given state's 92 * "parser action table" row. Entries are guaranteed to be sorted by the List 93 * entries' lookahead.index(). 94 * <p> 95 * Implementation must be such that this method can safely be called multiple 96 * times for a fixed <code>state</code> without performance becoming an issue. 97 */ 98 Action[] getSortedParserActionRow(size_t state); 99 100 /** 101 * Returns a List of the Goto entries for the given state's "goto table" row. 102 * Entries are guaranteed to be sorted by the List entries's lhs.index(). 103 * <p> 104 * Implementation must be such that this method can safely be called multiple 105 * times for a fixed <code>state</code> without performance becoming an issue. 106 */ 107 Goto[] getSortedGotoRow(size_t state); 108 }