jevitha wrote:

Hi all,

   Im facing this problem of converting parser grammar to tree grammar.
I have some rules which incrementally build ASTs  like the following example:

postfixExpression : (primary->primary)
                                     ( '(' args=expressionList ')' -> ^(CALL $postfixExpression $args)
                                   | '[' ie=_expression_ ']'  -> ^(INDEX $postfixExpression $ie)
                                   | '.' p=primary -> ^(FIELDACCESS $postfixExpression $p) )*;
 
When i convert this to tree grammar by removing the parser grammar leaving alone the rewrite rules, im unable to use the $postfixExpression in the tree grammar ... What is the equivaent i should use to denote the node already built for the rule?
                                 

Thanks in advance,
When you do things like that in the parser, the equivalent tree grammar will be quite different in structure as $postfixExpression does not make much sense (you have already built the tree. I suspect, that looking at your grammar here you have followed the normative spec for  a language too closely and so are finding it awkward to build the tree in a natural way. What language are you trying to parse?

That said though, all you need do is the following:

1) Identify all the nodes that can start the rewritten tree node: CALL, INDEX, FIELDACCESS, primary
2) Construct the recursive tree rule that reflects this.

You will have something like this:

pE  : ^(CALL pE args)
    | ^(INDEX pE args)
    | ^(FIELDACCESS pE args)
    | primary
    ;


I think though that you probably need to rework that grammar rule a bit though. It might look more natural using the ^ operators or you might need '.' postFixExpression. Sometimes the way you have this set up is the way to do it; without the whole grammar it is difficult to tell :-)

Jim

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "il-antlr-interest" group.
To post to this group, send email to il-antlr-interest@googlegroups.com
To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to