[antlr-interest] Line and column information

Björn ??? kreaper666 at hotmail.com
Fri Nov 16 03:06:15 PST 2007


Hi, 


We got a problem with our compiler.
What I want is to get the line and column information from it.

temptest :
    e1:equation s1:SEMICOLON!
    {
        #temptest = #([EQUATION_STATEMENT,"EQUATION_STATEMENT"], #temptest);        

        RefMyAST(#temptest)->setEndLine((#s1)->getLine()); // working
        RefMyAST(#temptest)->setEndColumn((#s1)->getColumn()); // working
/* This will not be correct since we don't know what e1 will look like and most likely the top tree node will not be first char.
        RefMyAST(#temptest)->setLine((#e1)->getLine());
        RefMyAST(#temptest)->setColumn((#e1)->getColumn());
*/
    }
    ;
    equation : 
        (   (simple_expression EQUALS) => tmp:equality_equation 
        |   /**some more matching...**/
        )
        {
            if(#tmp){
                RefMyAST(#equation)->setLine((#tmp)->getLine());
                RefMyAST(#equation)->setColumn((#tmp)->getColumn());
            }
            
        }

here we do have a problem, tmp->getline will not give the leftmost character.


That is the code.
What i want is in "temptest : matching" to get the position of the first character. 
So i get the start from there and the end from the semicolon, the semicolon is working.
But I can't figure out how to get the start-information.
if i recursivly return the line & column information i can go to "(simple_expression EQUALS) => tmp:equality_equation" at that predicate it will get messed up for some reason. I can't get the simple_expression position.

But preferebly I would like to get the start from


temptest :

    e1:equation s1:SEMICOLON!


Have any ideas ? 

 --Björn Zachrisson 

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071116/ab98ad3a/attachment.html 


More information about the antlr-interest mailing list