Re: [antlr-interest] request for comments on language
On Thu, Feb 26, 2009 at 12:00 PM,  <[email protected]> wrote:
> Send antlr-interest mailing list submissions to
>        [email protected]
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://www.antlr.org/mailman/listinfo/antlr-interest
> or, via email, send a message with subject or body 'help' to
>        [email protected]
>
> You can reach the person managing the list at
>        [email protected]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of antlr-interest digest..."
>
>
> Today's Topics:
>
>   1. Re: if..else in StringTemplate (Terence Parr)
>   2. Re: request for comments on language implementation (Andy Tripp)
>   3. Re: request for comments on language implementation (Terence Parr)
>   4. Re: request for comments on language implementation
>      (Michael Bedward)
>   5. Changed output path in ANTLRWorks: Cannot find    tokens file
>      <unset-dir> / X.tokens (Joern Gebhardt)
>   6. Re: request for comments on language implementation
>      (Andreas Meyer)
>   7. Re: request for comments on language implementation (Andy Tripp)
>   8. Manipulating text in the lexer (Sam Barnett-Cormack)
>   9. Re: request for comments on language implementation
>      (Andreas Meyer)
>  10. Error reporting with DebugListener attached (Indhu Bharathi)
>  11. Re: Changed output path in ANTLRWorks: Cannot find        tokens
>      file <unset-dir> / X.tokens (Joern Gebhardt)
>  12. Manipulating text in the lexer (Sam Barnett-Cormack)
>  13. common tokens (Robert Soule)
>  14. Backtracking vs Lookahead (Andreas Meyer)
>  15. Re: Manipulating text in the lexer (Indhu Bharathi)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 25 Feb 2009 13:29:23 -0800
> From: Terence Parr <[email protected]>
> Subject: Re: [antlr-interest] if..else in StringTemplate
> To: YingAnnie <[email protected]>
> Cc: [email protected]
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
>
>
> On Feb 24, 2009, at 6:48 PM, YingAnnie wrote:
>
>>
>>
>>
>> Hi everyone,
>>
>> I want to use if else in the StringTemplateGroup,if (x ="org") print
>> 1234 else print 5678, but <if(x=="org")> doesnot work.
>
> Correct. ST does not allow you to do any logic computations in the
> view. You must do the computation in the model and pass the result to
> the template.
>
>  this philosophy is explained in a number of places on the website
> and the wiki.
>
> Ter
>
>
> ------------------------------
>
> Message: 2
> Date: Wed, 25 Feb 2009 17:02:52 -0500
> From: Andy Tripp <[email protected]>
> Subject: Re: [antlr-interest] request for comments on language
>        implementation
> To: Andreas Meyer <[email protected]>
> Cc: [email protected]
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Hi Andreas,
>
> Andreas Meyer wrote:
>> Hi!
>>
>> Your mail was addressed to Michael, but I hope it's ok to answer
>> nonetheless:
>>
>> I would consider hand-written code to walk an AST harmful. Maybe there
>> are cases where it is useful, but walking a dynamically typed tree like
>> this looks like a maintenance nightmare to me.
>
> I've found it much easier to do "hand-written" AST transformations.
> For example, to find cases like "x+0" and replace with just "x", you'd
> have something like:
>
> List<AST> pluses = root.findAncestorsOfType(MyTokenTypes.PLUS);
> for (AST ast: plusses) {
>        if (ast.getChildCount() == 2
>            && ast.getSecondChild().getType() == MyTokenTypes.INTEGER
>            && ast.getSecondChild().getText().equals("0")) {
>                ast.replaceMyself(ast.getFirstChild());  // replace "x+0" with 
> just "x"
>        }
> }
>
> Isn't this simpler than the ANTLR treewalker equivalent?
> Especially since whoever takes over this code when you leave will likely
> already know Java but not know ANTLR?
>
> It's maintainable because later, when you want to also replace "x*1" with 
> just "x", and a few
> other similar patterns, you can make this into a generic function:
>
> void replaceIdentity(MyTokenType type, String value, AST root) {
>        List<AST> asts = root.findAncestorsOfType(type);
>        for (AST ast: plusses) {
>                if (ast.getChildCount() == 2
>                    && ast.getSecondChild().getType() == MyTokenTypes.INTEGER
>                    && ast.getSecondChild().getText().equals("0")) {
>                        ast.replaceMyself(ast.getFirstChild());  // replace "x 
> OP VALUE" with just "x"
>                }
>        }
> }

I also like this style (in the generic form) very much.  I find it
very readable/
maintainable.  Is there anything in your tree building process that guarantees
that the literal zero is the second child?  It seems to me that for
full generality
you would also need to check the first child for zero.

Also, is the AST guaranteed to be a binary tree?  In one code generator that I
built, the arguments to an 'add' operator node were strung in a list,
from widest to narrowest.  Similarly for the multiply node.

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to