At 03:17 12/12/2008, Sven Van Echelpoel wrote: >According to the book you can derive imaginary nodes from real >tokens to take over attributes (such as line number) from the >latter. The syntax for this is : > >foo : b='bar' -> ^( BAR[ $b ] ) > ; [...] >In the first one, createImaginaryNode, if you pass one argument to >it, which I'm assuming to be the case, a type from a text is created. >In the second one, createRewriteNodeFromElement, a type from a token >is created with the same number of arguments. > >Although I have not dug any further, I can tell from examining the >generated parser code that in an AST rewrite, the >createImaginaryNode is used, resulting in nothing (the cast to >pANTLR3_UINT8 probably and luckily makes it point to a zero, >immediately terminating the string). > >It can be made to work by passing the second argument (the text), >even though I have no use for that.
This is just a guess, but I suspect the reason for this is the lack of the ability to have overloaded methods in C :) In Java, you can have one method that accepts two different types of parameters, so the template code for the version that passes in a string and the version that passes in a token can be identical, leaving it up to the Java compiler to figure out which one you meant to call. In C, however, there's no overloading so this is not possible. The template will have to generate calls to differently-named functions depending on whether you are passing in a string or a token -- and unfortunately, since this is target-specific code, there's no (reliable) way for ANTLR to detect the type of a single parameter. So the only option left open to it is to settle for detecting whether you're passing one parameter or two. (A native C++ target could remove this limitation again, of course.) The workaround would be to change BAR[$b] to BAR[$b, $b.text], I think. List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org:8080/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 -~----------~----~----~----~------~----~------~--~---
