Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.statcato.calculator
Class TokenScanner

    java.lang.Object
      org.statcato.calculator.TokenScanner

    public class TokenScanner

extends java.lang.Object

A scanner that read Tokens from a string representing a mathematical expression.

Since:
  1.0
Version:
  %I%, %G%
Author:
  Margaret Yau
See Also:
  `Token`

Field Summary
`java.lang.String` | `error`

Constructor Summary
`TokenScanner(java.lang.String expr, Spreadsheet spreadsheet)` Constructor.

Method Summary
`int` | `consumeColumn()` Consumes the column at the next scan position.
`double` | `consumeConstant()` Consumes the constant at the next scan position.
`int` | `consumeFunction()` Consumes the function at the next scan position.
`double` | `consumeNumber()` Consumes the number at the next scan position.
`void` | `consumeToken()` Consumes the current token by advancing the index to the next position.
`void` | `error(java.lang.String msg)` Adds the given string to the error string.
`boolean` | `expect(java.lang.String name)`
`int` | `getColumn()` Attempts to parse a column label and returns the column number if successful.
`double` | `getConstant()` Attempts to parse a constant name and returns the constant if successful.
`double` | `getDecimal()` Returns the double value that begins with '.' at the current scan position.
`int` | `getFunction()` Attempts to parse a function name and returns the function number if successful.
`int` | `getInteger()` Returns the integer value at the current scan position.
`double` | `getNumber()` Returns the double value at the current scan position.
`java.lang.String` | `getString()` Returns the next string (delimited by single quotes)
`int` | `getToken()` Returns the type of the next token.
`void` | `printRemaining()` Prints the string remaining to be scanned.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### error

    public java.lang.String error

Constructor Detail

### TokenScanner

    public TokenScanner(java.lang.String expr,
                        Spreadsheet spreadsheet)

  Constructor. A string of mathematical expression and the associated spreadsheet is given.

  Parameters:
    `expr` - string of mathematical expression

Method Detail

### printRemaining

    public void printRemaining()

  Prints the string remaining to be scanned.

### consumeNumber

    public double consumeNumber()

  Consumes the number at the next scan position.

  Returns:
    double

### consumeColumn

    public int consumeColumn()

  Consumes the column at the next scan position.

  Returns:
    column number

### consumeFunction

    public int consumeFunction()

  Consumes the function at the next scan position.

  Returns:
    function number

### consumeConstant

    public double consumeConstant()

  Consumes the constant at the next scan position.

  Returns:
    constant double

### getToken

    public int getToken()

  Returns the type of the next token. The token is not consumed.

  Returns:
    token type

### consumeToken

    public void consumeToken()

  Consumes the current token by advancing the index to the next position. Should be used only after a @url(#getToken} call is called.

### getColumn

    public int getColumn()

  Attempts to parse a column label and returns the column number if successful.

  Returns:
    column number if a valid column label is parsed or -1 otherwise

### getFunction

    public int getFunction()

  Attempts to parse a function name and returns the function number if successful.

  Returns:
    function number if a valid function name is parsed or -1 otherwise

### getConstant

    public double getConstant()

  Attempts to parse a constant name and returns the constant if successful.

  Returns:
    a defined constant of double value if a valid constant name is parsed or MathFunctions.UNDEFINED otherwise

### expect

    public boolean expect(java.lang.String name)

### getString

    public java.lang.String getString()

  Returns the next string (delimited by single quotes)

  Returns:
    string

### getNumber

    public double getNumber()

  Returns the double value at the current scan position.

  Returns:
    double value

### getInteger

    public int getInteger()

  Returns the integer value at the current scan position.

  Returns:
    integer value

### getDecimal

    public double getDecimal()

  Returns the double value that begins with '.' at the current scan position.

  Returns:
    double value

### error

    public void error(java.lang.String msg)

  Adds the given string to the error string.

  Parameters:
    `msg` -

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD