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