[antlr-interest] How can I find the line number and column for asemantic error

dhjdhj dhjdhj at gmail.com
Fri Apr 10 12:24:12 PDT 2009


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 );
> }
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090410/a05529e7/attachment.html 


More information about the antlr-interest mailing list