step3
Class Scanner

java.lang.Object
  extended by java.io.StreamTokenizer
      extended by step3.Scanner
All Implemented Interfaces:
If.yyInput

public class Scanner
extends StreamTokenizer
implements If.yyInput

hand-crafted lexical analysis for lines with arithmetic expressions. The tracing facilities of the generated scanner are reused.

If pj is to include this scanner with -scanner:static Scanner.java the lines preceding this comment and the main program have to be removed and the package prefixes have to be made explicit.


Field Summary
protected  int token
          returned by token().
protected  Object value
          returned by value().
 
Fields inherited from class java.io.StreamTokenizer
nval, sval, TT_EOF, TT_EOL, TT_NUMBER, TT_WORD, ttype
 
Constructor Summary
Scanner(Reader in)
          configure for floating point numbers, skipping, comments, and newlines.
 
Method Summary
 boolean advance()
          move on to next token.
static void main(String[] args)
          main program, generates and tests scanner on standard input.
 int token()
          current input symbol.
 Object value()
          null or object associated with current input symbol.
 
Methods inherited from class java.io.StreamTokenizer
commentChar, eolIsSignificant, lineno, lowerCaseMode, nextToken, ordinaryChar, ordinaryChars, parseNumbers, pushBack, quoteChar, resetSyntax, slashSlashComments, slashStarComments, toString, whitespaceChars, wordChars
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

token

protected int token
returned by token().


value

protected Object value
returned by value().

Constructor Detail

Scanner

public Scanner(Reader in)
        throws IOException
configure for floating point numbers, skipping, comments, and newlines. Map double-quoted strings to '$' for demonstration purposes. Does not screen for reserved words.

Throws:
IOException
Method Detail

main

public static void main(String[] args)
                 throws IOException
main program, generates and tests scanner on standard input. This uses the boilerplate generated by pj for a generated static scanner.

Throws:
IOException

advance

public boolean advance()
                throws IOException
Description copied from interface: If.yyInput
move on to next token.

Specified by:
advance in interface If.yyInput
Returns:
false if positioned beyond tokens.
Throws:
IOException - on input error.

token

public int token()
current input symbol.

Specified by:
token in interface If.yyInput
Returns:
current %token or single character.

value

public Object value()
null or object associated with current input symbol.

Specified by:
value in interface If.yyInput
Returns:
value for If.yyInput.token().