Example #1
0
 private static ReduceAction CreateReduceAction(ActionSubRecord record, SymbolCollection symbols,
     RuleCollection rules)
 {
     SymbolTerminal symbol = symbols[record.SymbolIndex] as SymbolTerminal;
     Rule rule = rules[record.Target];
     return new ReduceAction(symbol, rule);
 }
Example #2
0
 private static GotoAction CreateGotoAction(ActionSubRecord record, SymbolCollection symbols,
     StateCollection states)
 {
     SymbolNonterminal symbol = symbols[record.SymbolIndex] as SymbolNonterminal;
     State state = states[record.Target];
     return new GotoAction(symbol, state);
 }
Example #3
0
 private static ShiftAction CreateShiftAction(ActionSubRecord record, SymbolCollection symbols,
     StateCollection states)
 {
     State state = states[record.Target];
     SymbolTerminal symbol = symbols[record.SymbolIndex] as SymbolTerminal;
     //todo: exception symbol type
     return new ShiftAction(symbol, state);
 }
Example #4
0
 public ActionSubRecordCollection(Record record, int start)
 {
     list = new ArrayList();
     if ((record.Entries.Count - start) % 4 != 0)
         throw new CGTContentException("Invalid number of entries for actions in LALR state");
     for (int i = start; i < record.Entries.Count; i = i + 4)
     {
         ActionSubRecord actionRecord =
             new ActionSubRecord(record.Entries[i], record.Entries[i + 1], record.Entries[i + 2]);
         list.Add(actionRecord);
     }
 }
 public ActionSubRecordCollection(Record record, int start)
 {
     list = new ArrayList();
     if ((record.Entries.Count - start) % 4 != 0)
     {
         throw new CGTContentException("Invalid number of entries for actions in LALR state");
     }
     for (int i = start; i < record.Entries.Count; i = i + 4)
     {
         ActionSubRecord actionRecord =
             new ActionSubRecord(record.Entries[i], record.Entries[i + 1], record.Entries[i + 2]);
         list.Add(actionRecord);
     }
 }
Example #6
0
 /// <summary>
 /// Creates a new action by specifying the needed information.
 /// </summary>
 /// <param name="record">A part of the LALR record from the file content.</param>
 /// <param name="states">The LALR states.</param>
 /// <param name="symbols">The symbols.</param>
 /// <param name="rules">The rules.</param>
 /// <returns>A new action object.</returns>
 public static Action CreateAction(ActionSubRecord record,
     StateCollection states,
     SymbolCollection symbols,
     RuleCollection rules)
 {
     Action action;
     switch (record.Action)
     {
         case 1: action = CreateShiftAction(record,symbols,states); break;
         case 2: action = CreateReduceAction(record,symbols,rules); break;
         case 3: action = CreateGotoAction(record,symbols,states); break;
         case 4: action = CreateAcceptAction(record,symbols); break;
         default: return null; //todo: make exception
     }
     return action;
 }
Example #7
0
 private static AcceptAction CreateAcceptAction(ActionSubRecord record,
     SymbolCollection symbols)
 {
     SymbolTerminal symbol = symbols[record.SymbolIndex] as SymbolTerminal;
     return new AcceptAction(symbol);
 }