$a.tree or $a.token are possibilities. :)

 

Sam

 

From: dhjdhj [mailto:[email protected]] 
Sent: Friday, April 10, 2009 2:24 PM
To: Sam Harwell
Cc: [email protected]
Subject: Re: [antlr-interest] How can I find the line number and column
for asemantic error

 

Capturing errors is not the issue, I've already got such a framework
setup --- the problem I'm running into is finding that "token" object
with the line and col information in it so that I can call a method such
as your AddError in the first place.

 

 

In other words, using your example,  suppose I have a grammar rule

 

foo:    a=expr b=expr

            {

                if $a.type != $b.type

                   //then

                       AddError("Types are incompatible",    ????????,
severity);

            }

 

What goes in the field marked by ?????????

 

 

D

 

 

On Apr 10, 2009, at 12:41 PM, Sam Harwell wrote:

         

        public void AddError( string message, CommonToken token,
Severity severity )

        {

            if ( string.IsNullOrEmpty( message ) || token == null ||
ErrorHandler == null )

                return;

         

            int line = token.Line;

            int col = token.CharPositionInLine;

            int length = token.StopIndex - token.StartIndex + 1;

            // these errors aren't forcing the parser into recovery mode
so they

            // shouldn't have the same devastating performance impact

            bool canCancel = false;

         

            ErrorHandler.AddError( message, line, col, length, severity,
canCancel );

        }

         


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