// Generic template for flex file - used by metaparser to automatically // create a lexical analyzer from a grammar spec. //import Myocc.Gsym; %% %class nonllklexer %unicode %line %column %type Gsym %eofval{ {return new Gsym("EOF");} %eofval} %{ /* copied from JFlex example */ StringBuffer string = new StringBuffer(); public int linenum() {return yyline; } // yyline is private public int columnnum() {return yycolumn;} %} LineTerminator = \r|\n|\r\n InputCharacter = [^\r\n] WhiteSpace = {LineTerminator} | [ \t\f] /* comments */ Comment = {TraditionalComment} | {EndOfLineComment} | {DocumentationComment} TraditionalComment = "/*" [^*] ~"*/" | "/*" "*"+ "/" EndOfLineComment = "//" {InputCharacter}* {LineTerminator} DocumentationComment = "/**" {CommentContent} "*"+ "/" CommentContent = ( [^*] | \*+ [^/*] )* Identifier = [:jletter:] ([:jletterdigit:] | "\_")* DecIntegerLiteral = 0 | [1-9][0-9]* FloatLiteral = [0-9]* "." [0-9]+ %state STRING %% /*{LineTerminator} { System.err.println("line "+(mylinenum++)); } */ /*";" { return new Gsym(";"); } //start { return new Gsym("start"); } */ /* keywords from nonllk.grammar: */ "x" {return new Gsym("x");} "y" {return new Gsym("y");} "z" {return new Gsym("z");} { {Identifier} { return new Gsym("ID", yytext()); } {DecIntegerLiteral} { return new Gsym("INTEGER",new Integer(yytext())); } {FloatLiteral} { return new Gsym("FLOAT",new Double(yytext())); } {Comment} { /* ignore*/ } {WhiteSpace} {/* ignore */} } \" { string.setLength(0); yybegin(STRING); } { \" { yybegin(YYINITIAL); return new Gsym("STRING", string.toString()); } [^\n\r\"\\]+ { string.append( yytext() ); } \\t { string.append('\t'); } \\n { string.append('\n'); } \\r { string.append('\r'); } \\\" { string.append('\"'); } \\ { string.append('\\'); } } /* error fallback */ [^] { throw new Error("Illegal character <"+ yytext()+">"); }