Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 3 package java_cup.simple_calc; 4 5 import java_cup.runtime.Symbol; 6 7 public class scanner implements java_cup.runtime.Scanner { 8 final java.io.InputStream instream; 9 10 public scanner(java.io.InputStream is) throws java.io.IOException { 11 instream = is; 12 } 13 public scanner() throws java.io.IOException { this(System.in); } 14 15 16 protected int next_char = -2; 17 18 19 protected void advance() 20 throws java.io.IOException 21 { next_char = instream.read(); } 22 23 24 private void init() 25 throws java.io.IOException 26 { advance(); } 27 28 29 public Symbol next_token() 30 throws java.io.IOException 31 { 32 if (next_char==-2) init(); for (;;) 34 switch (next_char) 35 { 36 case '0': case '1': case '2': case '3': case '4': 37 case '5': case '6': case '7': case '8': case '9': 38 39 int i_val = 0; 40 do { 41 i_val = i_val * 10 + (next_char - '0'); 42 advance(); 43 } while (next_char >= '0' && next_char <= '9'); 44 return new Symbol(sym.NUMBER, new Integer (i_val)); 45 46 case ';': advance(); return new Symbol(sym.SEMI); 47 case '+': advance(); return new Symbol(sym.PLUS); 48 case '-': advance(); return new Symbol(sym.MINUS); 49 case '*': advance(); return new Symbol(sym.TIMES); 50 case '/': advance(); return new Symbol(sym.DIVIDE); 51 case '%': advance(); return new Symbol(sym.MOD); 52 case '(': advance(); return new Symbol(sym.LPAREN); 53 case ')': advance(); return new Symbol(sym.RPAREN); 54 55 case -1: return new Symbol(sym.EOF); 56 57 default: 58 59 advance(); 60 break; 61 } 62 } 63 }; 64
| Popular Tags
|