[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Wrong line number

Thank you for your help. I find a bug in my token definition. The problem
was simple. I defined the new_line token like this:

new_line = 10 | 13;

So in DOS text file each CR LF combination was treated as two separate
tokens and most lines were counted twice.


-----Original Message-----
From: Etienne M. Gagnon [mailto:egagnon@j-meg.com]
Sent: Wednesday, December 29, 1999 5:08 PM
To: Pawel Szymanski
Cc: sablecc-list
Subject: Re: Wrong line number

Pawel Szymanski wrote:
> Hi
> I built a parser with SableCC and noticed that the default error handling
> messages give wrong line number of source file, where error occured.
> For example
> com.intel.itp.mof.lexer.LexerException: [5523,36] Unknown token: 0)
>         at com.intel.itp.mof.lexer.Lexer.getToken(Lexer.java, Compiled
>         at com.intel.itp.mof.lexer.Lexer.peek(Lexer.java, Compiled Code)
>         at com.intel.itp.mof.parser.Parser.parse(Parser.java, Compiled
>         at com.intel.itp.mof.parserTest.main(parserTest.java:21)
> While error is in line 3100.
> Why ?

I do not know.  You didn't give enough information (see below).

This seems to be a lexer error.  The first erroneous regular expression
(which is not matched to a token) starts at line 5523, column 36.  If
this should not be so:
(1) debug the lexer, by printing all matched tokens.  This is easily
done using a custom lexer.  Such a customized lexer can be found in the
mailing list archive.
(2) If you discover that tokens are not as you would like them to be
(this is quite likely to happen), fix your tokens definitions.

There is a very, very low probability that SableCC is faulty, but I
would be quite surprised, as programs tend to behave similarly over
time, and nobody has yet experienced a faulty line/column calculation up
to now (unless they have not reported it).

Normally, you should send a minimal grammar and input file necessary to
reproduce any bug you experience.

Etienne M. Gagnon, M.Sc.                     e-mail: egagnon@j-meg.com
Author of SableCC:                 http://www.sable.mcgill.ca/sablecc/