Example #1
0
    public ShiftParserAction(BnfTerm term, ParserState newState) {
      if (newState == null)
        throw new Exception("ParserShiftAction: newState may not be null. term: " + term.ToString());

      Term = term; 
      NewState = newState;
    }
Example #2
0
        public ParseState this[ParseState current, BnfTerm symbol]
        {
            get
            {
                Dictionary <BnfTerm, ParseState> transition;
                if (!transitionRules.TryGetValue(current, out transition))
                {
                    if (!allStates.Contains(current))
                    {
                        throw new ParseException("No such state");
                    }
                    else
                    {
                        return(null);
                    }
                }

                ParseState next;
                if (!transition.TryGetValue(symbol, out next))
                {
                    HashSet <Terminal> expected = new HashSet <Terminal>();
                    foreach (var item in current)
                    {
                        if (item.Position < item.Production.Body.Length)
                        {
                            expected.UnionWith(grammar.GetFirstSet(item.Production.Body[item.Position]));
                        }
                    }

                    throw new ParseException("Invalid symbol " + symbol.ToString() + " expected one of [" + String.Join(", ", expected.Select(a => a.Name)) + "]");
                }

                return(next);
            }
        }
Example #3
0
 public ShiftParserAction(BnfTerm term, ParserState newState)
 {
     if (term == null)
     {
         throw new ArgumentNullException(nameof(term));
     }
     NewState = newState ?? throw new ArgumentNullException(nameof(newState), "ParserShiftAction: newState may not be null. term: " + term.ToString());
     Term     = term;
 }
Example #4
0
 public override string ToString()
 {
     return($"{_bnfTerm.ToString()}");
 }