%{ /* SCCS @(#)alpha.lex 1.2 - 01/25/99 - 16:28:03 * $Log: 98/9/28 sn added \r to the NONNEWLINE_WHITE_SPACE_CHAR list because it appears in the code on the PC as \n\r. Thus, we now treat \n as the character that determines a new line, and \r just as white space. 98/10/2 aa added "else" catches so that SPECIAL and NSLJ was not getting thrown in were not wanted. 98/10/3 aa added "new" catch to ARRAY so that "ARRAY" was not getting thrown in where not wanted. */ import java.lang.System; import java.io.*; import lx.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]); } } //{COMMENT_TEXT} { } %} %s COMMENT %s VERB_ON %s VERB_SCAN %s VERB_IGN IDENTIFIER [A-Za-z_$][A-Za-z_$0-9]* QIDENTIFIER {IDENTIFIER}("."{IDENTIFIER})*|"public:"|"private:" IDENT_ARR {IDENTIFIER}"["[^=,;]*"]" ALPHA [A-Za-z] DIGIT [0-9] HEXDIGIT [A-Fa-f0-9] OCTDIGIT [0-7] DECNUMBER [1-9]{DIGIT}* HEXNUMBER 0[Xx]{HEXDIGIT}+ OCTNUMBER 0{OCTDIGIT}* DECLONG {DECNUMBER}[Ll] HEXLONG {HEXNUMBER}[Ll] OCTLONG {OCTNUMBER}[Ll] EXPONENT [Ee][+-]?{DIGIT}+ FLOATBASE ((({DIGIT}+\.{DIGIT}*)|({DIGIT}*\.{DIGIT}+)){EXPONENT})|({DIGIT}+{EXPONENT})|({DIGIT}+\.{DIGIT}*)|({DIGIT}*\.{DIGIT}+) DOUBLE ({FLOATBASE}[Dd]?)|({DIGIT}+[Dd]) FLOAT ({FLOATBASE}|({DIGIT}+))[Ff] UNICODE_CHARACTER \\u{HEXDIGIT}{HEXDIGIT}{HEXDIGIT}{HEXDIGIT} ONECHAR [\^'\"]|(\\.)|.|(\\[0123]?{OCTDIGIT}{OCTDIGIT}?)|{UNICODE_CHARACTER} CHARLITCHAR {ONECHAR}|"\"" CHARACTER '[\^'\"]'|'(\\.)'|'.'|'(\\[0123]?{OCTDIGIT}{OCTDIGIT}?)'|'{UNICODE_CHARACTER}' STRINGCHAR {ONECHAR}|' STRING "\""{STRINGCHAR}*"\"" CHAR_OP [,;()[\].&|!~=+*/%<>^?:@] WHITESPACE [ \n\r\t]+ ONELINECOMMENT "//".* OLD_CCOMMENT "/*"([^("/*")]|\n)*"*/" CCOMMENT "/""*"+(("/"+[^*])?("*"[^/]|[^*/])*)*"*"+"/" HARD_COMMENT {WHITESPACE}|{ONELINECOMMENT}|{CCOMMENT} NONNEWLINE_WHITE_SPACE_CHAR [\ \t\b\012\r] WHITE_SPACE_CHAR [\ \t\b\012] STRING_TEXT (\\"\""|[^\n\"]|\\{WHITE_SPACE_CHAR}+\\)* COMMENT_TEXT ([^"/"*\n]|[^*\n]"/"[^*\n]|[^/\n]"*"[^/\n]|"*"[^/\n]|"/"[^*\n])* MYCOMMENT "/*"{COMMENT_TEXT}"*/" %% {NONNEWLINE_WHITE_SPACE_CHAR}+ {new_echo();} \n {new_echo(); //yyreturn(new YYtoken(YYtokentypes.ANY,yytext)); } \n {new_echo();} "/*" { echo(); yybegin(COMMENT); comment_count = comment_count + 1; } "/*" {echo(); comment_count = comment_count + 1; } "*/" {echo(); comment_count = comment_count - 1; Utility.assert(comment_count >= 0); if (comment_count == 0) { yybegin(INITIAL); } } . { echo(); } "//".* { new_echo(); } \"{STRING_TEXT}\" { new_echo(); //yyreturn(new YYtoken(YYtokentypes.ANY,yytext)); // Utility.assert(str.length() == lexeme().length() - 2); } \"{STRING_TEXT} { new_echo(); //yyreturn(new YYtoken(YYtokentypes.ANY,yytext)); // Utility.error(Utility.E_UNCLOSEDSTR); //Utility.assert(str.length() == lexeme().length() - 1); } [.] { new_echo(); } \n {new_echo();} "verbatim" { new_echo(); yybegin(VERB_SCAN); //yyreturn(new YYtoken(YYtokentypes.ANY,yytext)); } "nslClass " { r_echo(" class "); } "verbatim" { new_echo(); yybegin(VERB_SCAN); //yyreturn(new YYtoken(YYtokentypes.ANY,yytext)); } "NSLJ" { new_echo(" "); yybegin(VERB_ON); //yyreturn(new YYtoken(YYtokentypes.ANY,yytext)); } "off" { new_echo(" "); yybegin(INITIAL); //yyreturn(new YYtoken(YYtokentypes.ANY,yytext)); } "NSLC" { new_echo(" "); yybegin(VERB_ON); //yyreturn(new YYtoken(YYtokentypes.ANY,yytext)); } {IDENT_ARR}{WHITESPACE}{IDENTIFIER}{WHITESPACE}*";" { new_echo("special "); //yyreturn(new YYtoken(YYtokentypes.ANY,yytext)); } {IDENT_ARR}{WHITESPACE}{IDENTIFIER}{WHITESPACE}*[=,].*";" { new_echo("special "); //yyreturn(new YYtoken(YYtokentypes.ANY,yytext)); } "else"{WHITESPACE}{IDENT_ARR}{WHITESPACE}*[=,].*";" {new_echo(); } {IDENTIFIER}{WHITESPACE}{IDENT_ARR}{WHITESPACE}*[=,].*";" { new_echo("special "); //yyreturn(new YYtoken(YYtokentypes.ANY,yytext)); } "new"{WHITESPACE}{IDENT_ARR}{WHITESPACE}*";" { new_echo(); //yyreturn(new YYtoken(YYtokentypes.ANY,yytext)); } {IDENTIFIER}{WHITESPACE}{IDENT_ARR}{WHITESPACE}*";" { new_echo("ARRAY "); //yyreturn(new YYtoken(YYtokentypes.ANY,yytext)); } "else"{WHITESPACE}{IDENTIFIER}{WHITESPACE}?"("[^)]*")"{HARD_COMMENT}*"{" { new_echo(); } {QIDENTIFIER}{WHITESPACE}{IDENTIFIER}{WHITESPACE}?"("[^)]*")"{HARD_COMMENT}*"{" { new_echo("NSLJ "); } ignorethis{CCOMMENT} { r_echo("/*===*/"); System.err.println("***** ISTE\n"+yytext.lexeme()+ "\n**************\n"); } "else"{WHITESPACE}{IDENTIFIER}{WHITESPACE}*[=,].*";" {new_echo(); } {QIDENTIFIER}{WHITESPACE}{IDENTIFIER}{WHITESPACE}*[=,].*";" { new_echo("SPECIAL "); } {QIDENTIFIER}{WHITESPACE}{IDENTIFIER}{WHITESPACE}*";" { new_echo("SPECIAL "); //yyreturn(new YYtoken(YYtokentypes.ANY,yytext)); } . { new_echo(); //yyreturn(new YYtoken(YYtokentypes.ANY,yytext)); } %% private int comment_count = 0; public YYtoken dummy=new YYtoken(0,"dummy",0,0,1); public int lineno=1; NslPreProcessor npp; void r_echo(String s) { System.out.print(s); // System.out.println("\t\t/*%%Line no: "+lineno+"%%*/"); // lineno++; } void echo() { System.out.print(yytext.lexeme()); } void new_echo() { String line=yytext.lexeme(); int newline=line.indexOf("\n"); int length=line.length(); System.out.print(line); if(newline >= 0) { System.out.println("/*##Line no: "+lineno+"##*/"); lineno++; } } void new_echo(String s) { String line=yytext.lexeme(); int newline=line.indexOf("\n"); int length=line.length(); System.out.print(s+yytext.lexeme()); if(newline>=0) { System.out.println("/*^^Line no: "+lineno+"^^*/"); lineno++; } } void echo(String s) { System.out.print(s+yytext.lexeme()); } void init(NslPreProcessor npp) { npp.setWholeBuffer(yytext.wholebuffer); } int yywrap() { System.out.println(" ********* YYWRAP!!!!"); return(0); }