📄 simplecparser.m
字号:
SimpleCParser_type_return * _retval = [[SimpleCParser_type_return alloc] init]; [_retval setStart:[input LT:1]]; id root_0 = nil; // token labels ANTLRToken * _set20 = nil; // token+rule list labels // rule labels // rule list labels // rule refs in alts with rewrites id _set20_tree = nil; @try { // SimpleC.g:44:5: ( ('int'|'char'|'void'|ID)) // ruleBlockSingleAlt // SimpleC.g:44:9: ('int'|'char'|'void'|ID) // alt { root_0 = (id)[treeAdaptor emptyTree]; _set20 = (ANTLRToken *)[input LT:1]; if ([input LA:1]==SimpleCParser_ID||([input LA:1]>=SimpleCParser_INT_TYPE && [input LA:1]<=SimpleCParser_VOID)) { [treeAdaptor addChild:[treeAdaptor newTreeWithToken:_set20] toTree:root_0]; [input consume]; errorRecovery = NO; } else { ANTLRMismatchedSetException *mse = [ANTLRMismatchedSetException exceptionWithSet:nil stream:input]; [self recoverFromMismatchedSet:input exception:mse follow:FOLLOW_set_in_type312]; @throw mse; } } } @catch (ANTLRRecognitionException *re) { [self reportError:re]; [self recover:input exception:re]; } @finally { // token labels [_set20 release]; // token+rule list labels // rule labels // 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 type// $ANTLR start block// SimpleC.g:50:1: block : lc= '{' ( variable )* ( stat )* '}' -> ^( BLOCK[$lc,\"BLOCK\"] ( variable )* ( stat )* ) ;- (SimpleCParser_block_return *) block{ SimpleCParser_block_return * _retval = [[SimpleCParser_block_return alloc] init]; [_retval setStart:[input LT:1]]; id root_0 = nil; // token labels ANTLRToken * _lc = nil; ANTLRToken * _char_literal23 = nil; // token+rule list labels // rule labels SimpleCParser_variable_return * _variable21 = nil; SimpleCParser_stat_return * _stat22 = nil; // rule list labels // rule refs in alts with rewrites NSMutableArray *_list_stat = [[NSMutableArray alloc] init]; NSMutableArray *_list_variable = [[NSMutableArray alloc] init]; NSMutableArray *_list_26 = [[NSMutableArray alloc] init]; NSMutableArray *_list_25 = [[NSMutableArray alloc] init]; id _lc_tree = nil; id _char_literal23_tree = nil; @try { // SimpleC.g:51:9: (lc= '{' ( variable )* ( stat )* '}' -> ^( BLOCK[$lc,\"BLOCK\"] ( variable )* ( stat )* ) ) // ruleBlockSingleAlt // SimpleC.g:51:9: lc= '{' ( variable )* ( stat )* '}' // alt { _lc=(ANTLRToken *)[input LT:1]; [_lc retain]; [self match:input tokenType:25 follow:FOLLOW_25_in_block376]; [_list_25 addObject:_lc]; do { int alt5=2; { int LA5_0 = [input LA:1]; if ( LA5_0==SimpleCParser_ID ) { { int LA5_2 = [input LA:2]; if ( LA5_2==SimpleCParser_ID ) { alt5 = 1; } } } else if ( (LA5_0>=SimpleCParser_INT_TYPE && LA5_0<=SimpleCParser_VOID) ) { alt5 = 1; } } switch (alt5) { case 1 : // SimpleC.g:52:13: variable // alt { [following addObject:FOLLOW_variable_in_block390]; _variable21 = [self variable]; [following removeLastObject]; [_list_variable addObject:[_variable21 tree]]; } break; default : goto loop5; } } while (YES); loop5: ; do { int alt6=2; { int LA6_0 = [input LA:1]; if ( LA6_0==SimpleCParser_ID||(LA6_0>=SimpleCParser_INT && LA6_0<=SimpleCParser_FOR)||(LA6_0>=21 && LA6_0<=22)||LA6_0==25 ) { alt6 = 1; } } switch (alt6) { case 1 : // SimpleC.g:53:13: stat // alt { [following addObject:FOLLOW_stat_in_block405]; _stat22 = [self stat]; [following removeLastObject]; [_list_stat addObject:[_stat22 tree]]; } break; default : goto loop6; } } while (YES); loop6: ; _char_literal23=(ANTLRToken *)[input LT:1]; [_char_literal23 retain]; [self match:input tokenType:26 follow:FOLLOW_26_in_block416]; [_list_26 addObject:_char_literal23]; // AST REWRITE int i_0 = 0; [_retval setTree:root_0]; root_0 = (id)[treeAdaptor emptyTree]; // 55:9: -> ^( BLOCK[$lc,\"BLOCK\"] ( variable )* ( stat )* ) { // SimpleC.g:55:12: ^( BLOCK[$lc,\"BLOCK\"] ( variable )* ( stat )* ) { id root_1 = (id)[treeAdaptor emptyTree]; root_1 = (id)[treeAdaptor makeNode:[treeAdaptor newTreeWithTokenType:SimpleCParser_BLOCK text:[_lc text]] parentOf:root_1]; // SimpleC.g:55:33: ( variable )* { int n_1 = _list_variable == nil ? 0 : [_list_variable count]; int i_1; for (i_1=0; i_1<n_1; i_1++) { [treeAdaptor addChild:(id<ANTLRTree>)[_list_variable objectAtIndex:i_1] toTree:root_1]; } } // SimpleC.g:55:43: ( stat )* { int n_1 = _list_stat == nil ? 0 : [_list_stat count]; int i_1; for (i_1=0; i_1<n_1; i_1++) { [treeAdaptor addChild:(id<ANTLRTree>)[_list_stat objectAtIndex:i_1] toTree:root_1]; } } [treeAdaptor addChild:root_1 toTree:root_0]; } } } } @catch (ANTLRRecognitionException *re) { [self reportError:re]; [self recover:input exception:re]; } @finally { // token labels [_lc release]; [_char_literal23 release]; // token+rule list labels // rule labels [_variable21 release]; [_stat22 release]; // rule refs in alts with rewrites [_list_stat release]; [_list_variable release]; [_list_26 release]; [_list_25 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 block// $ANTLR start stat// SimpleC.g:58:1: stat : ( forStat | expr ';'! | block | assignStat ';'! | ';'! );- (SimpleCParser_stat_return *) stat{ SimpleCParser_stat_return * _retval = [[SimpleCParser_stat_return alloc] init]; [_retval setStart:[input LT:1]]; id root_0 = nil; // token labels ANTLRToken * _char_literal26 = nil; ANTLRToken * _char_literal29 = nil; ANTLRToken * _char_literal30 = nil; // token+rule list labels // rule labels SimpleCParser_forStat_return * _forStat24 = nil; SimpleCParser_expr_return * _expr25 = nil; SimpleCParser_block_return * _block27 = nil; SimpleCParser_assignStat_return * _assignStat28 = nil; // rule list labels // rule refs in alts with rewrites id _char_literal26_tree = nil; id _char_literal29_tree = nil; id _char_literal30_tree = nil; @try { // SimpleC.g:58:7: ( forStat | expr ';'! | block | assignStat ';'! | ';'! ) //ruleblock int alt7=5; switch ([input LA:1]) { case SimpleCParser_FOR: alt7 = 1; break; case SimpleCParser_ID: { int LA7_2 = [input LA:2]; if ( LA7_2==SimpleCParser_EQ ) { alt7 = 4; } else if ( (LA7_2>=SimpleCParser_EQEQ && LA7_2<=SimpleCParser_PLUS)||LA7_2==21 ) { alt7 = 2; } else { ANTLRNoViableAltException *nvae = [ANTLRNoViableAltException exceptionWithDecision:7 state:2 stream:input]; @throw nvae; } } break; case SimpleCParser_INT: case 22: alt7 = 2; break; case 25: alt7 = 3; break; case 21: alt7 = 5; break; default: { ANTLRNoViableAltException *nvae = [ANTLRNoViableAltException exceptionWithDecision:7 state:0 stream:input]; @throw nvae; }} switch (alt7) { case 1 : // SimpleC.g:58:7: forStat // alt { root_0 = (id)[treeAdaptor emptyTree]; [following addObject:FOLLOW_forStat_in_stat449]; _forStat24 = [self forStat]; [following removeLastObject]; [treeAdaptor addChild:[_forStat24 tree] toTree:root_0]; } break; case 2 : // SimpleC.g:59:7: expr ';'! // alt { root_0 = (id)[treeAdaptor emptyTree]; [following addObject:FOLLOW_expr_in_stat457]; _expr25 = [self expr]; [following removeLastObject]; [treeAdaptor addChild:[_expr25 tree] toTree:root_0]; _char_literal26=(ANTLRToken *)[input LT:1]; [_char_literal26 retain]; [self match:input tokenType:21 follow:FOLLOW_21_in_stat459]; } break; case 3 : // SimpleC.g:60:7: block // alt { root_0 = (id)[treeAdaptor emptyTree]; [following addObject:FOLLOW_block_in_stat468]; _block27 = [self block]; [following removeLastObject]; [treeAdaptor addChild:[_block27 tree] toTree:root_0]; } break; case 4 : // SimpleC.g:61:7: assignStat ';'! // alt { root_0 = (id)[treeAdaptor emptyTree]; [following addObject:FOLLOW_assignStat_in_stat476]; _assignStat28 = [self assignStat]; [following removeLastObject]; [treeAdaptor addChild:[_assignStat28 tree] toTree:root_0]; _char_literal29=(ANTLRToken *)[input LT:1]; [_char_literal29 retain]; [self match:input tokenType:21 follow:FOLLOW_21_in_stat478]; } break; case 5 : // SimpleC.g:62:7: ';'! // alt { root_0 = (id)[treeAdaptor emptyTree]; _char_literal30=(ANTLRToken *)[input LT:1]; [_char_literal30 retain]; [self match:input tokenType:21 follow:FOLLOW_21_in_stat487]; } break; } } @catch (ANTLRRecognitionException *re) { [self reportError:re]; [self recover:input exception:re]; } @finally { // token labels [_char_literal26 release]; [_char_literal29 release]; [_char_literal30 release]; // token+rule list labels
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -