8

Ho bisogno di analizzare il codice Objective-C statica, soprattutto AST, dopo aver guardato i possibili strumenti che ho scoperto che strumento Clang da LLVM può scaricare l'AST, così ho usato il terminale di provarlo con questo comando:Come estrarre AST dal codice Objective-C?

clang -cc1 -ast-dump ~/SomeTest.m 

ma sto ottenendo questo errore:

In file included from /Users/myusername/SomeTest.m:9: 
/Users/myusername/SomeTest.h:9:9: fatal error: 'UIKit/UIKit.h' file not found 
#import <UIKit/UIKit.h> 
     ^
typedef __int128_t __int128_t; 
typedef __uint128_t __uint128_t; 
typedef SEL *SEL; 
typedef id id; 
typedef Class *Class; 
struct __va_list_tag { 
    unsigned int gp_offset; 
    unsigned int fp_offset; 
    void *overflow_arg_area; 
    void *reg_save_area; 
}; 
typedef struct __va_list_tag __va_list_tag; 
typedef __va_list_tag __builtin_va_list[1]; 
@interface [email protected] 
@implementation just4testViewController 
- (void) dealloc (CompoundStmt 0x7f86b183b110 </Users/myusername/SomeTest.m:14:1, line:16:1>) 


- (void) didReceiveMemoryWarning (CompoundStmt 0x7f86b183b2a0 </Users/myusername/SomeTest.m:19:1, line:24:1>) 


- (void) viewDidUnload (CompoundStmt 0x7f86b183b430 </Users/myusername/SomeTest.m:37:1, line:41:1>) 


- (id) shouldAutorotateToInterfaceOrientation:(id)interfaceOrientation (CompoundStmt 0x7f86b183b648 </Users/myusername/SomeTest.m:44:1, line:47:1>) 


@end 
1 error generated. 

Qualsiasi idea del perché sto ottenendo questo? Non mi dispiace usare alcuno strumento per estrarre AST dal codice Objective-C finché è affidabile e fornire documentazione per l'output

+0

Ciao, sei riuscito a trovare un parser per estrarre AST dal codice sorgente dell'obiettivo-C? Grazie! – ramo

risposta

2

Il compilatore non trova il framework UIKit. Devi dirgli di usarlo:

clang -framework UIKit -cc1 -ast-dump ~/SomeTest.m 
+0

clang: avviso: argomento non utilizzato durante la compilazione: '-cc1' clang: avviso: argomento non utilizzato durante la compilazione: '-ast-dump' Nel file incluso da /Users/myusername/SomeTest.m:9: /Users/myusername/SomeTest.h:9:9: errore irreversibile: file UIKit/UIKit.h non trovato #import ^ 1 errore generato. –

0

Prova -Xclang -ast-dump invece di -cc1 -ast-dump. (Liberatoria standard: qualsiasi cosa utilizzando -Xclang o -cc1 sta utilizzando un'interfaccia instabile al compilatore.)

+0

ancora ottenendo esattamente gli stessi errori pubblicati nella domanda :( –

+0

Prendi un comando che lavora per compilare il file in questione, quindi aggiungi -Xclang -ast-dump a quel comando, altrimenti finirai con strani risultati ; l'AST per un file ObjC dipende dalle opzioni della riga di comando. – servn

+0

Non ho capito il tuo punto. Puoi riformularlo per me, per favore? –

0

OP dice Non mi importa di utilizzare qualsiasi strumento per estrarre AST dal codice Objective-C ...

Il nostro DMS Software Reengingineering Toolkit può farlo per Objective-C.

Per questa riga di comando al parser "domainparser" DMS-generated:

run \DMS\Domains\C\ObjectiveCv2\Tools\Parser\domainparser ++AST "C:\temp\test.m" 

questo file Objective C "test.m":

@implementation GTLClientLoginAuthorizationArgs 

@synthesize request = request_, 
    delegate = delegate_, 
    selector = sel_, 
    completionHandler = completionHandler_, 
    thread = thread_, 
    error = error_; 

+ (GTLClientLoginAuthorizationArgs *)argsWithRequest:(NSMutableURLRequest *)req 
        delegate:(id)delegate 
        selector:(SEL)sel 
       completionHandler:(id)completionHandler 
         thread:(NSThread *)thread { 
    GTLClientLoginAuthorizationArgs *obj; 
    obj = [[[GTLClientLoginAuthorizationArgs alloc] init] autorelease]; 
    obj.request = req; 
    obj.delegate = delegate; 
    obj.selector = sel; 
    obj.completionHandler = completionHandler; 
    obj.thread = thread; 
    return obj; 
} 

- (void)dealloc { 
    self.request = nil; 
    self.delegate = nil; 
    self.selector = NULL; 
    self.completionHandler = nil; 
    self.thread = nil; 
    self.error = nil; 
    [super dealloc]; 
} 
@end 

produce questa uscita con un AST:

Domain Parser for C~ObjectiveCv2 2.4.4 
Copyright (C) Semantic Designs 1996-2012; All Rights Reserved 
([email protected]~ObjectiveCv2=2#422f080^0 Line 1 Column 1 File C:/temp/test.m 
([email protected]~ObjectiveCv2=1048#422f140 Line 1 Column 1 File C:/temp/test.m 
    ([email protected]~ObjectiveCv2=1270#4228b40[`GTLClientLoginAuthorizationArgs'] Line 1 Column 17 File C:/temp/test.m)IDENTIFIER 
    ([email protected]~ObjectiveCv2=1046#4228b80 Line 3 Column 1 File C:/temp/test.m)super_class_option 
    ([email protected]~ObjectiveCv2=1061#4228bc0 Line 3 Column 1 File C:/temp/test.m)instance_variables 
    ([email protected]~ObjectiveCv2=1079#422f0a0 Line 3 Column 1 File C:/temp/test.m 
    ([email protected]~ObjectiveCv2=1079#422e8c0 Line 3 Column 1 File C:/temp/test.m 
    |([email protected]~ObjectiveCv2=1079#42290a0 Line 3 Column 1 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=1078#4228c00 Line 3 Column 1 File C:/temp/test.m)implementation_definition_list 
    | ([email protected]~ObjectiveCv2=1131#4229080 Line 3 Column 1 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=1134#4229060 Line 3 Column 13 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=1134#4228fc0 Line 3 Column 13 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=1134#4228f40 Line 3 Column 13 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1134#4228e80 Line 3 Column 13 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1134#4228de0 Line 3 Column 13 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1133#4228d00 Line 3 Column 13 File C:/temp/test.m 
    | | |([email protected]~ObjectiveCv2=1136#4228cc0 Line 3 Column 13 File C:/temp/test.m 
    | | | ([email protected]~ObjectiveCv2=1270#4228c40[`request'] Line 3 Column 13 File C:/temp/test.m)IDENTIFIER 
    | | | ([email protected]~ObjectiveCv2=1270#4228c80[`request_'] Line 3 Column 23 File C:/temp/test.m)IDENTIFIER 
    | | |)property_synthesize_item 
    | | )property_synthesize_list 
    | | ([email protected]~ObjectiveCv2=1136#4228dc0 Line 4 Column 13 File C:/temp/test.m 
    | | |([email protected]~ObjectiveCv2=1270#4228d80[`delegate'] Line 4 Column 13 File C:/temp/test.m)IDENTIFIER 
    | | |([email protected]~ObjectiveCv2=1270#4228da0[`delegate_'] Line 4 Column 24 File C:/temp/test.m)IDENTIFIER 
    | | )property_synthesize_item 
    | | )property_synthesize_list 
    | | ([email protected]~ObjectiveCv2=1136#4228e60 Line 5 Column 13 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#4228e20[`selector'] Line 5 Column 13 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1270#4228e40[`sel_'] Line 5 Column 24 File C:/temp/test.m)IDENTIFIER 
    | | )property_synthesize_item 
    | |)property_synthesize_list 
    | | ([email protected]~ObjectiveCv2=1136#4228f20 Line 6 Column 13 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#4228ea0[`completionHandler'] Line 6 Column 13 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1270#4228f00[`completionHandler_'] Line 6 Column 33 File C:/temp/test.m)IDENTIFIER 
    | |)property_synthesize_item 
    | |)property_synthesize_list 
    | |([email protected]~ObjectiveCv2=1136#4228fa0 Line 7 Column 13 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#4228f60[`thread'] Line 7 Column 13 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1270#4228f80[`thread_'] Line 7 Column 22 File C:/temp/test.m)IDENTIFIER 
    | |)property_synthesize_item 
    | )property_synthesize_list 
    | ([email protected]~ObjectiveCv2=1136#4229040 Line 8 Column 13 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=1270#4228fe0[`error'] Line 8 Column 13 File C:/temp/test.m)IDENTIFIER 
    | |([email protected]~ObjectiveCv2=1270#4229020[`error_'] Line 8 Column 21 File C:/temp/test.m)IDENTIFIER 
    | )property_synthesize_item 
    | )property_synthesize_list 
    |)property_implementation 
    |)implementation_definition_list 
    |([email protected]~ObjectiveCv2=1087#422ea00 Line 10 Column 1 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=1103#4229200 Line 10 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=647#42291c0 Line 10 Column 4 File C:/temp/test.m 
    | (AMBIGUITY<type_specifier=388>@C~ObjectiveCv2=1390#4228ca0{2} Line 10 Column 4 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=1144#4229100 Line 10 Column 4 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#42290c0^2#4228ca0:2#4229100:1[`GTLClientLoginAuthorizationArgs'] Line 10 Column 4 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1057#42290e0 Line 10 Column 36 File C:/temp/test.m)protocol_option 
    | |)type_specifier 
    | |([email protected]~ObjectiveCv2=1270#42290c0^2#4228ca0:2#4229100:1... [ALREADY PRINTED] ...) 
    | )AMBIGUITY 
    | ([email protected]~ObjectiveCv2=640#4229120 Line 10 Column 36 File C:/temp/test.m)ptr_operator 
    | )type_id 
    |)method_type 
    | ([email protected]~ObjectiveCv2=1095#4229940 Line 10 Column 38 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=1095#4229720 Line 10 Column 38 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=1095#42296a0 Line 10 Column 38 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=1095#4229580 Line 10 Column 38 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1094#42294a0 Line 10 Column 38 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1099#4229480 Line 10 Column 38 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#42291e0[`argsWithRequest'] Line 10 Column 38 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1103#4229440 Line 10 Column 54 File C:/temp/test.m 
    | | |([email protected]~ObjectiveCv2=647#42293c0 Line 10 Column 55 File C:/temp/test.m 
    | | | (AMBIGUITY<type_specifier=388>@C~ObjectiveCv2=1390#4229300{2} Line 10 Column 55 File C:/temp/test.m 
    | | | ([email protected]~ObjectiveCv2=1144#42292a0 Line 10 Column 55 File C:/temp/test.m 
    | | | ([email protected]~ObjectiveCv2=1270#4229220^2#4229300:2#42292a0:1[`NSMutableURLRequest'] Line 10 Column 55 File C:/temp/test.m)IDENTIFIER 
    | | | ([email protected]~ObjectiveCv2=1057#4229260 Line 10 Column 75 File C:/temp/test.m)protocol_option 
    | | | )type_specifier 
    | | | ([email protected]~ObjectiveCv2=1270#4229220^2#4229300:2#42292a0:1... [ALREADY PRINTED] ...) 
    | | |)AMBIGUITY 
    | | | ([email protected]~ObjectiveCv2=640#42293a0 Line 10 Column 75 File C:/temp/test.m)ptr_operator 
    | | |)type_id 
    | | )method_type 
    | | ([email protected]~ObjectiveCv2=1270#42293e0[`req'] Line 10 Column 77 File C:/temp/test.m)IDENTIFIER 
    | | )keyword_declarator 
    | |)keyword_selector 
    | | ([email protected]~ObjectiveCv2=1099#4229600 Line 11 Column 45 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#4229460[`delegate'] Line 11 Column 45 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1103#4228d40 Line 11 Column 54 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1143#42294e0 Line 11 Column 55 File C:/temp/test.m 
    | | |([email protected]~ObjectiveCv2=1057#4229500 Line 11 Column 57 File C:/temp/test.m)protocol_option 
    | | )type_specifier 
    | | )method_type 
    | | ([email protected]~ObjectiveCv2=1270#4228d20[`delegate'] Line 11 Column 58 File C:/temp/test.m)IDENTIFIER 
    | |)keyword_declarator 
    | |)keyword_selector 
    | |([email protected]~ObjectiveCv2=1099#4229680 Line 12 Column 45 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#42295a0[`selector'] Line 12 Column 45 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1103#4229280 Line 12 Column 54 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1141#42295c0 Line 12 Column 55 File C:/temp/test.m)simple_type_specifier 
    | |)method_type 
    | | ([email protected]~ObjectiveCv2=1270#4229560[`sel'] Line 12 Column 59 File C:/temp/test.m)IDENTIFIER 
    | |)keyword_declarator 
    | )keyword_selector 
    | ([email protected]~ObjectiveCv2=1099#4229700 Line 13 Column 36 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=1270#4229520[`completionHandler'] Line 13 Column 36 File C:/temp/test.m)IDENTIFIER 
    | |([email protected]~ObjectiveCv2=1103#42294c0 Line 13 Column 54 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1143#42296c0 Line 13 Column 55 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1057#42296e0 Line 13 Column 57 File C:/temp/test.m)protocol_option 
    | |)type_specifier 
    | |)method_type 
    | |([email protected]~ObjectiveCv2=1270#4228c60[`completionHandler'] Line 13 Column 58 File C:/temp/test.m)IDENTIFIER 
    | )keyword_declarator 
    | )keyword_selector 
    | ([email protected]~ObjectiveCv2=1099#4229920 Line 14 Column 47 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=1270#4229760[`thread'] Line 14 Column 47 File C:/temp/test.m)IDENTIFIER 
    | ([email protected]~ObjectiveCv2=1103#4229900 Line 14 Column 54 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=647#4229860 Line 14 Column 55 File C:/temp/test.m 
    | | (AMBIGUITY<type_specifier=388>@C~ObjectiveCv2=1390#4229320{2} Line 14 Column 55 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1144#42297e0 Line 14 Column 55 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#42297c0^2#4229320:2#42297e0:1[`NSThread'] Line 14 Column 55 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1057#4229740 Line 14 Column 64 File C:/temp/test.m)protocol_option 
    | | )type_specifier 
    | | ([email protected]~ObjectiveCv2=1270#42297c0^2#4229320:2#42297e0:1... [ALREADY PRINTED] ...) 
    | |)AMBIGUITY 
    | | ([email protected]~ObjectiveCv2=640#4229840 Line 14 Column 64 File C:/temp/test.m)ptr_operator 
    | |)type_id 
    | )method_type 
    | ([email protected]~ObjectiveCv2=1270#42298c0[`thread'] Line 14 Column 66 File C:/temp/test.m)IDENTIFIER 
    | )keyword_declarator 
    |)keyword_selector 
    | ([email protected]~ObjectiveCv2=1085#4229980 Line 14 Column 73 File C:/temp/test.m)declaration_star 
    | ([email protected]~ObjectiveCv2=403#422e920 Line 14 Column 73 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=405#422e3e0 {8} Line 15 Column 3 File C:/temp/test.m 
    | (AMBIGUITY<statement=332>@C~ObjectiveCv2=1390#4229780{2} Line 15 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=400#422e200 Line 15 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=209#4229e60 Line 15 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#42299e0^3#42297a0:1#4229a80:1#4229e60:1[`GTLClientLoginAuthorizationArgs'] Line 15 Column 3 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1270#4229ca0^2#4229d60:2#4229e60:2[`obj'] Line 15 Column 36 File C:/temp/test.m)IDENTIFIER 
    | |)multiplicative_expression 
    | |)expression_statement 
    | |([email protected]~ObjectiveCv2=515#422e1e0 Line 15 Column 3 File C:/temp/test.m 
    | | (AMBIGUITY<type_specifier=388>@C~ObjectiveCv2=1390#42297a0{2} Line 15 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#42299e0^3#42297a0:1#4229a80:1#4229e60:1... [ALREADY PRINTED] ...) 
    | | ([email protected]~ObjectiveCv2=1144#4229a80 Line 15 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#42299e0^3#42297a0:1#4229a80:1#4229e60:1... [ALREADY PRINTED] ...) 
    | | ([email protected]~ObjectiveCv2=1057#4229a20 Line 15 Column 35 File C:/temp/test.m)protocol_option 
    | | )type_specifier 
    | |)AMBIGUITY 
    | | ([email protected]~ObjectiveCv2=624#4229d60 Line 15 Column 35 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=640#4229cc0 Line 15 Column 35 File C:/temp/test.m)ptr_operator 
    | | ([email protected]~ObjectiveCv2=1270#4229ca0^2#4229d60:2#4229e60:2... [ALREADY PRINTED] ...) 
    | |)declarator 
    | |)simple_declaration 
    | )AMBIGUITY 
    | ([email protected]~ObjectiveCv2=400#422e3c0 Line 16 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=356#422e360 Line 16 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#422e1c0[`obj'] Line 16 Column 3 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1158#422e340 Line 16 Column 9 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1158#422e320 Line 16 Column 10 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1158#422e2e0 Line 16 Column 11 File C:/temp/test.m 
    | | |([email protected]~ObjectiveCv2=1270#422e220[`GTLClientLoginAuthorizationArgs'] Line 16 Column 12 File C:/temp/test.m)IDENTIFIER 
    | | |([email protected]~ObjectiveCv2=1270#422e2a0[`alloc'] Line 16 Column 44 File C:/temp/test.m)IDENTIFIER 
    | | )primary_expression 
    | | ([email protected]~ObjectiveCv2=1270#422e2c0[`init'] Line 16 Column 51 File C:/temp/test.m)IDENTIFIER 
    | | )primary_expression 
    | | ([email protected]~ObjectiveCv2=1270#422e300[`autorelease'] Line 16 Column 57 File C:/temp/test.m)IDENTIFIER 
    | |)primary_expression 
    | |)assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422e540 Line 17 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=356#422e500 Line 17 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=130#422e480 Line 17 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#422e380[`obj'] Line 17 Column 3 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1270#422e440[`request'] Line 17 Column 7 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | | ([email protected]~ObjectiveCv2=1270#422e4a0[`req'] Line 17 Column 17 File C:/temp/test.m)IDENTIFIER 
    | |)assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422e680 Line 18 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=356#422e640 Line 18 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=130#422e600 Line 18 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#422e520[`obj'] Line 18 Column 3 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1270#422e5c0[`delegate'] Line 18 Column 7 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | | ([email protected]~ObjectiveCv2=1270#422e620[`delegate'] Line 18 Column 18 File C:/temp/test.m)IDENTIFIER 
    | |)assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422e780 Line 19 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=356#422e720 Line 19 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=130#422e740 Line 19 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#422e660[`obj'] Line 19 Column 3 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1270#422e560[`selector'] Line 19 Column 7 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | | ([email protected]~ObjectiveCv2=1270#422e760[`sel'] Line 19 Column 18 File C:/temp/test.m)IDENTIFIER 
    | |)assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422e6e0 Line 20 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=356#422e800 Line 20 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=130#422e840 Line 20 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#422e580[`obj'] Line 20 Column 3 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1270#422e6a0[`completionHandler'] Line 20 Column 7 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | | ([email protected]~ObjectiveCv2=1270#422e860[`completionHandler'] Line 20 Column 27 File C:/temp/test.m)IDENTIFIER 
    | |)assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422e900 Line 21 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=356#422e960 Line 21 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=130#422e8a0 Line 21 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1270#422e820[`obj'] Line 21 Column 3 File C:/temp/test.m)IDENTIFIER 
    | | ([email protected]~ObjectiveCv2=1270#422e7a0[`thread'] Line 21 Column 7 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | | ([email protected]~ObjectiveCv2=1270#422e940[`thread'] Line 21 Column 16 File C:/temp/test.m)IDENTIFIER 
    | |)assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=487#422e9c0 Line 22 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=1270#422e880[`obj'] Line 22 Column 10 File C:/temp/test.m)IDENTIFIER 
    | )jump_statement 
    | )statement_seq 
    |)compound_statement 
    |)class_method_definition 
    )implementation_definition_list 
    ([email protected]~ObjectiveCv2=1088#422f280 Line 25 Column 1 File C:/temp/test.m 
    |(AMBIGUITY<method_result_option=527>@C~ObjectiveCv2=1390#4229f40{2} Line 25 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=1101#422ea60 Line 25 Column 3 File C:/temp/test.m)method_result_option 
    | ([email protected]~ObjectiveCv2=1103#422e7c0 Line 25 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=545#422e9e0 Line 25 Column 4 File C:/temp/test.m)simple_type_specifier 
    |)method_type 
    |)AMBIGUITY 
    |([email protected]~ObjectiveCv2=1270#422e8e0[`dealloc'] Line 25 Column 9 File C:/temp/test.m)IDENTIFIER 
    |([email protected]~ObjectiveCv2=1085#422e7e0 Line 25 Column 17 File C:/temp/test.m)declaration_star 
    |([email protected]~ObjectiveCv2=403#422efa0 Line 25 Column 17 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=405#422ecc0 {7} Line 26 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=400#422eb40 Line 26 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=356#422eb20 Line 26 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=130#422eae0 Line 26 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1155#422ea80 Line 26 Column 3 File C:/temp/test.m)primary_expression 
    | | ([email protected]~ObjectiveCv2=1270#422eaa0[`request'] Line 26 Column 8 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | |([email protected]~ObjectiveCv2=1157#422eb00 Line 26 Column 18 File C:/temp/test.m)primary_expression 
    | )assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422eca0 Line 27 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=356#422ec40 Line 27 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=130#422ec00 Line 27 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1155#422eba0 Line 27 Column 3 File C:/temp/test.m)primary_expression 
    | | ([email protected]~ObjectiveCv2=1270#422ebc0[`delegate'] Line 27 Column 8 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | |([email protected]~ObjectiveCv2=1157#422ec20 Line 27 Column 19 File C:/temp/test.m)primary_expression 
    | )assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422ee20 Line 28 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=356#422ee00 Line 28 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=130#422ed60 Line 28 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1155#422ece0 Line 28 Column 3 File C:/temp/test.m)primary_expression 
    | | ([email protected]~ObjectiveCv2=1270#422ed40[`selector'] Line 28 Column 8 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | |([email protected]~ObjectiveCv2=1270#422edc0[`NULL'] Line 28 Column 19 File C:/temp/test.m)IDENTIFIER 
    | )assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422ef40 Line 29 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=356#422ef20 Line 29 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=130#422eee0 Line 29 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1155#422ee60 Line 29 Column 3 File C:/temp/test.m)primary_expression 
    | | ([email protected]~ObjectiveCv2=1270#422eec0[`completionHandler'] Line 29 Column 8 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | |([email protected]~ObjectiveCv2=1157#422ef00 Line 29 Column 28 File C:/temp/test.m)primary_expression 
    | )assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422ee80 Line 30 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=356#422efe0 Line 30 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=130#422f020 Line 30 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1155#422ee40 Line 30 Column 3 File C:/temp/test.m)primary_expression 
    | | ([email protected]~ObjectiveCv2=1270#422f000[`thread'] Line 30 Column 8 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | |([email protected]~ObjectiveCv2=1157#422efc0 Line 30 Column 17 File C:/temp/test.m)primary_expression 
    | )assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422ef80 Line 31 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=356#422f0c0 Line 31 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=130#422f100 Line 31 Column 3 File C:/temp/test.m 
    | | ([email protected]~ObjectiveCv2=1155#422ef60 Line 31 Column 3 File C:/temp/test.m)primary_expression 
    | | ([email protected]~ObjectiveCv2=1270#422f060[`error'] Line 31 Column 8 File C:/temp/test.m)IDENTIFIER 
    | |)postfix_expression 
    | |([email protected]~ObjectiveCv2=1157#422f120 Line 31 Column 16 File C:/temp/test.m)primary_expression 
    | )assignment_expression 
    | )expression_statement 
    | ([email protected]~ObjectiveCv2=400#422f1a0 Line 32 Column 3 File C:/temp/test.m 
    | ([email protected]~ObjectiveCv2=1158#422f180 Line 32 Column 3 File C:/temp/test.m 
    | |([email protected]~ObjectiveCv2=1156#422f1e0 Line 32 Column 4 File C:/temp/test.m)primary_expression 
    | |([email protected]~ObjectiveCv2=1270#422f040[`dealloc'] Line 32 Column 10 File C:/temp/test.m)IDENTIFIER 
    | )primary_expression 
    | )expression_statement 
    |)statement_seq 
    |)compound_statement 
    )instance_method_definition 
)implementation_definition_list 
)class_implementation 
)translation_unit 
Exiting with final status 0 

Poiché la forma dell'albero è isomorfa alla grammatica che usiamo, la grammatica i s la documentazione. Vedere una risposta SO precedente per how we do this and yet produce an AST.

Questo è un frammento di codice preso da una libreria popolare; è solo un frammento perché altrimenti l'albero sarebbe enorme. Ho anche imbrogliato un pochino, tralasciando le #import, che mi permettono di eseguire un parser facilmente configurabile. DMS analizzerà i file contenenti #include e manterrà la direttiva o manterrà il testo di inclusione, a seconda di come è configurato il parser.

Questo è per ObjectiveC, non ObjectiveC++. Ci stiamo lavorando: -}

DMS offre un supporto aggiuntivo per l'analisi del programma che opera sugli AST che produce.

+0

Grazie, downvoter Questa risposta fornisce una risposta specifica alla richiesta dell'OP e mostra esattamente come fare ciò che vuole. –