[antlr-interest] Objective-C target problem no createTree:
Rod Schmidt
rod at infinitenil.com
Fri Aug 5 20:30:40 PDT 2011
I'm using the latest antlr-3.4.jar to generate an ObjC target. The target is generated but I'm not sure it's correct. When I build I get the following warning (among others):
file://localhost/Users/rod/Desktop/Merlin/objc-impl/Merlin/Merlin/MerlinParser.m: warning: Semantic Issue: Instance method '-createTree:' not found (return type defaults to 'id')
I'm on Mac OS X Lion and using XCode 4.1. I've also downloaded the source to the Objective-C runtime, etc., and there is not a createTree: method. There are methods such as createTree:text:, etc. but no just createTree:
So at this point, I wondering. Is there a bug in the 3.4 (i.e. the templates are not correct), or am I just not setup right? Or is there something wrong with my grammar file? Here it is:
grammar Merlin;
options {
language = ObjC;
output = AST;
// ANTLR can handle literally any tree node type.
// For convenience, specify the Java type
ASTLabelType = ANTLRCommonTree; // type of $stat.tree ref etc.
}
@memVars {
// Map variable name to Integer object holding value
NSMutableDictionary *memory;
}
@init {
memory = [[NSMutableDictionary alloc] init];
}
/** Match a series of stat rules and, for each one, print out the
* tree stat returns, $stat.tree. toStringTree() prints the tree
* out in form: (root child1 .. childN). ANTLR's default tree
* construction mechanism will build a list (flat tree) of the stat
* result trees. This tree will be the input to the tree parser.
*/
prog : ( stat { NSLog(@"\%@", $stat.tree == nil ? @"null" : [$stat.tree toStringTree]); } )+ ;
stat : expr NEWLINE -> expr
| ID '=' expr NEWLINE -> ^('=' ID expr)
| NEWLINE ->
;
expr : multExpr (('+'^ | '-'^) multExpr)*
;
multExpr: atom ('*'^ atom)*
;
atom : INT
| ID
| '('! expr ')'!
;
ID : ('a'..'z' | 'A'..'Z')+ ;
INT : '0'..'9'+ ;
NEWLINE : '\r'? '\n' ;
WS : (' '|'\t')+ { [self skip]; } ;
If I take out the rewrite rules (i.e. all the AST generate stuff) and just use Objective-C code actions it works fine (lots of warnings though in the generated code).
If anybody could shed some light on this, I would very much appreciate it. Otherwise I'll have to try a C target or another tool besides ANTLR, which I'd rather not do since ANTLR seems like the best tool out there.
Thanks,
Rod Schmidt
www.infinitenil.com
More information about the antlr-interest
mailing list