Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need help on using ANTLR3 library for Objective-C #15

Open
madhavnv opened this issue May 28, 2013 · 0 comments
Open

Need help on using ANTLR3 library for Objective-C #15

madhavnv opened this issue May 28, 2013 · 0 comments

Comments

@madhavnv
Copy link

This is Madhav from Bangalore, India. I am using ANTLR3-ObjC2.0-Runtime
library from the URL(https://github.com/muggins/ANTLR3-ObjC2.0-Runtime) for generating code in Objective-C. I needed your help to debug the problem i am facing which is explained below.

My input would be some thing like this:-

abc1 = new abc(100) // abc1 is an object of class abc...something like this
xyz22 = new xyz(30)
abc1
xyz22 and so on...

For this the grammar file looks like:-
/*****************************************************************************************************/
options{
output=AST;
language=ObjC;
ASTLabelType=CommonTree;
}

@Header {
}

@lexer::header {
}

@members {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
}

@memVars {
NSMutableDictionary *dict;
}

@init {
dict = [[NSMutableDictionary alloc] init];
}

prog: stat+;

stat : ID {
NSString *v = [dict objectForKey:$ID.text];
NSLog(@"id=%@\n",v);
} |

     ID '=' NEW WORD LPARN NUMBER RPARN NEWLINE
     {
            [dict setObject:$WORD.text forKey:$ID.text];
            NSLog(@"new= \%@\n",$NEW.text);
            NSLog(@"word= \%@\n",$WORD.text);
     }
| NEWLINE
;

NEW : ('n''e''w');
NUMBER: '0'..'9'+;
WORD: ('a'..'z'| 'A'..'Z')+;
ID: ('a'..'z'| 'A'..'Z')+('0'..'9')+;
LPARN : '(';
RPARN : ')';
COMMA : ',';
NEWLINE:'\r'? '\n' ;
WS : (' ' | '\t') {$channel=HIDDEN;} ;

/*****************************************************************************************************/
For the above mentioned grammar and input file, build/compilation everything is success, but while i run i get something like:-

missing NEW at 'new' (even though there is new in the input)
and
extraneous input 'abc' expecting LPARN

So i needed help in debugging above statements and in the NSLog print iam getting new=(null) but i expect new=new and word=abc.

But strange aspect is, in the above grammar file if i re-order the lexer tokens by moving the NUMBER:'0'..'9'+ token to after the WORD token, everything works perfectly. This is really strange.

Please point the mistakes i am doing or is this a bug in the antlr3/library. Awaiting your response. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant