[antlr-interest] Parser acessing lexer rules info for error recovery

Thiago Silva thiago.silva at kdemail.net
Wed Dec 7 04:12:14 PST 2005


Hello, 
I'm having a problem on parser error recovery. Some times I need lexer rules 
info to proceed with the recovery. But I'm not so sure the way to proceed, 
after reading the manual, the generated sources and antlr sources.

As a simple example:

----------------------
class SomeParser extends Parser

somerule : (....);

exception
catch[...] {
   //here I need to check, for instance, if LA(1) is a T_DATATYPE
  //or if LA(1) belongs to the token section (testLiteralsTable()?)
}


class SomeParser extends Lexer;

T_DATATYPE : T_FOO | T_BAR

T_FOO: "foo";
T_BAR: "bar"
----------------------

Now, what I'm doing is checking the LA in the catch block, manually writing 
(again) the members of T_DATATYPE:

catch[..]
 if(la_token == T_FOO | la_token == T_BAR) {
   //print a warning message
 } else {
   //print a different warning message
 }


So, if T_DATATYPE changes, I would have to update all the catch[] blocks that 
checks for T_DATATYPE.

Did I miss something in the docs? Or is this the only way possible to do it?
By the way, I'm using C++.

Thanks in advance,
Thiago



More information about the antlr-interest mailing list