簡単な例:選択

PARSER_BEGIN(Test)

public class Test {
  public static void main(String args[]) throws ParseException {
    Test parser = new Test(System.in);
    parser.Input();
  }
}

PARSER_END(Test)

SKIP :
{
    <SPACE:  " " | "\t" | "\n" | "\r">
}
TOKEN :
{
    <A: "a">
  | <B: "b">
  | <C: "c">
}

void Input() :
{}
{
    ( <A> | <B> | <C> )+ <EOF>
}

で、

a
b
c
abc
d
Exception in thread "main" TokenMgrError: Lexical error at line 5, column 1.  Encountered: "d" (100), after : ""
	at TestTokenManager.getNextToken(TestTokenManager.java:272)
	at Test.jj_ntk(Test.java:161)
	at Test.Input(Test.java:26)
	at Test.main(Test.java:5)