1 module gamma.parsgen.lalr1.run.OrderedLR1TablesImpl; 2 3 import gamma.grammar.Alternative; 4 import gamma.grammar.Grammar; 5 import gamma.grammar.SymbolNode; 6 import gamma.grammar.Terminal; 7 import gamma.parsgen.lalr1.OrderedLR1Tables; 8 9 /** 10 * An implementation suitable for use by an LR1 parser. 11 * 12 * @author SöKa 13 */ 14 public class OrderedLR1TablesImpl : OrderedLR1Tables 15 { 16 private size_t stateCount_; 17 18 private Grammar grammar_; 19 20 private Action[][] parserActionRows; 21 22 private Goto[][] gotoRows; 23 24 private Terminal eof_; 25 26 /** 27 * Constructor method. 28 */ 29 public this(Grammar grammar, Action[][] parserActionRows, Goto[][] gotoRows) 30 in (grammar !is null) 31 in (parserActionRows.length == gotoRows.length) 32 { 33 this.grammar_ = grammar; 34 this.parserActionRows = parserActionRows; 35 this.gotoRows = gotoRows; 36 this.stateCount_ = parserActionRows.length; 37 this.eof_ = 38 cast(Terminal)(cast(SymbolNode)(cast(Alternative) this 39 .grammar_ 40 .ruleOf(this.grammar_.startSymbol) 41 .alternatives[0]) 42 .rhs[1]) 43 .symbol; 44 } 45 46 /* (non-Javadoc) 47 * @see gamma.parsgen.lalr1.OrderedLR1Tables#eof 48 */ 49 public Terminal eof() 50 { 51 return this.eof_; 52 } 53 54 /* (non-Javadoc) 55 * @see gamma.parsgen.lalr1.OrderedLR1Tables#getSortedGotoRow(int) 56 */ 57 public Goto[] getSortedGotoRow(size_t state) 58 { 59 return this.gotoRows[state]; 60 } 61 62 /* (non-Javadoc) 63 * @see gamma.parsgen.lalr1.OrderedLR1Tables#getSortedParserActionRow(int) 64 */ 65 public Action[] getSortedParserActionRow(size_t state) 66 { 67 return this.parserActionRows[state]; 68 } 69 70 /* (non-Javadoc) 71 * @see gamma.parsgen.lalr1.OrderedLR1Tables#grammar 72 */ 73 public Grammar grammar() 74 { 75 return this.grammar_; 76 } 77 78 /* (non-Javadoc) 79 * @see gamma.parsgen.lalr1.OrderedLR1Tables#stateCount 80 */ 81 public size_t stateCount() 82 { 83 return this.stateCount_; 84 } 85 }