[antlr-interest] Parse assignments and method calls
Damien Urruty
lepilache at hotmail.com
Tue Mar 23 06:56:54 PDT 2010
Hello
I have been working on the Java grammar, and in my opinion, there is a strange thing with the expressions. Actually the parser is able to detect an expression like :
1+2 = 3+4;
or
a = b+6 = c;
And these are not legal statements in Java (it displays "The left-hand side of an assignment must be a variable"). This is detected later by the semantical analysis I guess, but I would like to modify the grammar to verify syntactically left hand-side variables. Here are my rules :
statement : block | // others statements ... | affectation ';' | methodCall ';' | instanciation ';' ; affectation : affectMember+ methodAccess | affectMember+ 'new' identST arguments | affectMember+ expression ; affectMember : varAccess assignmentOperator ; varAccess : identST ('[' argument ']')* | members '.' identST ('[' argument ']')* | '(' varAccess ')' ; members : 'this' ('.' member)* | 'super' ('.' member)* | instanciation ('.' member)* | member ('.' member)* | parMember ('.' member)* ;
parMember : '(' castMember? members ')' ;
castMember : '(' primitiveType ')' | '(' type ')' ;
member : identST arguments ('[' argument ']')* | identST ('[' argument ']')* ;
methodAccess : methodCall | '(' castMember? methodAccess ')' ;
methodCall : 'this' '.' (member '.')* methodMinimum | 'super' '.' (member '.')* methodMinimum | instanciation '.' (member '.')* methodMinimum | (member '.')* methodMinimum | members '.' methodMinimum ;
methodMinimum : identST arguments ;
instanciation : 'new' creator ;
expression : conditionalExpression ;
//.........
The code is not organized at all, but works, except when there is a castMember, as in :
((int)obj.method()).method2();
I think I have a problem with the parenthesis and their priorities. If anyone could help, I would appreciate it. I can't find things like these, nowhere. Parsers usually parse expression like in the Java.g grammar, but I need to parse this way.
Thanks in advance.Dam.
_________________________________________________________________
Hotmail et MSN dans la poche? HOTMAIL et MSN sont dispo gratuitement sur votre téléphone!
http://www.messengersurvotremobile.com/?d=Hotmail
More information about the antlr-interest
mailing list