%{ package patch.src; import java.util.*; import java.io.*; import java.lang.System; import patch.src.util.*; import pp.src.jbf.*; // import patch.src.jbf.*; class Utility { public static void assert ( boolean expr ) { if (false == expr) { throw (new Error("Error: Assertion failed.")); } } private static final String errorMsg[] = { "Error: Unmatched end-of-comment punctuation.", "Error: Unmatched start-of-comment punctuation.", "Error: Unclosed string.", "Error: Illegal character." }; public static final int E_ENDCOMMENT = 0; public static final int E_STARTCOMMENT = 1; public static final int E_UNCLOSEDSTR = 2; public static final int E_UNMATCHED = 3; public static void error ( int code ) { System.out.println(errorMsg[code]); } } %} %s COMMENT IDENTIFIER [A-Za-z_$][A-Za-z_$0-9]* IDENT_ARR {IDENTIFIER}{WHITESPACE}*"["[^=,;]*"]" WHITESPACE [ \n\r\t]+ ONELINECOMMENT "//".* OLD_CCOMMENT "/*"([^("/*")]|\n)*"*/" CCOMMENT "/""*"+(("/"+[^*])?("*"[^/]|[^*/])*)*"*"+"/" HARD_COMMENT {WHITESPACE}|{ONELINECOMMENT}|{CCOMMENT} CHAR_OP [,;()[\].&|!~=+*/%<>^?:@] %% "/*" { yybegin(COMMENT); comment_count = comment_count + 1; } "/*" { comment_count = comment_count + 1; } "*/" { comment_count = comment_count - 1; Utility.assert(comment_count >= 0); if (comment_count == 0) { yybegin(INITIAL); } } . { } "//".* { } "abstract" { yyreturn(new YYtoken(YYtokentypes.ABSTRACT,yytext));} "boolean" { yyreturn(new YYtoken(YYtokentypes.BOOLEAN,yytext));} "byte" { yyreturn(new YYtoken(YYtokentypes.BYTE,yytext));} "char" { yyreturn(new YYtoken(YYtokentypes.CHAR, yytext));} "class" { yyreturn(new YYtoken(YYtokentypes.CLASS,yytext));} "double" { yyreturn(new YYtoken(YYtokentypes.DOUBLE,yytext));} "float" { yyreturn(new YYtoken(YYtokentypes.FLOAT,yytext));} "extends" { yyreturn(new YYtoken(YYtokentypes.EXTENDS, yytext));} "final" { yyreturn(new YYtoken(YYtokentypes.FINAL, yytext));} "implements" { yyreturn(new YYtoken(YYtokentypes.IMPLEMENTS, yytext));} "int" { yyreturn(new YYtoken(YYtokentypes.INT ,yytext));} "interface" { yyreturn(new YYtoken(YYtokentypes.INTERFACE, yytext));} "long" { yyreturn(new YYtoken(YYtokentypes.LONG ,yytext));} "private" { yyreturn(new YYtoken(YYtokentypes.PRIVATE , yytext));} "protected" { yyreturn(new YYtoken(YYtokentypes.PROTECTED, yytext));} "public" { yyreturn(new YYtoken(YYtokentypes.PUBLIC, yytext));} "short" { yyreturn(new YYtoken(YYtokentypes.SHORT, yytext));} "static" { yyreturn(new YYtoken(YYtokentypes.STATIC, yytext));} "transient" { yyreturn(new YYtoken(YYtokentypes.TRANSIENT, yytext));} "volatile" { yyreturn(new YYtoken(YYtokentypes.VOLATILE , yytext));} "void" { yyreturn(new YYtoken(YYtokentypes.VOID , yytext));} "{" { yyreturn(new YYtoken((yytext.lexeme()).charAt(0), yytext));} "}" { yyreturn(new YYtoken((yytext.lexeme()).charAt( 0), yytext));} {CHAR_OP} { yyreturn(new YYtoken((yytext.lexeme()).charAt(0), yytext));} "-" { yyreturn(new YYtoken((yytext.lexeme()).charAt(0), yytext));} {IDENTIFIER} { YYtoken t =new YYtoken(YYtokentypes.SYMBOL, yytext); yyreturn(t); } %% private int comment_count = 0; npp.src.util.NslPreProcessor p; public void init(npp.src.util.NslPreProcessor pat) { // pat.setWholeBuffer(yytext.wholebuffer); } /* public void init(npp.src.NPP pat) { // pat.setWholeBuffer(yytext.wholebuffer); } */