1/** \file 2 * This OBJC source file was generated by $ANTLR version 3.3.1-SNAPSHOT Jan 30, 2011 08:28:24 3 * 4 * - From the grammar source file : PolyPrinter.g 5 * - On : 2011-01-30 08:45:32 6 * - for the tree parser : PolyPrinterTreeParser * 7 * Editing it, at least manually, is not wise. 8 * 9 * ObjC language generator and runtime by Alan Condit, acondit|hereisanat|ipns|dotgoeshere|com. 10 * 11 * 12*/ 13// [The "BSD licence"] 14// Copyright (c) 2010 Alan Condit 15// 16// All rights reserved. 17// 18// Redistribution and use in source and binary forms, with or without 19// modification, are permitted provided that the following conditions 20// are met: 21// 1. Redistributions of source code must retain the above copyright 22// notice, this list of conditions and the following disclaimer. 23// 2. Redistributions in binary form must reproduce the above copyright 24// notice, this list of conditions and the following disclaimer in the 25// documentation and/or other materials provided with the distribution. 26// 3. The name of the author may not be used to endorse or promote products 27// derived from this software without specific prior written permission. 28// 29// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 30// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 31// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 32// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 33// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 34// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 38// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 40// $ANTLR 3.3.1-SNAPSHOT Jan 30, 2011 08:28:24 PolyPrinter.g 2011-01-30 08:45:32 41 42/* ----------------------------------------- 43 * Include the ANTLR3 generated header file. 44 */ 45#import <ST4/ST.h> 46#import <ST4/STGroup.h> 47#import "PolyPrinter.h" 48/* ----------------------------------------- */ 49 50 51/* ============================================================================= */ 52 53/* ============================================================================= 54 * Start of recognizer 55 */ 56 57 58 59#pragma mark Bitsets 60static ANTLRBitSet *FOLLOW_8_in_poly43; 61static const unsigned long long FOLLOW_8_in_poly43_data[] = { 0x0000000000000004LL}; 62static ANTLRBitSet *FOLLOW_poly_in_poly48; 63static const unsigned long long FOLLOW_poly_in_poly48_data[] = { 0x0000000000000370LL}; 64static ANTLRBitSet *FOLLOW_poly_in_poly52; 65static const unsigned long long FOLLOW_poly_in_poly52_data[] = { 0x0000000000000008LL}; 66static ANTLRBitSet *FOLLOW_MULT_in_poly74; 67static const unsigned long long FOLLOW_MULT_in_poly74_data[] = { 0x0000000000000004LL}; 68static ANTLRBitSet *FOLLOW_poly_in_poly78; 69static const unsigned long long FOLLOW_poly_in_poly78_data[] = { 0x0000000000000370LL}; 70static ANTLRBitSet *FOLLOW_poly_in_poly82; 71static const unsigned long long FOLLOW_poly_in_poly82_data[] = { 0x0000000000000008LL}; 72static ANTLRBitSet *FOLLOW_9_in_poly104; 73static const unsigned long long FOLLOW_9_in_poly104_data[] = { 0x0000000000000004LL}; 74static ANTLRBitSet *FOLLOW_poly_in_poly109; 75static const unsigned long long FOLLOW_poly_in_poly109_data[] = { 0x0000000000000370LL}; 76static ANTLRBitSet *FOLLOW_poly_in_poly113; 77static const unsigned long long FOLLOW_poly_in_poly113_data[] = { 0x0000000000000008LL}; 78static ANTLRBitSet *FOLLOW_INT_in_poly134; 79static const unsigned long long FOLLOW_INT_in_poly134_data[] = { 0x0000000000000002LL}; 80static ANTLRBitSet *FOLLOW_ID_in_poly148; 81static const unsigned long long FOLLOW_ID_in_poly148_data[] = { 0x0000000000000002LL}; 82 83 84#pragma mark Dynamic Global Scopes 85 86#pragma mark Dynamic Rule Scopes 87 88#pragma mark Rule return scopes start 89@implementation PolyPrinter_poly_return /* returnScope */ 90 /* start of synthesize -- OBJC-Line 1837 */ 91+ (PolyPrinter_poly_return *)newPolyPrinter_poly_return 92{ 93 return [[[PolyPrinter_poly_return alloc] init] retain]; 94} 95 96- (id) getTemplate { return st; } 97 98//public StringTemplate st; 99//public Object getTemplate() { return st; } 100//public String toString() { return st==null?null:st.toString(); } 101 102@end /* end of returnScope implementation */ 103 104 105 106@implementation PolyPrinter // line 637 107 108+ (void) initialize 109{ 110 #pragma mark Bitsets 111 FOLLOW_8_in_poly43 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_8_in_poly43_data Count:(NSUInteger)1] retain]; 112 FOLLOW_poly_in_poly48 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_poly_in_poly48_data Count:(NSUInteger)1] retain]; 113 FOLLOW_poly_in_poly52 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_poly_in_poly52_data Count:(NSUInteger)1] retain]; 114 FOLLOW_MULT_in_poly74 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_MULT_in_poly74_data Count:(NSUInteger)1] retain]; 115 FOLLOW_poly_in_poly78 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_poly_in_poly78_data Count:(NSUInteger)1] retain]; 116 FOLLOW_poly_in_poly82 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_poly_in_poly82_data Count:(NSUInteger)1] retain]; 117 FOLLOW_9_in_poly104 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_9_in_poly104_data Count:(NSUInteger)1] retain]; 118 FOLLOW_poly_in_poly109 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_poly_in_poly109_data Count:(NSUInteger)1] retain]; 119 FOLLOW_poly_in_poly113 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_poly_in_poly113_data Count:(NSUInteger)1] retain]; 120 FOLLOW_INT_in_poly134 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_INT_in_poly134_data Count:(NSUInteger)1] retain]; 121 FOLLOW_ID_in_poly148 = [[ANTLRBitSet newBitSetWithBits:(const unsigned long long *)FOLLOW_ID_in_poly148_data Count:(NSUInteger)1] retain]; 122 123 [BaseRecognizer setTokenNames:[[NSArray arrayWithObjects:@"<invalid>", @"<EOR>", @"<DOWN>", @"<UP>", 124 @"MULT", @"INT", @"ID", @"WS", @"'+'", @"'^'", nil] retain]]; 125 [BaseRecognizer setGrammarFileName:@"PolyPrinter.g"]; 126} 127 128+ (PolyPrinter *)newPolyPrinter:(id<TreeNodeStream>)aStream 129{ 130 131 return [[PolyPrinter alloc] initWithStream:aStream]; 132 133} 134 135 136- (id) initWithStream:(id<TreeNodeStream>)aStream 137{ 138 if ((self = [super initWithStream:aStream State:[[RecognizerSharedState newRecognizerSharedStateWithRuleLen:1+1] retain]]) != nil) { 139 140 141 /* start of actions-actionScope-init */ 142 /* start of init */ 143 } 144 return self; 145} 146 147- (void) dealloc 148{ 149 [super dealloc]; 150} 151 152/* members */ 153 154 155/* start actions.actionScope.methods */ 156/* start methods() */ 157/*protected StringTemplateGroup templateLib = new StringTemplateGroup("PolyPrinterTemplates", AngleBracketTemplateLexer.class); */ 158STGroup *templateLib = [STGroup newSTGroup]; 159 160//public void setTemplateLib(StringTemplateGroup templateLib) { 161// this.templateLib = templateLib; 162//} 163//public StringTemplateGroup getTemplateLib() { 164// return templateLib; 165//} 166- (void) setTemplateLib:(STGroup *)aTemplateLib { templateLib = aTemplateLib; } 167- (STGroup *)getTemplateLib { return templateLib; } 168/** allows convenient multi-value initialization: 169 * "new STAttrMap().put(...).put(...)" 170 */ 171/* 172public static class STAttrMap extends HashMap { 173 public STAttrMap put(String attrName, Object value) { 174 super.put(attrName, value); 175 return this; 176 } 177 public STAttrMap put(String attrName, int value) { 178 super.put(attrName, new Integer(value)); 179 return this; 180 } 181} 182 */ 183// start rules 184/* 185 * $ANTLR start poly 186 * PolyPrinter.g:9:1: poly : ( ^( '+' a= poly b= poly ) -> template(a=$a.stb=$b.st) \"<a>+<b>\" | ^( MULT a= poly b= poly ) -> template(a=$a.stb=$b.st) \"<a><b>\" | ^( '^' a= poly b= poly ) -> template(a=$a.stb=$b.st) \"<a>^<b>\" | INT -> {%{$INT.text}} | ID -> {%{$ID.text}}); 187 */ 188- (PolyPrinter_poly_return *) poly 189{ 190 /* ruleScopeSetUp */ 191 192 PolyPrinter_poly_return * retval = [PolyPrinter_poly_return newPolyPrinter_poly_return]; 193 [retval setStart:[input LT:1]]; 194 195 @try { 196 CommonTree *INT1 = nil; 197 CommonTree *ID2 = nil; 198 PolyPrinter_poly_return * a = nil; 199 200 PolyPrinter_poly_return * b = nil; 201 202 203 // PolyPrinter.g:9:5: ( ^( '+' a= poly b= poly ) -> template(a=$a.stb=$b.st) \"<a>+<b>\" | ^( MULT a= poly b= poly ) -> template(a=$a.stb=$b.st) \"<a><b>\" | ^( '^' a= poly b= poly ) -> template(a=$a.stb=$b.st) \"<a>^<b>\" | INT -> {%{$INT.text}} | ID -> {%{$ID.text}}) //ruleblock 204 NSInteger alt1=5; 205 switch ([input LA:1]) { 206 case 8: ; 207 { 208 alt1=1; 209 } 210 break; 211 case MULT: ; 212 { 213 alt1=2; 214 } 215 break; 216 case 9: ; 217 { 218 alt1=3; 219 } 220 break; 221 case INT: ; 222 { 223 alt1=4; 224 } 225 break; 226 case ID: ; 227 { 228 alt1=5; 229 } 230 break; 231 232 default: ; 233 NoViableAltException *nvae = [NoViableAltException newException:1 state:0 stream:input]; 234 @throw nvae; 235 } 236 237 switch (alt1) { 238 case 1 : ; 239 // PolyPrinter.g:9:7: ^( '+' a= poly b= poly ) // alt 240 { 241 [self match:input TokenType:8 Follow:FOLLOW_8_in_poly43]; 242 243 [self match:input TokenType:DOWN Follow:nil]; 244 /* ruleRef */ 245 [self pushFollow:FOLLOW_poly_in_poly48]; 246 a = [self poly]; 247 248 [self popFollow]; 249 250 251 /* ruleRef */ 252 [self pushFollow:FOLLOW_poly_in_poly52]; 253 b = [self poly]; 254 255 [self popFollow]; 256 257 258 259 [self match:input TokenType:UP Follow:nil]; 260 261 262 // TEMPLATE REWRITE 263 // 9:29: -> template(a=$a.stb=$b.st) \"<a>+<b>\" 264 { 265 retval.st = new StringTemplate(templateLib, "<a>+<b>", 266 new STAttrMap().put("a", (a!=nil?[a st]:nil)).put("b", (b!=nil?[b st]:nil))); 267 } 268 269 270 } 271 break; 272 case 2 : ; 273 // PolyPrinter.g:10:4: ^( MULT a= poly b= poly ) // alt 274 { 275 [self match:input TokenType:MULT Follow:FOLLOW_MULT_in_poly74]; 276 277 [self match:input TokenType:DOWN Follow:nil]; 278 /* ruleRef */ 279 [self pushFollow:FOLLOW_poly_in_poly78]; 280 a = [self poly]; 281 282 [self popFollow]; 283 284 285 /* ruleRef */ 286 [self pushFollow:FOLLOW_poly_in_poly82]; 287 b = [self poly]; 288 289 [self popFollow]; 290 291 292 293 [self match:input TokenType:UP Follow:nil]; 294 295 296 // TEMPLATE REWRITE 297 // 10:26: -> template(a=$a.stb=$b.st) \"<a><b>\" 298 { 299 retval.st = new StringTemplate(templateLib, "<a><b>", 300 new STAttrMap().put("a", (a!=nil?[a st]:nil)).put("b", (b!=nil?[b st]:nil))); 301 } 302 303 304 } 305 break; 306 case 3 : ; 307 // PolyPrinter.g:11:4: ^( '^' a= poly b= poly ) // alt 308 { 309 [self match:input TokenType:9 Follow:FOLLOW_9_in_poly104]; 310 311 [self match:input TokenType:DOWN Follow:nil]; 312 /* ruleRef */ 313 [self pushFollow:FOLLOW_poly_in_poly109]; 314 a = [self poly]; 315 316 [self popFollow]; 317 318 319 /* ruleRef */ 320 [self pushFollow:FOLLOW_poly_in_poly113]; 321 b = [self poly]; 322 323 [self popFollow]; 324 325 326 327 [self match:input TokenType:UP Follow:nil]; 328 329 330 // TEMPLATE REWRITE 331 // 11:26: -> template(a=$a.stb=$b.st) \"<a>^<b>\" 332 { 333 retval.st = [ST newST:@"<a>^<b>"]; 334 [retval.st add:@"a" value:@"b"]; 335 } 336 337 338 } 339 break; 340 case 4 : ; 341 // PolyPrinter.g:12:4: INT // alt 342 { 343 INT1=(CommonTree *)[self match:input TokenType:INT Follow:FOLLOW_INT_in_poly134]; 344 345 346 // TEMPLATE REWRITE 347 // 12:13: -> {%{$INT.text}} 348 { 349 retval.st = [ST newST:(INT1!=nil?INT1.text:nil)]; 350 } 351 352 353 } 354 break; 355 case 5 : ; 356 // PolyPrinter.g:13:4: ID // alt 357 { 358 ID2=(CommonTree *)[self match:input TokenType:ID Follow:FOLLOW_ID_in_poly148]; 359 360 361 // TEMPLATE REWRITE 362 // 13:12: -> {%{$ID.text}} 363 { 364 retval.st = [ST newST:ID2!=nil?[ID2.text]:nil]; 365 } 366 367 368 } 369 break; 370 371 } 372 // token+rule list labels 373 374 } 375 @catch (RecognitionException *re) { 376 [self reportError:re]; 377 [self recover:input Exception:re]; 378 } 379 @finally { 380 } 381 return retval; 382} 383/* $ANTLR end poly */ 384 385@end /* end of PolyPrinter implementation line 692 */ 386 387 388/* End of code 389 * ============================================================================= 390 */ 391