Пример #1
0
        public override void Apply(ParserState state)
        {
            ParserStackItem[] subItems = new ParserStackItem[ReduceWith.Production.Pattern.Length];
            for (var i = subItems.Length - 1; i >= 0; i--)
            {
                subItems[i] = state.ParsedStack.Pop();
                state.StateStack.Pop();
            }
            ParserStackItem reduction = new ParserStackItem(ReduceWith.Production.Name, subItems);

            state.InputStack.Push(reduction);
        }
Пример #2
0
 static void WriteItem(ParserStackItem item)
 {
     if (item == null)
     {
         Console.Write("EOF");
     }
     else if (item.ProductionName != null)
     {
         Console.Write("{" + item.ProductionName + "}");
     }
     else if (item.Token.TokenType == "newline" || item.Token.TokenType == "space")
     {
         Console.Write("<" + item.Token.TokenType + ">");
     }
     else
     {
         Console.Write(item.Token.Value);
     }
 }
Пример #3
0
        static void PrintRecursive(ParserStackItem item, int tabDepth = 0)
        {
            string tabs = new string(' ', tabDepth);

            if (item == null)
            {
                Console.WriteLine(tabs + "EOF");
            }
            else if (item.Token != null)
            {
                Console.WriteLine(tabs + item.Token);
            }
            else
            {
                Console.WriteLine(tabs + "{" + item.ProductionName + "}");
                foreach (var subItem in item.ProductionComponents)
                {
                    PrintRecursive(subItem, tabDepth + 1);
                }
            }
        }
Пример #4
0
 public UnknownTokenException(ParserStackItem stackItem)
     : base($"An input item does not match any column of the parse table. Value = '{stackItem.Token.Value}', Type = '{stackItem.Token.TokenType}'")
 {
     UnrecognizedItem = stackItem.Token;
 }