|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectitec.minicompiler.Scanner
The Scanner
implements the actions necessary to extract the Token
out of the source code. These are reading the source code characterwise and mainly
distinguishing between SimpleToken
, NumberToken
and IdentToken
and handling the comments.
Field Summary | |
private char |
actChar
The character the Scanner just works on |
private int |
column
The actual column in sourceCode |
private java.util.HashSet |
digits
The set of digits |
private ErrorHandler |
errorhandler
The Errorhandler used by the actual Scanner |
private java.util.HashSet |
keywords
The set of keywords |
private java.util.HashSet |
letters
The set of letters |
private int |
line
The actual line in sourceCode |
private int |
position
The next position in sourceCode (column number) |
private java.util.HashSet |
singles
The set of special characters |
private java.lang.String |
sourceCode
The source code the Scanner works on |
Constructor Summary | |
Scanner(java.lang.String sc,
ErrorHandler e)
Initialize the Scanner with a source code sc and an ErrorHandler
e . |
Method Summary | |
private void |
comment()
Ignore any comment, i.e. read until a close comment ( *) ) is found or
the end of sourceCode is reached |
int |
getColumn()
Return the column of the actual Scanner . |
int |
getLine()
Return the line of the actual Scanner . |
private Token |
ident()
Get the identifier or keyword starting with actChar |
private void |
initDigits()
Initialize the set of digits. |
private void |
initKeywords()
Initialize the set of keywords. |
private void |
initLetters()
Initialize the set of letters. |
private void |
initSingles()
Initialize the set of special characters. |
private void |
nextChar()
Get the next character from sourceCode . |
Token |
nextToken()
Get the next token from sourceCode . |
private NumberToken |
number()
Get the number starting with actChar . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private java.util.HashSet keywords
private java.util.HashSet letters
private java.util.HashSet digits
private java.util.HashSet singles
private ErrorHandler errorhandler
private java.lang.String sourceCode
private int position
sourceCode
(column number)
private int line
sourceCode
private int column
sourceCode
private char actChar
Constructor Detail |
public Scanner(java.lang.String sc, ErrorHandler e)
sc
and an ErrorHandler
e
. Furthermore set the position
, the line
and column
to the right value in he source code (i.e. at the
position 1:0).
sc
- The source code the Scanner should work one
- The ErrorHandler the Scanner should useMethod Detail |
public int getLine()
Scanner
.
public int getColumn()
Scanner
.
private void initKeywords()
private void initLetters()
private void initDigits()
private void initSingles()
private void nextChar()
sourceCode
.
private NumberToken number()
actChar
.
NumberToken
containing the value of the whole numberprivate Token ident()
actChar
SimpleToken
if a keyword is found, an IdentToken
otherwiseprivate void comment()
*)
) is found or
the end of sourceCode
is reached
public Token nextToken()
sourceCode
.
IdentToken
if an identifier is found, a NumberToken
if a number is found or a SimpleToken
if a keyword or an
operation is found. If the end of sourceCode
is reached, a
SimpleToken
"EMPTY" is returned.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |