How can I use the same lexer with multiple parsers?

Terence Parr

Lexers are just objects, so you can attach any parser you want to instances of the same object (just don't have the parsers operate simultaneously--lexers only work on one input stream at a time). The only thing you have to keep in mind is that the vocabularies have to be compatible. In other words, if your parser is looking for INT and ID, but your lexer only generates tokens STRING and STRUCT then you will have a problem. The parser can only apply grammatical structure to a stream of vocabulary symbols it's expecting.