Package cs2110

Class Token

java.lang.Object
cs2110.Token
Direct Known Subclasses:
Token.CondOp, Token.Function, Token.Number, Token.Operator, Token.Variable

public abstract class Token extends Object
Represents a single token (e.g., a number, variable name, operator symbol, or function name) within an expression string.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A token representing the conditional operator symbol "?:".
    static class 
    A token representing a function call.
    static class 
    A token representing a floating-point number.
    static class 
    A token representing a binary arithmetic operator.
    static class 
    A token representing the name of a variable.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final String
    The substring corresponding to the token.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Token(String value)
    Initialize inherited value field to `value`.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Token
    parse(String value)
    Create a new Token of the appropriate class corresponding to the substring `value`.
    static Iterable<Token>
    Return the sequence of whitespace-separated tokens contained in `str`.
    Return the substring that this token corresponds to.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • value

      protected final String value
      The substring corresponding to the token.
  • Constructor Details

    • Token

      protected Token(String value)
      Initialize inherited value field to `value`.
  • Method Details

    • value

      public String value()
      Return the substring that this token corresponds to.
    • parse

      public static Token parse(String value)
      Create a new Token of the appropriate class corresponding to the substring `value`. Valid decimal numbers will yield a Number token; recognized operator symbols will yield an Operator or CondOp token; values ending in "()" will yield a Function token, and all other values will yield a Variable token.
    • tokenizer

      public static Iterable<Token> tokenizer(String str)
      Return the sequence of whitespace-separated tokens contained in `str`.