[antlr-interest] retrieving the length of a production match

Randall R Schulz rschulz at sonic.net
Tue Aug 21 13:37:39 PDT 2007


On Tuesday 21 August 2007 13:29, Adrian Herscu wrote:
> ...
>
> I can deal with parsing errors by extracting the token from the
> exception. The problem is with things beyond the syntax, like type
> checking.
>
> I will rephrase the question. On a syntactically correct input, is it
> possible to retrieve the textual length of each production match and
> store it in the AST during parsing?

In which case, Kay's answer seems germane. But it does assume you're 
using a 2nd-pass tree parser. Are you? If not, check it out. They're a 
fantastic innovation in ANTLR.


> > ...
> >
> > Other more sophisticated, parser-generator-specific techniques are
> > possible, but I'm not up on them. The topic is covered extensively
> > in TDAR.
>
> What is "TDAR"?

"The Definitive ANTLR Reference," (published Pragmatic Bookshelf; ISBN 
0-9787392-5-6 or 978-0-9787392-5-6) by none other than Terence Parr, 
the principal author of ANTLR and all its ancestors. The book is 
available in print and as a PDF. I have both (one for searching, the 
other for actually reading...)


Randall Schulz


More information about the antlr-interest mailing list