Hi all,
sorry for the porevious mail, webmail messed it up ...
I am desperately trying to create a tree for method calls but am struggling
with recursion in the tree generation. My language allows for statements like
this:
print().foo().test().me()
Where print() is a function returning an object. Then subsequently
methods are called.
$x.this().is().it()
Where $x is a variable holding an object.
Previous two statements should be transformed to trees like this:
^(^(METHOD ^(METHOD ^(FUN print) foo) test) me)
^(^(METHOD ^(METHOD ^(VAR x) this) is) it)
So I started with a grammar, but got stuck here:
grammar Test;
options {
language = Java;
output = AST;
ASTLabelType=CommonTree;
}
tokens {
VAR;
FUN;
METHOD;
}
program
: statement* EOF!
;
statement
: token
(
'.' IDENT '(' ')' -> ^(METHOD token IDENT)
)*
;
token
: function
| variable
;
function
: IDENT '(' ')' -> ^(FUN IDENT)
;
variable
: '$' IDENT -> ^(VAR IDENT)
;
fragment LETTER : ('a'..'z' | 'A'..'Z');
fragment DIGIT : '0'..'9';
fragment LINEBREAK : '\r'? '\n';
IDENT : LETTER (LETTER | DIGIT | '_')*;
WHITESPACES : (' ' | '\t' | '\f' | LINEBREAK)+ { $channel = HIDDEN; };
Running this grammar on the example input results in following tree:
(METHOD (FUN print) foo) (METHOD (VAR x) this)
I see that I need to change the * from "statement" to ? somehow, but how can I
call statement recursively?
Thanks
Christian
___________________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de
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.