public class LexicalAnalyzer
extends java.lang.Object
This analyzes the lexical content of the code entered by the user. It also feed the table of symbols with identifiers, images and number of line.
SymbolsTable
Modifier and Type | Field and Description |
---|---|
private boolean |
found
Boolean telling whether the token as been found or not.
|
private java.util.List<java.lang.String> |
keywords
List of all the possible keywords.
|
private java.lang.String[] |
label
Array containing an identifier and the line number
on which it occurred.
|
private int |
lineNum
Current line number
|
private SymbolsTable |
symTab
Table of symbols.
|
private java.util.List<java.lang.String> |
units
List of all the possible lexical units corresponding
to the equivalent keyword.
|
private java.lang.String[] |
variable
Array containing an identifier and its corresponding
image.
|
Constructor and Description |
---|
LexicalAnalyzer(SymbolsTable tos)
Constructor
|
Modifier and Type | Method and Description |
---|---|
private boolean |
isComment(java.lang.String input,
boolean newLine)
Checks if the input String is a comment.
|
private boolean |
isIdentifier(java.lang.String input)
Checks if the input String is an identifier.
|
private boolean |
isImage(java.lang.String input)
Checks if the input String is an image.
|
private boolean |
isInteger(java.lang.String input)
Checks if the input String is an integer.
|
private boolean |
isReal(java.lang.String input)
Checks if the input String is a real number.
|
private boolean |
isString(java.lang.String input)
Checks if the input String is a string.
|
java.lang.String[] |
nextToken(java.lang.String input,
boolean newLine,
int lineNum)
Analyzes the String it is feed with.
|
void |
printSymbolsTable()
Ask the table of symbols to the SymbolsTable
object and print it on the standard output.
|
private java.lang.String[] |
searchTokenType(java.lang.String[] couple) |
private java.util.List<java.lang.String> keywords
List of all the possible keywords.
private java.util.List<java.lang.String> units
List of all the possible lexical units corresponding to the equivalent keyword.
keywords
private java.lang.String[] variable
Array containing an identifier and its corresponding image. Used to feed the table of symbols.
private java.lang.String[] label
Array containing an identifier and the line number on which it occurred. Used to feed the table of symbols.
private SymbolsTable symTab
Table of symbols.
SymbolsTable
private boolean found
private int lineNum
public LexicalAnalyzer(SymbolsTable tos)
Initializes the keywords and lexical units ArrayLists. Creates the table of symbols.
private boolean isIdentifier(java.lang.String input)
Checks if the input String is an identifier.
input
- Candidate to the identifier status.private boolean isImage(java.lang.String input)
Checks if the input String is an image.
input
- Candidate to the image status.private boolean isInteger(java.lang.String input)
Checks if the input String is an integer.
input
- Candidate to the integer status.private boolean isReal(java.lang.String input)
Checks if the input String is a real number.
input
- Candidate to the real status.private boolean isString(java.lang.String input)
Checks if the input String is a string.
input
- Candidate to the string status.private boolean isComment(java.lang.String input, boolean newLine)
Checks if the input String is a comment.
input
- Candidate to the comment status.public java.lang.String[] nextToken(java.lang.String input, boolean newLine, int lineNum)
Analyzes the String it is feed with.
It begins by checking either the input is a comment or not. If not, it splits it and begins the analysis. As soon as a token is recognized, the method gives it back to the caller along the corresponding lexical unit.
It will also feed the table of symbols with various couple of identifier/image or identifier/line number.
input
- String to analyze.newLine
- Boolean telling if the input String is
the beginning of a new line or not.
Useful for the isComment() method.lineNum
- Line of the current String being analyzed.
Useful for the table of symbols.SymbolsTable.addLabel(java.lang.String[])
,
SymbolsTable.addVariable(java.lang.String[])
private java.lang.String[] searchTokenType(java.lang.String[] couple)
public void printSymbolsTable()
Ask the table of symbols to the SymbolsTable object and print it on the standard output.
SymbolsTable.toString()