📄 simplecparser.m
字号:
- (void) setTree:(id)aTree{ if (tree != aTree) { [aTree retain]; [tree release]; tree = aTree; }}@end@implementation SimpleCParser_atom_return- (id) tree{ return tree;}- (void) setTree:(id)aTree{ if (tree != aTree) { [aTree retain]; [tree release]; tree = aTree; }}@end@implementation SimpleCParser+ (void) initialize{ FOLLOW_declaration_in_program85 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_declaration_in_program85_data count:1]; FOLLOW_variable_in_declaration105 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_variable_in_declaration105_data count:1]; FOLLOW_functionHeader_in_declaration115 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_functionHeader_in_declaration115_data count:1]; FOLLOW_21_in_declaration117 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_21_in_declaration117_data count:1]; FOLLOW_functionHeader_in_declaration135 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_functionHeader_in_declaration135_data count:1]; FOLLOW_block_in_declaration137 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_block_in_declaration137_data count:1]; FOLLOW_type_in_variable166 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_type_in_variable166_data count:1]; FOLLOW_declarator_in_variable168 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_declarator_in_variable168_data count:1]; FOLLOW_21_in_variable170 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_21_in_variable170_data count:1]; FOLLOW_SimpleCParser_ID_in_declarator199 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_SimpleCParser_ID_in_declarator199_data count:1]; FOLLOW_type_in_functionHeader219 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_type_in_functionHeader219_data count:1]; FOLLOW_SimpleCParser_ID_in_functionHeader221 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_SimpleCParser_ID_in_functionHeader221_data count:1]; FOLLOW_22_in_functionHeader223 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_22_in_functionHeader223_data count:1]; FOLLOW_formalParameter_in_functionHeader227 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_formalParameter_in_functionHeader227_data count:1]; FOLLOW_23_in_functionHeader231 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_23_in_functionHeader231_data count:1]; FOLLOW_formalParameter_in_functionHeader233 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_formalParameter_in_functionHeader233_data count:1]; FOLLOW_24_in_functionHeader241 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_24_in_functionHeader241_data count:1]; FOLLOW_type_in_formalParameter281 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_type_in_formalParameter281_data count:1]; FOLLOW_declarator_in_formalParameter283 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_declarator_in_formalParameter283_data count:1]; FOLLOW_set_in_type312 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_set_in_type312_data count:1]; FOLLOW_25_in_block376 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_25_in_block376_data count:1]; FOLLOW_variable_in_block390 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_variable_in_block390_data count:1]; FOLLOW_stat_in_block405 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_stat_in_block405_data count:1]; FOLLOW_26_in_block416 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_26_in_block416_data count:1]; FOLLOW_forStat_in_stat449 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_forStat_in_stat449_data count:1]; FOLLOW_expr_in_stat457 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_expr_in_stat457_data count:1]; FOLLOW_21_in_stat459 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_21_in_stat459_data count:1]; FOLLOW_block_in_stat468 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_block_in_stat468_data count:1]; FOLLOW_assignStat_in_stat476 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_assignStat_in_stat476_data count:1]; FOLLOW_21_in_stat478 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_21_in_stat478_data count:1]; FOLLOW_21_in_stat487 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_21_in_stat487_data count:1]; FOLLOW_SimpleCParser_FOR_in_forStat507 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_SimpleCParser_FOR_in_forStat507_data count:1]; FOLLOW_22_in_forStat509 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_22_in_forStat509_data count:1]; FOLLOW_assignStat_in_forStat513 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_assignStat_in_forStat513_data count:1]; FOLLOW_21_in_forStat515 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_21_in_forStat515_data count:1]; FOLLOW_expr_in_forStat517 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_expr_in_forStat517_data count:1]; FOLLOW_21_in_forStat519 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_21_in_forStat519_data count:1]; FOLLOW_assignStat_in_forStat523 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_assignStat_in_forStat523_data count:1]; FOLLOW_24_in_forStat525 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_24_in_forStat525_data count:1]; FOLLOW_block_in_forStat527 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_block_in_forStat527_data count:1]; FOLLOW_SimpleCParser_ID_in_assignStat570 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_SimpleCParser_ID_in_assignStat570_data count:1]; FOLLOW_SimpleCParser_EQ_in_assignStat572 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_SimpleCParser_EQ_in_assignStat572_data count:1]; FOLLOW_expr_in_assignStat574 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_expr_in_assignStat574_data count:1]; FOLLOW_condExpr_in_expr598 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_condExpr_in_expr598_data count:1]; FOLLOW_aexpr_in_condExpr617 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_aexpr_in_condExpr617_data count:1]; FOLLOW_SimpleCParser_EQEQ_in_condExpr622 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_SimpleCParser_EQEQ_in_condExpr622_data count:1]; FOLLOW_SimpleCParser_LT_in_condExpr627 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_SimpleCParser_LT_in_condExpr627_data count:1]; FOLLOW_aexpr_in_condExpr631 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_aexpr_in_condExpr631_data count:1]; FOLLOW_atom_in_aexpr653 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_atom_in_aexpr653_data count:1]; FOLLOW_SimpleCParser_PLUS_in_aexpr657 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_SimpleCParser_PLUS_in_aexpr657_data count:1]; FOLLOW_atom_in_aexpr660 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_atom_in_aexpr660_data count:1]; FOLLOW_SimpleCParser_ID_in_atom680 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_SimpleCParser_ID_in_atom680_data count:1]; FOLLOW_SimpleCParser_INT_in_atom694 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_SimpleCParser_INT_in_atom694_data count:1]; FOLLOW_22_in_atom708 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_22_in_atom708_data count:1]; FOLLOW_expr_in_atom710 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_expr_in_atom710_data count:1]; FOLLOW_24_in_atom712 = [[ANTLRBitSet alloc] initWithBits:FOLLOW_24_in_atom712_data count:1];}- (id) initWithTokenStream:(id<ANTLRTokenStream>)aStream{ if ((self = [super initWithTokenStream:aStream])) { tokenNames = [[NSArray alloc] initWithObjects:@"<invalid>", @"<EOR>", @"<DOWN>", @"<UP>", @"VAR_DEF", @"ARG_DEF", @"FUNC_HDR", @"FUNC_DECL", @"FUNC_DEF", @"BLOCK", @"ID", @"EQ", @"INT", @"FOR", @"INT_TYPE", @"CHAR", @"VOID", @"EQEQ", @"LT", @"PLUS", @"WS", @"';'", @"'('", @"','", @"')'", @"'{'", @"'}'", nil]; dfa2 = [[SimpleCParserDFA2 alloc] initWithRecognizer:self]; [self setTreeAdaptor:[[[ANTLRCommonTreeAdaptor alloc] init] autorelease]]; } return self;}- (void) dealloc{ [tokenNames release]; [dfa2 release]; [self setTreeAdaptor:nil]; [super dealloc];}- (NSString *) grammarFileName{ return @"SimpleC.g";}// $ANTLR start program// SimpleC.g:16:1: program : ( declaration )+ ;- (SimpleCParser_program_return *) program{ SimpleCParser_program_return * _retval = [[SimpleCParser_program_return alloc] init]; [_retval setStart:[input LT:1]]; id root_0 = nil; // token labels // token+rule list labels // rule labels SimpleCParser_declaration_return * _declaration1 = nil; // rule list labels // rule refs in alts with rewrites @try { // SimpleC.g:17:9: ( ( declaration )+ ) // ruleBlockSingleAlt // SimpleC.g:17:9: ( declaration )+ // alt { root_0 = (id)[treeAdaptor emptyTree]; // SimpleC.g:17:9: ( declaration )+ // positiveClosureBlock int cnt1=0; do { int alt1=2; { int LA1_0 = [input LA:1]; if ( LA1_0==SimpleCParser_ID||(LA1_0>=SimpleCParser_INT_TYPE && LA1_0<=SimpleCParser_VOID) ) { alt1 = 1; } } switch (alt1) { case 1 : // SimpleC.g:17:9: declaration // alt { [following addObject:FOLLOW_declaration_in_program85]; _declaration1 = [self declaration]; [following removeLastObject]; [treeAdaptor addChild:[_declaration1 tree] toTree:root_0]; } break; default : if ( cnt1 >= 1 ) goto loop1; ANTLREarlyExitException *eee = [ANTLREarlyExitException exceptionWithStream:input decisionNumber:1]; @throw eee; } cnt1++; } while (YES); loop1: ; } } @catch (ANTLRRecognitionException *re) { [self reportError:re]; [self recover:input exception:re]; } @finally { // token labels // token+rule list labels // rule labels [_declaration1 release]; // rule refs in alts with rewrites [_retval setStop:[input LT:-1]]; [_retval setTree:(id)[treeAdaptor postProcessTree:root_0]]; [treeAdaptor setBoundariesForTree:[_retval tree] fromToken:[_retval start] toToken:[_retval stop]]; } return _retval;}// $ANTLR end program// $ANTLR start declaration// SimpleC.g:20:1: declaration : ( variable | functionHeader ';' -> ^( FUNC_DECL functionHeader ) | functionHeader block -> ^( FUNC_DEF functionHeader block ) );- (SimpleCParser_declaration_return *) declaration{ SimpleCParser_declaration_return * _retval = [[SimpleCParser_declaration_return alloc] init]; [_retval setStart:[input LT:1]]; id root_0 = nil; // token labels ANTLRToken * _char_literal4 = nil; // token+rule list labels // rule labels SimpleCParser_variable_return * _variable2 = nil; SimpleCParser_functionHeader_return * _functionHeader3 = nil; SimpleCParser_functionHeader_return * _functionHeader5 = nil; SimpleCParser_block_return * _block6 = nil; // rule list labels // rule refs in alts with rewrites NSMutableArray *_list_functionHeader = [[NSMutableArray alloc] init]; NSMutableArray *_list_block = [[NSMutableArray alloc] init]; NSMutableArray *_list_21 = [[NSMutableArray alloc] init]; id _char_literal4_tree = nil; @try { // SimpleC.g:21:9: ( variable | functionHeader ';' -> ^( FUNC_DECL functionHeader ) | functionHeader block -> ^( FUNC_DEF functionHeader block ) ) //ruleblock int alt2=3; alt2 = [dfa2 predict]; switch (alt2) { case 1 : // SimpleC.g:21:9: variable // alt { root_0 = (id)[treeAdaptor emptyTree]; [following addObject:FOLLOW_variable_in_declaration105]; _variable2 = [self variable]; [following removeLastObject]; [treeAdaptor addChild:[_variable2 tree] toTree:root_0]; } break; case 2 : // SimpleC.g:22:9: functionHeader ';' // alt { [following addObject:FOLLOW_functionHeader_in_declaration115]; _functionHeader3 = [self functionHeader]; [following removeLastObject]; [_list_functionHeader addObject:[_functionHeader3 tree]]; _char_literal4=(ANTLRToken *)[input LT:1]; [_char_literal4 retain]; [self match:input tokenType:21 follow:FOLLOW_21_in_declaration117]; [_list_21 addObject:_char_literal4]; // AST REWRITE int i_0 = 0; [_retval setTree:root_0]; root_0 = (id)[treeAdaptor emptyTree]; // 22:28: -> ^( FUNC_DECL functionHeader ) { // SimpleC.g:22:31: ^( FUNC_DECL functionHeader ) { id root_1 = (id)[treeAdaptor emptyTree]; root_1 = (id)[treeAdaptor makeNode:[treeAdaptor newTreeWithTokenType:SimpleCParser_FUNC_DECL text:[tokenNames objectAtIndex:SimpleCParser_FUNC_DECL]] parentOf:root_1]; [treeAdaptor addChild:(id<ANTLRTree>)[_list_functionHeader objectAtIndex:i_0] toTree:root_1]; [treeAdaptor addChild:root_1 toTree:root_0]; } } } break; case 3 : // SimpleC.g:23:9: functionHeader block // alt { [following addObject:FOLLOW_functionHeader_in_declaration135]; _functionHeader5 = [self functionHeader]; [following removeLastObject]; [_list_functionHeader addObject:[_functionHeader5 tree]]; [following addObject:FOLLOW_block_in_declaration137]; _block6 = [self block]; [following removeLastObject]; [_list_block addObject:[_block6 tree]]; // AST REWRITE int i_0 = 0; [_retval setTree:root_0]; root_0 = (id)[treeAdaptor emptyTree]; // 23:30: -> ^( FUNC_DEF functionHeader block ) { // SimpleC.g:23:33: ^( FUNC_DEF functionHeader block ) { id root_1 = (id)[treeAdaptor emptyTree]; root_1 = (id)[treeAdaptor makeNode:[treeAdaptor newTreeWithTokenType:SimpleCParser_FUNC_DEF text:[tokenNames objectAtIndex:SimpleCParser_FUNC_DEF]] parentOf:root_1]; [treeAdaptor addChild:(id<ANTLRTree>)[_list_functionHeader objectAtIndex:i_0] toTree:root_1]; [treeAdaptor addChild:(id<ANTLRTree>)[_list_block objectAtIndex:i_0] toTree:root_1]; [treeAdaptor addChild:root_1 toTree:root_0]; } } } break; } } @catch (ANTLRRecognitionException *re) { [self reportError:re]; [self recover:input exception:re]; } @finally { // token labels [_char_literal4 release]; // token+rule list labels // rule labels [_variable2 release]; [_functionHeader3 release]; [_functionHeader5 release]; [_block6 release]; // rule refs in alts with rewrites [_list_functionHeader release]; [_list_block release]; [_list_21 release]; [_retval setStop:[input LT:-1]]; [_retval setTree:(id)[treeAdaptor postProcessTree:root_0]]; [treeAdaptor setBoundariesForTree:[_retval tree] fromToken:[_retval start] toToken:[_retval stop]]; } return _retval;}// $ANTLR end declaration// $ANTLR start variable// SimpleC.g:26:1: variable : type declarator ';' -> ^( VAR_DEF type declarator ) ;- (SimpleCParser_variable_return *) variable{ SimpleCParser_variable_return * _retval = [[SimpleCParser_variable_return alloc] init]; [_retval setStart:[input LT:1]]; id root_0 = nil; // token labels ANTLRToken * _char_literal9 = nil; // token+rule list labels // rule labels SimpleCParser_type_return * _type7 = nil; SimpleCParser_declarator_return * _declarator8 = nil; // rule list labels // rule refs in alts with rewrites NSMutableArray *_list_type = [[NSMutableArray alloc] init]; NSMutableArray *_list_declarator = [[NSMutableArray alloc] init]; NSMutableArray *_list_21 = [[NSMutableArray alloc] init]; id _char_literal9_tree = nil; @try { // SimpleC.g:27:9: ( type declarator ';' -> ^( VAR_DEF type declarator ) ) // ruleBlockSingleAlt // SimpleC.g:27:9: type declarator ';' // alt { [following addObject:FOLLOW_type_in_variable166]; _type7 = [self type]; [following removeLastObject]; [_list_type addObject:[_type7 tree]]; [following addObject:FOLLOW_declarator_in_variable168]; _declarator8 = [self declarator];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -