示例#1
0
        private static void Main(string[] args)
        {
            try
            {
                string        input = "";
                StringBuilder text  = new StringBuilder();
                Console.WriteLine("Input the chat.");

                // to type the EOF character and end the input: use CTRL+D, then press <enter>
                while ((input = Console.ReadLine()) != "\u0004")
                {
                    text.AppendLine(input);
                }
                AntlrInputStream  inputStream       = new AntlrInputStream(text.ToString());
                SpeakLexer        speakLexer        = new SpeakLexer(inputStream);
                CommonTokenStream commonTokenStream = new CommonTokenStream(speakLexer);
                SpeakParser       speakParser       = new SpeakParser(commonTokenStream);

                SpeakParser.ChatContext chatContext = speakParser.chat();
                SpeakVisitor            visitor     = new SpeakVisitor();
                visitor.Visit(chatContext);

                foreach (var line in visitor.Lines)
                {
                    Console.WriteLine("{0} has said {1}", line.Person, line.Text);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex);
            }
        }
 /// <summary>
 /// Exit a parse tree produced by <see cref="SpeakParser.chat"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitChat([NotNull] SpeakParser.ChatContext context)
 {
 }
示例#3
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="SpeakParser.chat"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitChat([NotNull] SpeakParser.ChatContext context)
 {
     return(VisitChildren(context));
 }