org.statcato.calculator
Class TokenScanner
- java.lang.Object
-
- org.statcato.calculator.TokenScanner
-
public class TokenScanner extends java.lang.ObjectA scanner that read Tokens from a string representing a mathematical expression.- Since:
- 1.0
- See Also:
Token
-
-
Field Summary
Fields Modifier and Type Field and Description java.lang.Stringerror
-
Constructor Summary
Constructors Constructor and Description TokenScanner(java.lang.String expr, Spreadsheet spreadsheet)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description intconsumeColumn()Consumes the column at the next scan position.doubleconsumeConstant()Consumes the constant at the next scan position.intconsumeFunction()Consumes the function at the next scan position.doubleconsumeNumber()Consumes the number at the next scan position.voidconsumeToken()Consumes the current token by advancing the index to the next position.voiderror(java.lang.String msg)Adds the given string to the error string.booleanexpect(java.lang.String name)intgetColumn()Attempts to parse a column label and returns the column number if successful.doublegetConstant()Attempts to parse a constant name and returns the constant if successful.doublegetDecimal()Returns the double value that begins with '.' at the current scan position.intgetFunction()Attempts to parse a function name and returns the function number if successful.intgetInteger()Returns the integer value at the current scan position.doublegetNumber()Returns the double value at the current scan position.java.lang.StringgetString()Returns the next string (delimited by single quotes)intgetToken()Returns the type of the next token.voidprintRemaining()Prints the string remaining to be scanned.
-
-
-
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-
-
-
DMelt 3.0 © DataMelt by jWork.ORG