1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#import "NewickParser.h"

@implementation NewickParser

-(void)parse:(NSString*) newickString {
    
    NSLog(@"newick is %@", newickString);
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"newickgrammar" ofType:@"txt"];  
    NSString *grammar = [NSString stringWithContentsOfFile:filePath encoding:NSASCIIStringEncoding error:nil];
    NSLog(@"grammar is %@", grammar);
    PKParser *parser = [[PKParserFactory factory] parserFromGrammar:grammar assembler:self];
    [parser parse:newickString];

}

-(void)didMatchTree:(PKAssembly*)a {
    NSLog(@"%@", a);
    
}

@end

output:

newick is (A:0.1,B:0.2,(C:0.3,D:0.4):0.5);
2011-11-03 13:31:47.019 iRangerCLI[11654:60b] grammar is @start = tree+;
tree = subtree ';' | branch ';';
subtree = leaf | internal;
leaf = name;
internal = '(' branchset ')' name;
branchset = branch | branchset ',' branch;
branch = subtree length;
name = Word | QuotedString;
length = ':' Number;
warning: Unable to restore previously selected frame.
kill
quit