Class Lexer

java.lang.Object
org.flag4j.io.parsing.Lexer

public abstract class Lexer extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String
    Content of the lexer.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Lexer(String content)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static void
    error(String message)
    Stops execution with an error message
    Gets the content of this Lexer.
    protected int
    Produces individual symbols from content, left to right, as ascii values.
    abstract org.flag4j.io.parsing.Token
    Produces next Token from the string being parsed.
    protected boolean
    isDigit(int code)
     
    protected void
    putBackSymbol(int sym)
    Replaces unneeded symbol back into content string.

    Methods inherited from class java.lang.Object

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

    • content

      protected String content
      Content of the lexer.
  • Constructor Details

    • Lexer

      protected Lexer(String content)
      Parameters:
      content - String representation of complex number
  • Method Details

    • getContent

      public String getContent()
      Gets the content of this Lexer.
      Returns:
      content of Lexer
    • isDigit

      protected boolean isDigit(int code)
      Parameters:
      code - ascii value of character
      Returns:
      true if character is digit; false otherwise.
    • getNextSymbol

      protected int getNextSymbol()
      Produces individual symbols from content, left to right, as ascii values.
      Returns:
      Returns ascii value of the next symbol from content. If content is empty then returns -1
    • putBackSymbol

      protected void putBackSymbol(int sym)
      Replaces unneeded symbol back into content string. Note: This method should only be used when the programmer is confident the token is not an unexpected token.
      Parameters:
      sym - Symbol to place back into content string
    • getNextToken

      public abstract org.flag4j.io.parsing.Token getNextToken()
      Produces next Token from the string being parsed. Also removes this Token from the string. This method implements a finite automata which describes the legal arrangement of tokens within a complex number.
      Returns:
      Next Token in string.
      Throws:
      RuntimeException - If the string is not a valid representation of a complex number.
    • error

      protected static void error(String message)
      Stops execution with an error message
      Parameters:
      message - Error message to print