簡単な例、Scanner の部分で JFlex を使って

トークンでなく、直接文字を記述

%%

%class Scanner
%implements Test.yyInput

%type int

%eofval{
    return YYEOF;
%eofval}

%{
    private int token;
    protected Object value;

    public boolean advance() throws java.io.IOException {
        token = yylex();
        return token != YYEOF;
    }

    public int token() {
        return token;
    }

    public Object value() {
        return value;
    }
%}

%%

.|\n    { value = null; return yytext().charAt(0); }

と、

%{

import java.io.*;

public class Test {

%}

%%

start : 'a' '\n'  { System.out.println("*a*"); }

%%

  public static void main (String args []) {
    Scanner scanner = new Scanner(new InputStreamReader(System.in));
    try {
      new Test().yyparse(scanner);
    } catch (IOException ie) { ie.printStackTrace(); }
      catch (yyException ye) { System.err.println(ye); }
  }

}

で、

a
*a*
a
syntax error
Test$yyException: irrecoverable syntax error