Hello folks,

I'm working on an expression reader in one of my grammars and am working
with transporting line and column numbers from my grammar to a different
place in my compiler architecture. I apologize if this has been asked
before. I did a search, but did not immediately see an answer. A simplified
version of the grammar is below

expression    returns[ExpressionValue eval]
    :
    |    ^(PLUS left = expression right = expression)
        {        }
    |    INT
        {
            int bl = $INT.getLine();
            int bc = $INT.getCharPositionInLine();
            int ec = bc + $INT.text.length();
            //etc
        }
    ;

Now, when the item I want to get line and column numbers from is a terminal,
things are easy, as I can just call getLine and getCharPositionInLine.
However, when I have rules, it's not immediately clear to me how I go about
getting them without doing some hacking behind the scenes. What I've been
doing is something like this:

CLASS ID?
    {
        currentClass.setLineBegin($CLASS.getLine());
        currentClass.setColumnBegin($CLASS.getCharPositionInLine());
    }
        method_declaration*
    END
    {
        currentClass.setLineEnd($END.getLine());
        currentClass.setColumnEnd($END.getCharPositionInLine());
    }

This works fine when I've got terminals at the beginning and end of a
particular rule, but does not work when I have rewrite rules in a grammar
(e.g., ^(PLUS left = expression right = expression) )

What am I missing here? Is there an easy way to get line and column number
information from each subrule in a rewrite?

Any ideas are appreciated,

Andy

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

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