package rog; import java.io.*; /** Counting parens with a lexer. * @author Roger Levy */ %% %{ private int numParens = 0; %} %class ParenCounter %standalone %unicode %type Object %eofval{ return null; %eofval} %% { \( { numParens++; return yytext(); } \) { if(numParens == 0) throw new RuntimeException("error -- too many close parens!"); else { numParens--; return yytext(); } } }