1f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar// [The "BSD licence"] 22aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// Copyright (c) 2006-2007 Kay Roepke 2010 Alan Condit 32aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// All rights reserved. 42aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// 52aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// Redistribution and use in source and binary forms, with or without 62aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// modification, are permitted provided that the following conditions 72aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// are met: 82aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// 1. Redistributions of source code must retain the above copyright 9f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar// notice, this list of conditions and the following disclaimer. 102aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// 2. Redistributions in binary form must reproduce the above copyright 112aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// notice, this list of conditions and the following disclaimer in the 122aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// documentation and/or other materials provided with the distribution. 13f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar// 3. The name of the author may not be used to endorse or promote products 142aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// derived from this software without specific prior written permission. 152aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// 162aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 172aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 182aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 192aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 202aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier 272aeb4771a6ca0ee253e4836edbab5705203d9bb4Chad Rosier#import <Cocoa/Cocoa.h> 28c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier#import "ANTLRBaseRecognizer.h" 29c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier#import "ANTLRTreeNodeStream.h" 30c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier#import "ANTLRCommonTreeAdaptor.h" 31c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier#import "ANTLRMismatchedTreeNodeException.h" 32c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier 33f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar@interface ANTLRTreeParser : ANTLRBaseRecognizer { 34c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier id<ANTLRTreeNodeStream> input; 35c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier} 36c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier 37f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar@property (retain, getter=getInput, setter=setInput:) id<ANTLRTreeNodeStream> input; 38c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier 39c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier+ (id) newANTLRTreeParser:(id<ANTLRTreeNodeStream>)anInput; 40c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier+ (id) newANTLRTreeParser:(id<ANTLRTreeNodeStream>)anInput State:(ANTLRRecognizerSharedState *)state; 41c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier 42c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier- (id) initWithStream:(id<ANTLRTreeNodeStream>)theInput; 43c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier- (id) initWithStream:(id<ANTLRTreeNodeStream>)theInput 44c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier State:(ANTLRRecognizerSharedState *)state; 45f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar 46c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier 47c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier- (id<ANTLRTreeNodeStream>)getInput; 48c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier- (void) setInput:(id<ANTLRTreeNodeStream>)anInput; 49f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar 50c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier- (void) setTreeNodeStream:(id<ANTLRTreeNodeStream>) anInput; 51c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier- (id<ANTLRTreeNodeStream>) getTreeNodeStream; 52c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier 53c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier- (NSString *)getSourceName; 54c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier 55c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier- (id) getCurrentInputSymbol:(id<ANTLRIntStream>) anInput; 56c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier 57f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar- (id) getMissingSymbol:(id<ANTLRIntStream>)input 58c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier Exception:(ANTLRRecognitionException *) e 59c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier ExpectedToken:(NSInteger) expectedTokenType 60c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier BitSet:(ANTLRBitSet *)follow; 61f3ef5332fa3f4d5ec72c178a2b19dac363a19383Pirama Arumuga Nainar 62c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier/** Match '.' in tree parser has special meaning. Skip node or 63c97650079383110d66ab104ee60d03ded2be8e35Chad Rosier * entire tree if node has children. If children, scan until 64 * corresponding UP node. 65 */ 66- (void) matchAny:(id<ANTLRIntStream>)ignore; 67 68/** We have DOWN/UP nodes in the stream that have no line info; override. 69 * plus we want to alter the exception type. Don't try to recover 70 * from tree parser errors inline... 71 */ 72- (id) recoverFromMismatchedToken:(id<ANTLRIntStream>)anInput 73 Type:(NSInteger)ttype 74 Follow:(ANTLRBitSet *)follow; 75 76/** Prefix error message with the grammar name because message is 77 * always intended for the programmer because the parser built 78 * the input tree not the user. 79 */ 80- (NSString *)getErrorHeader:(ANTLRRecognitionException *)e; 81 82- (NSString *)getErrorMessage:(ANTLRRecognitionException *)e TokenNames:(NSArray *) tokenNames; 83 84- (void) traceIn:(NSString *)ruleName Index:(NSInteger)ruleIndex; 85- (void) traceOut:(NSString *)ruleName Index:(NSInteger)ruleIndex; 86 87 88 89@end 90