Class Token

java.lang.Object
net.aifusion.asn.Token

public class Token extends Object
Class to represent a lexical token
Author:
Sharad Singhal
  • Constructor Details

    • Token

      public Token(TokenType type)
      Create a token for a given type
      Parameters:
      type - - type of token
    • Token

      public Token(TokenType type, String value)
      Create a token with given type and value
      Parameters:
      type - - token type
      value - - value of the token
  • Method Details

    • is

      public boolean is(TokenType expected)
      Check if this token is of a given type
      Parameters:
      expected - - expected type of the token
      Returns:
      - true if the token type matches the expected type, false otherwise
    • isBuiltInType

      public boolean isBuiltInType()
    • setType

      public void setType(TokenType expected)
      Reset the type of this token to the expected type
      Parameters:
      expected - - expected type of the token
    • setPosition

      public void setPosition(int lineNumber, int cursor)
      Set the input position for this token
      Parameters:
      lineNumber - - line number in input
      cursor - - cursor within the line
    • value

      public String value()
      Get the value of this token
      Returns:
      - value of the token. '??' returned if the token does not have a value
    • type

      public TokenType type()
      Get the type of this token
      Returns:
      - type of the token
    • toString

      public String toString()
      Overrides:
      toString in class Object