Class Scanner

java.lang.Object
org.openjdk.asmtools.jcoder.Scanner

public class Scanner extends Object
A Scanner for Jcoder tokens. Errors are reported to the environment object.

The scanner keeps track of the current token, the value of the current token (if any), and the start position of the current token.

The scan() method advances the scanner to the next token in the input.

The match() method is used to quickly match opening brackets (ie: '(', '{', or '[') with their closing counter part. This is useful during error recovery.

The compiler treats either "\n", "\r" or "\r\n" as the end of a line.

  • Field Details

    • EOF

      public static final int EOF
      End of input
      See Also:
    • LBRACE

      public static final int LBRACE
      See Also:
    • debugCP

      private boolean debugCP
    • numCPentrs

      private int numCPentrs
    • env

      protected SourceFile env
      Where errors are reported
    • in

      protected SourceFile in
      Input stream
    • macros

    • ch

      protected int ch
      The current character
    • prevCh

      protected int prevCh
      The current character
    • macro

      protected String macro
    • indexMacro

      protected int indexMacro
    • token

      protected JcodTokens.Token token
      Current token
    • pos

      protected int pos
      The position of the current token
    • prevPos

      protected int prevPos
      The position of the previous token
    • longValue

      protected long longValue
    • intValue

      protected int intValue
    • intSize

      protected int intSize
    • stringValue

      protected String stringValue
    • longStringValue

      protected ByteBuffer longStringValue
    • sign

      protected int sign
    • docComment

      protected String docComment
    • count

      private int count
      A growable character buffer.
    • buffer

      private char[] buffer
  • Constructor Details

  • Method Details

    • setDebugCP

      void setDebugCP(boolean enable)
    • addConstDebug

      void addConstDebug(JcodTokens.ConstType ct)
    • setMacro

      void setMacro(String macro)
    • readCh

      void readCh() throws IOException
      Throws:
      IOException
    • putc

      private void putc(int ch)
    • bufferString

      private String bufferString()
    • skipComment

      private void skipComment() throws IOException
      Scan a comment. This method should be called once the initial /, * and the next character have been read.
      Throws:
      IOException
    • scanDocComment

      private String scanDocComment() throws IOException
      Scan a doc comment. This method should be called once the initial /, * and * have been read. It gathers the content of the comment (witout leading spaces and '*'s) in the string buffer.
      Throws:
      IOException
    • scanDecNumber

      private void scanDecNumber() throws IOException
      Scan a decimal number
      Throws:
      IOException
    • scanHexNumber

      private void scanHexNumber() throws IOException
      Scan a hex number.
      Throws:
      IOException
    • scanEscapeChar

      private int scanEscapeChar() throws IOException
      Scan an escape character.
      Returns:
      the character or -1 if it escaped an end-of-line.
      Throws:
      IOException
    • scanString

      private void scanString() throws IOException
      Scan a string. The current character should be the opening " of the string.
      Throws:
      IOException
    • scanCharArray

      private void scanCharArray() throws IOException
      Scan a character array. The current character should be the opening ' of the array.
      Throws:
      IOException
    • scanIdentifier

      private void scanIdentifier() throws IOException
      Scan an Identifier. The current character should be the first character of the identifier.
      Throws:
      IOException
    • skipTill

      protected void skipTill(int sym) throws IOException
      Throws:
      IOException
    • xscan

      protected int xscan() throws IOException
      Throws:
      IOException
    • match

      protected void match(JcodTokens.Token open, JcodTokens.Token close) throws IOException
      Scan to a matching '}', ']' or ')'. The current token must be a '{', '[' or '(';
      Throws:
      IOException
    • scan

      protected int scan() throws IOException
      Scan the next token.
      Returns:
      the position of the previous token.
      Throws:
      IOException
    • scanMacro

      protected int scanMacro() throws IOException
      Scan the next token.
      Returns:
      the position of the previous token.
      Throws:
      IOException