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
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.