// jBASIC lexer, JFlex version -- for use with Water Buffalo, not Cup %% %class jblexer %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]* %state STRING %% /* keywords */ /*{LineTerminator} { System.err.println("line "+(mylinenum++)); } */ ";" { return new Gsym(";"); } goto { return new Gsym("goto"); } and { return new Gsym("and"); } label { return new Gsym("label"); } "(" { return new Gsym("("); } ")" { return new Gsym(")"); } ":=" { return new Gsym("assign"); } "=" { return new Gsym("="); } true { return new Gsym("true"); } false { return new Gsym("false"); } if { return new Gsym("if"); } "+" { return new Gsym("+"); } "*" { return new Gsym("*"); } then { return new Gsym("then"); } not { return new Gsym("not"); } print { return new Gsym("print"); } while { return new Gsym("while"); } begin { return new Gsym("begin"); } end { return new Gsym("end"); } { {Identifier} { return new Gsym("id", yytext()); } {DecIntegerLiteral} { return new Gsym("num",new Integer(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()+">"); }