public class SymbolsTable
extends java.lang.Object
This class receives the different variables and labels from the lexical analyzer, store them in arrays, sort those arrays and output them if required.
Modifier and Type | Field and Description |
---|---|
private java.util.List<java.lang.String> |
labels
ArrayList containing the labels.
|
private java.util.List<java.lang.String[]> |
tos
Table of symbols
|
private java.util.List<java.lang.String> |
variables
ArrayList containing the variables.
|
Constructor and Description |
---|
SymbolsTable()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addLabel(java.lang.String[] newLab)
Add a new label to the list.
|
void |
addVariable(java.lang.String[] newVar)
Add a new variable to the list.
|
int |
getIndexOf(java.lang.String id)
Searches for the identifier in the table and returns its id.
|
int |
getMaxLengthOf(java.lang.String id) |
java.lang.String |
getValueOf(java.lang.String id) |
boolean |
isIdSigned(java.lang.String id) |
void |
newEntry(java.lang.String[] entry) |
private void |
sortList(java.util.List<java.lang.String> list)
Sorting of the list.
|
java.lang.String |
toString()
Production and formating of the output String.
|
private java.util.List<java.lang.String> variables
ArrayList containing the variables.
The i th element is an identifier, the i+1 th is the corresponding image.
private java.util.List<java.lang.String> labels
ArrayList containing the labels.
The i th element is an identifier, the i+1 th is the corresponding line number at which it occurred.
private java.util.List<java.lang.String[]> tos
Table of symbols
Name, Initialization, Type (signed int, unsigned int), digits, current value
public void addVariable(java.lang.String[] newVar)
Add a new variable to the list.
If the list does not already contains the identifier, the identifier and its corresponding image are appended to the list.
newVar
- Array of two elements:
variables
public void addLabel(java.lang.String[] newLab)
Add a new label to the list.
The method first checks if the list already contains the identifier. In the case it does, it needs to check if it's not on the same line as given in parameter. It can then add it to the list. If the list does not already contain the identifier, the method directly append the parameter to the list without any further question.
newLab
- Array of two Strings:
labels
public java.lang.String toString()
Production and formating of the output String.
toString
in class java.lang.Object
private void sortList(java.util.List<java.lang.String> list)
Sorting of the list.
The algorithm used is the bubble sort.
list
- Can be either list, they are both similarly structured.public void newEntry(java.lang.String[] entry)
public int getIndexOf(java.lang.String id)
id
- - Identifierpublic int getMaxLengthOf(java.lang.String id)
public java.lang.String getValueOf(java.lang.String id)
public boolean isIdSigned(java.lang.String id)