public class SymbolTable
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
(package private) class |
SymbolTable.Symbol
A class representing
|
| Constructor and Description |
|---|
SymbolTable() |
| Modifier and Type | Method and Description |
|---|---|
java.lang.Integer |
get(java.lang.String k)
Return the Integer associated with the variable name, k.
|
int |
getSize() |
java.util.List<SymbolTable.Symbol> |
inorder() |
static java.util.List<SymbolTable.Symbol> |
inorderRecursive(SymbolTable.Symbol current,
java.util.List<SymbolTable.Symbol> infix)
Similar to the infixRecursive method you implemented in the previous assignment.
|
(package private) static boolean |
isValidJavaIdentifier(java.lang.String k)
Identifies whether or not the variable is a legal Java identifier.
|
static void |
main(java.lang.String[] args) |
void |
put(java.lang.String k,
java.lang.Integer v)
If the variable is a legal Java identifier,
add the symbol and it's corresponding value into the SymbolTree.
|
public int getSize()
static boolean isValidJavaIdentifier(java.lang.String k)
Read section 3.8 from the following resource to learn how to identify legal Java identifiers: Lexical Structure
This includes checking to make sure the identifier is not a keyword, boolean literal, or null literal.
k - the variable nameCharacter.isJavaIdentifierStart(char),
Character.isJavaIdentifierPart(char)public void put(java.lang.String k,
java.lang.Integer v)
Here is the algorithm to add the symbol to the SymbolTree:
k - the symbol namev - the value to be associated with the symboljava.lang.RuntimeException - if k is not a valid Java identifier
use the following message: String.format("\"%s\" is not a valid Java identifier", k)public java.lang.Integer get(java.lang.String k)
k - the variable namejava.lang.RuntimeException - if k is not a legal Java identifier, use the following message:
String.format("\"%s\" is not a valid Java identifier", k)java.lang.RuntimeException - if the variable does not exist, use the following message
String.format("\"%s\" does not exist", k)public java.util.List<SymbolTable.Symbol> inorder()
public static java.util.List<SymbolTable.Symbol> inorderRecursive(SymbolTable.Symbol current, java.util.List<SymbolTable.Symbol> infix)
Instead of creating a String, add the Symbol to the ArrayList.
current - the current Symbolinfix - the ArrayListpublic static void main(java.lang.String[] args)