// jBASIC lexer // import java_cup.runtime.*; // import JB1.myclasses.*; %% %{ private int mylinenum = 1; // keep track of line numbers private void err(int pos, String s) { System.out.println("Error at line " + mylinenum + ":\n" + s); } private void err(String s) { err(yychar,s); } private java_cup.runtime.Symbol tok(int k, Object val) { return new java_cup.runtime.Symbol(k, yychar, yychar+yylength(), val); } // changestring inserts real line returns (mine) private String changestring(String s) { int i = 0; String news = ""; int len = s.length(); while (i\n { mylinenum++; } {NONNEWLINE_WHITE_SPACE}+ {} \"{STRING_TEXT}\" { // System.out.println("I found a string: " + changestring(yytext().substring(1,yytext().length() - 1))); return tok(sym.STRINGe, changestring(yytext().substring(1,yytext().length() - 1))); } ";" { return tok(sym.SEMI, null); } goto { return tok(sym.GOTO, null); } and { return tok(sym.ANDop, null); } label { return tok(sym.LABEL, null); } ":=" { return tok(sym.ASSIGN, null); } "(" { return tok(sym.LPAREN, null); } ")" { return tok(sym.RPAREN, null); } "=" { return tok(sym.EQUAL, null); } true { return tok(sym.TRUE, null); } false { return tok(sym.FALSE, null); } if { return tok(sym.IF, null); } "+" { return tok(sym.PLUS, null); } "*" { return tok(sym.TIMES, null); } then { return tok(sym.THEN, null); } not { return tok(sym.NOT, null); } print { // System.out.println("I found a print token!"); return tok(sym.PRINT, null); } while { return tok(sym.WHILE, null); } begin { return tok(sym.BEGIN, null); } end { return tok(sym.END, null); } {DIGITS} { return tok(sym.NUM, new Integer(yytext())); } [a-zA-Z]([a-zA-Z0-9]*) { return tok(sym.ID, yytext()); }