Ejemplo n.º 1
0
        static void PrintLispTree(DialogicParser parser, ParserRuleContext prc)
        {
            string tree        = prc.ToStringTree(parser);
            int    indentation = 1;

            Console.WriteLine("\nPARSE-TREE");
            foreach (char c in tree)
            {
                if (c == '(')
                {
                    if (indentation > 1)
                    {
                        Console.WriteLine();
                    }
                    for (int i = 0; i < indentation; i++)
                    {
                        Console.Write("  ");
                    }
                    indentation++;
                }
                else if (c == ')')
                {
                    indentation--;
                }
                Console.Write(c);
            }
            Console.WriteLine("\n");
        }
Ejemplo n.º 2
0
        public void Test()
        {
            string            source  = "split.gs";
            ITokenSource      lexer   = new DialogicLexer(new AntlrInputStream(source));
            CommonTokenStream tokens  = new CommonTokenStream(lexer);
            DialogicParser    parser  = new DialogicParser(tokens);
            ParserRuleContext context = parser.script();

            Visit(context);
            String tree = context.ToStringTree(parser);

            printPrettyLispTree(tree);
        }
Ejemplo n.º 3
0
        protected static List <Chat> Parse(string[] lines)
        {
            HandleDefaultCommand(lines, "SAY");
            var            ais    = new AntlrInputStream(String.Join("\n", lines));
            DialogicParser parser = CreateParser(ais);

            parser.ErrorHandler = new BailErrorStrategy();
            ParserRuleContext prc = parser.script();
            ChatParser        cp  = new ChatParser();

            cp.Visit(prc);
            PrintLispTree(parser, prc);
            Console.WriteLine(cp);
            return(cp.chats);
        }