package oops; import java.io.IOException; import java.io.Reader; import oops.parser.Parser; import oops.parser.Set; import oops.parser.Token; %% %public %class Scanner %type boolean %eofval{ return false; %eofval} %{ protected Set tokenSet; // null or lookahead identifying token protected Object node; // node representing token protected Parser parser; // for lookup of tokens protected Set NUMBER; // for marking of constants /** implements oops' interface -- should be reworked! */ public static class Input implements oops.parser.Scanner { protected Scanner scanner; // aggregated protected boolean atEnd; // true at EOF public boolean atEnd () { return atEnd; } public Set tokenSet () { return scanner.tokenSet; } public Object node () { return scanner.node; } public void scan (Reader r, Parser parser) throws IOException { scanner = new Scanner(r); scanner.parser = parser; scanner.NUMBER = ((Token)parser.getPeer("Number")).getLookahead(); advance(); // one token lookahead } public boolean advance () throws IOException { if (!atEnd && scanner.yylex()) return true; scanner.tokenSet = null; atEnd = true; return false; } } %} comment = ("#".*) space = [\ \t\b\015]+ digit = [0-9] integer = {digit}+ exp = ([eE]("+"|"-")?{digit}+) real = ({digit}+"."{digit}*{exp}?|"."{digit}+{exp}?|{digit}+{exp}) %% {space} { } {comment} { } {integer} { tokenSet = NUMBER; node = new Integer(yytext()); return true; } {integer}[lL] { tokenSet = NUMBER; node = new Long(yytext().substring(0, yytext().length()-1)); return true; } {real} { tokenSet = NUMBER; node = new Double(yytext()); return true; } .|\n { tokenSet = parser.getLitSet(yytext()); return true; }