00001 /* 00002 [The "BSD licence"] 00003 Copyright (c) 2005-2007 Kunle Odutola 00004 All rights reserved. 00005 00006 Redistribution and use in source and binary forms, with or without 00007 modification, are permitted provided that the following conditions 00008 are met: 00009 1. Redistributions of source code MUST RETAIN the above copyright 00010 notice, this list of conditions and the following disclaimer. 00011 2. Redistributions in binary form MUST REPRODUCE the above copyright 00012 notice, this list of conditions and the following disclaimer in 00013 the documentation and/or other materials provided with the 00014 distribution. 00015 3. The name of the author may not be used to endorse or promote products 00016 derived from this software without specific prior WRITTEN permission. 00017 4. Unless explicitly state otherwise, any contribution intentionally 00018 submitted for inclusion in this work to the copyright owner or licensor 00019 shall be under the terms and conditions of this license, without any 00020 additional terms or conditions. 00021 00022 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00023 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00024 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00025 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00027 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00028 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00029 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00030 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00031 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 */ 00033 00034 00035 namespace Antlr.Runtime.Debug 00036 { 00037 using System; 00038 using Antlr.Runtime; 00039 using ITreeAdaptor = Antlr.Runtime.Tree.ITreeAdaptor; 00040 using ITreeNodeStream = Antlr.Runtime.Tree.ITreeNodeStream; 00041 00042 00048 public class Tracer : BlankDebugEventListener 00049 { 00050 public IIntStream input; 00051 protected int level = 0; 00052 00053 public Tracer(IIntStream input) 00054 { 00055 this.input = input; 00056 } 00057 00058 override public void EnterRule(string grammarFileName, string ruleName) 00059 { 00060 for (int i = 1; i <= level; i++) 00061 { 00062 Console.Out.Write(" "); 00063 } 00064 Console.Out.WriteLine("> " + grammarFileName + " " + ruleName + " lookahead(1)=" + GetInputSymbol(1)); 00065 level++; 00066 } 00067 00068 override public void ExitRule(string grammarFileName, string ruleName) 00069 { 00070 level--; 00071 for (int i = 1; i <= level; i++) 00072 { 00073 Console.Out.Write(" "); 00074 } 00075 Console.Out.WriteLine("< " + grammarFileName + " " + ruleName + " lookahead(1)=" + GetInputSymbol(1)); 00076 } 00077 00078 public virtual object GetInputSymbol(int k) 00079 { 00080 if (input is ITokenStream) 00081 { 00082 return ((ITokenStream) input).LT(k); 00083 } 00084 return (char) input.LA(k); 00085 } 00086 } 00087 }
1.5.5