[antlr-interest] Getting column number in simple parser
Alexey Demakov
demakov at ispras.ru
Tue Mar 1 05:35:36 PST 2005
Hi
> I am using a simple parser with no AST construction. Let me explain the rule that I am trying to write.
>
> sentence: keyword (rest of the rule or subrules ...)
>
> keyword: "Town"|"City"|"Land"|"Country" ;
>
> Now I want to check the column number where the keyword occurs by using getColumn() or some other way in C++. I am new to ANTLR,
so any help will be appreciated.
I didn't use it in C++ but in Java or C# (and I beleive in C++ too)
you need to label your tokens and call label.getColumn() in code. Sorry label->getColumn() :)
keyword:
{
Token k = null;
}
// if we need label for multiple tokens
{ k=LT(1); } // thanks, Terrence :)
"Town" | "City" | "Land"
// if we need label only for one token:
| country:"Country" { country->getColumn(); }
// use label->getColumn()
{ k->getColumn(); }
Regards,
Alexey
-----
Alexey Demakov
TreeDL: Tree Description Language: http://treedl.sourceforge.net
RedVerst Group: http://www.unitesk.com
More information about the antlr-interest
mailing list