de.projectory.koivima.compiler.assembler
Class Parser

java.lang.Object
  extended by de.projectory.koivima.compiler.assembler.Parser

public class Parser
extends java.lang.Object

Parses a piece of assembler code for tokens.


Nested Class Summary
(package private) static class Parser.ParseMode
          state of parsing
 
Field Summary
(package private) static char cr
           
(package private)  boolean eofHasBeenReached
          has end of file been reached?
protected  java.io.Reader in
          The input stream to read from
(package private) static char lf
           
(package private)  Parser.ParseMode mode
          Used by buildToken() to remember the state or parsing
(package private) static char space
           
(package private) static char tab
           
(package private)  java.lang.StringBuilder tokenBuilder
          used by buildToken() to build a new token
 
Constructor Summary
Parser(java.io.Reader input)
          Creates a parser that reads tokens from a given Reader.
 
Method Summary
protected  java.lang.String buildToken(int in)
          Receives single characters and builds a token from them.
 java.lang.String getToken()
          Returns the next token.
protected  boolean isSeparator(char character)
          Checks wether the given character is a separator for a new token.
protected  boolean isToken(char character)
          Checks if given character is a token by itself.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tab

static final char tab
See Also:
Constant Field Values

cr

static final char cr
See Also:
Constant Field Values

lf

static final char lf
See Also:
Constant Field Values

space

static final char space
See Also:
Constant Field Values

in

protected java.io.Reader in
The input stream to read from


tokenBuilder

java.lang.StringBuilder tokenBuilder
used by buildToken() to build a new token


eofHasBeenReached

boolean eofHasBeenReached
has end of file been reached? Used by buildToken()


mode

Parser.ParseMode mode
Used by buildToken() to remember the state or parsing

Constructor Detail

Parser

public Parser(java.io.Reader input)
Creates a parser that reads tokens from a given Reader.

Method Detail

isSeparator

protected boolean isSeparator(char character)
Checks wether the given character is a separator for a new token.


isToken

protected boolean isToken(char character)
Checks if given character is a token by itself. Valid single character tokens are: { } [ ]


buildToken

protected java.lang.String buildToken(int in)
Receives single characters and builds a token from them.

Returns:
A new token if the token is finished or null if this methods expects more characters.

getToken

public java.lang.String getToken()
                          throws java.io.IOException
Returns the next token. If there are no more tokens, null is returned. Token examples: "Hello" 12 Operator { }

Throws:
java.io.IOException