Thanks for reply. the funny thing is after I sent the email, I realized what I was missing, but I came across some new rules I was sure how to translate.<br><br>such as:<br>
<br>propOrIdent[LinkedListTree identPrimary, Token startToken]<br> : <br> { retval.start = startToken; }<br> d=DOT propId=qualifiedIdent<br> -> ^(PROPERTY_OR_IDENTIFIER[$d] {$identPrimary} $propId)<br>
;<br><br>and<br><br>xmlLiteral<br> @init {<br> LinkedListTree xml = null;<br> }<br> :<br> LT<br> { xml=parseXMLLiteral(); }<br> -> ^(XML_LITERAL {xml})<br> ;<br>I haven't found any leads on how to translate the "action
inserted" {} nodes. I'm not sure what to call them. Looking at the
resulting parser code comments for the xmlLiteral rule it doesn't look
like ANTLR sees the special nodes. <br>
<br> root_0 = (LinkedListTree)adaptor.nil();<br> // 1121:3: -> ^( XML_LITERAL )<br> {<br> // AS3.g3:1121:6: ^( XML_LITERAL )<br> {<br> LinkedListTree root_1 = (LinkedListTree)adaptor.nil();<br>
root_1 = (LinkedListTree)adaptor<div id="1es9" class="ArwC7c ckChnd">.becomeRoot(adaptor.create(XML_LITERAL, "XML_LITERAL"), root_1);<br><br> adaptor.addChild(root_1, xml);<br><br>
adaptor.addChild(root_0, root_1);<br>
}<br><br> }<br><br>So how would I go about translating the rules in a tree grammar?<br><br>xmlLiteral : ^(XML_LITERAL WHATGOESHERE?) ;<br><br>Thanks,<br><font color="#888888">Don</font></div><br>
<br><div class="gmail_quote">On Wed, May 7, 2008 at 3:25 PM, David Holroyd <<a href="mailto:dave@badgers-in-foil.co.uk">dave@badgers-in-foil.co.uk</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello,<br>
<div class="Ih2E3d"><br>
On Mon, Apr 28, 2008 at 02:28:50PM -0700, Don-Duong Quach wrote:<br>
> I'm trying to build an Actionscript 3 to haxe <a href="http://haxe.org" target="_blank">http://haxe.org</a> translator,<br>
> and I've been taking a closer look at metaas to see if I could reuse the AS3<br>
> and island grammars as the basis for it. I thought I might as well try to<br>
> build something robust with ANTLR than hand code a translator, but I've into<br>
> a couple snags with building the project.<br>
><br>
> I was hoping maybe David Holroyd or someone would give me some pointers on<br>
> how to alter the grammar into a tree grammar for rewriting as I'm still<br>
> learning how to use ANTLR.<br>
><br>
> Just as a side note, I setup Netbeans with a Maven plugin to build the<br>
> metaas project but ran into some dependency issues with the maven-archiver,<br>
> plexus-archiver and plexus-components. I stopped trying to resolve them at<br>
> that point because I wanted to focus on the task of the tree grammar.<br>
<br>
</div>I'm afraid I have no experience of Netbeans/Maven integration, so I<br>
can't really help out there. Were you able to get things to work with<br>
the plain-old Maven command line interface?<br>
<div class="Ih2E3d"><br>
<br>
> I've been reading through the docs and examples, but I don't know I would<br>
> translate the certain parser rewrites into a tree grammar rule. For<br>
> example:<br>
><br>
> classDefinition[LinkedListTree annos, LinkedListTree mods]<br>
> : CLASS ident<br>
> classExtendsClause<br>
> implementsClause<br>
> typeBlock<br>
> -> ^(CLASS_DEF {$annos} {$mods} ident classExtendsClause<br>
> implementsClause typeBlock)<br>
> ;<br>
><br>
> In The Definitive Guide to ANTLR, Terrence Parr says to copy the rules over<br>
> like so:<br>
><br>
> classDefinition[LinkedListTree annos, LinkedListTree mods]<br>
> : ^(CLASS_DEF {$annos} {$mods} ident classExtendsClause<br>
> implementsClause typeBlock)<br>
> ;<br>
<br>
</div>Note that you would not need to pass the [annos,mods] arguments to this<br>
rule in the tree parser. The main parser will already have inserted<br>
these into the resulting tree.<br>
<div class="Ih2E3d"><br>
<br>
> But what would I do about the {$annos} and {$mods} elements in the rule? I<br>
> figure the parameter clause should be removed, but what should I use to<br>
> reference the annos and mods elements in the AST?<br>
<br>
</div>You need to consider what structure the tree parser will actually<br>
observe.<br>
<br>
In the above example, {$annos} and {$mods} are references (passed as<br>
arguments to the rule) to some subtrees. In your tree parser, you would<br>
need to address the concrete tree structure that will be produced that<br>
these points.<br>
<br>
If you look at the rules that may invoke the classDefinition rule,<br>
you'll see that $annos and $mods are the subtrees produced by the rules<br>
'annotations' and 'modifiers' respectively.<br>
<br>
Therefore, you could write the rule in the tree parser like...<br>
<br>
<br>
classDefinition<br>
: ^(CLASS_DEF annotations modifiers ident classExtendsClause implementsClause typeBlock)<br>
<br>
<br>
does that make sense?<br>
<br>
<br>
ta,<br>
dave<br>
<font color="#888888"><br>
--<br>
<a href="http://david.holroyd.me.uk/" target="_blank">http://david.holroyd.me.uk/</a><br>
<br>
_______________________________________________<br>
metaas-dev mailing list<br>
<a href="mailto:metaas-dev@lists.badgers-in-foil.co.uk">metaas-dev@lists.badgers-in-foil.co.uk</a><br>
<a href="http://lists.badgers-in-foil.co.uk/mailman/listinfo/metaas-dev" target="_blank">http://lists.badgers-in-foil.co.uk/mailman/listinfo/metaas-dev</a><br>
</font></blockquote></div><br>