From f028ea6dc555fc5192a96b00b8e96e90dbf6de55 Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Mon, 9 Oct 2017 16:02:10 -0300 Subject: TODO tagging --- dice-lang/src/bjc/dicelang/expr/Tokens.java | 50 +++++++++++++---------------- 1 file changed, 22 insertions(+), 28 deletions(-) (limited to 'dice-lang/src/bjc/dicelang/expr/Tokens.java') diff --git a/dice-lang/src/bjc/dicelang/expr/Tokens.java b/dice-lang/src/bjc/dicelang/expr/Tokens.java index f763d37..287d2b4 100644 --- a/dice-lang/src/bjc/dicelang/expr/Tokens.java +++ b/dice-lang/src/bjc/dicelang/expr/Tokens.java @@ -11,43 +11,39 @@ import java.util.Map; * */ public class Tokens { - /* - * Contains mappings from variable references to string names. - */ + /* Contains mappings from variable references to string names. */ private final Map symTab; - /* - * Reverse index into the symbol table. - */ + /* Reverse index into the symbol table. */ private final Map revSymTab; - /** - * Read-only view on the symbol table. - */ + /** Read-only view on the symbol table. */ public final Map symbolTable; - /* - * Next index into the symbol table. - */ + /* Next index into the symbol table. */ private int nextSym; - /* - * Mapping from literal tokens to token types. - */ + /* Mapping from literal tokens to token types. */ private final Map litTokens; - /** - * Create a new set of tokens. - */ + /** Create a new set of tokens. */ public Tokens() { + /* Create tables. */ symTab = new HashMap<>(); revSymTab = new HashMap<>(); + /* Init public view. */ symbolTable = Collections.unmodifiableMap(symTab); + /* Set sym ID. */ nextSym = 0; + /* + * Setup literal mappings. + * + * @NOTE + * Should this be a static member? + */ litTokens = new HashMap<>(); - litTokens.put("+", TokenType.ADD); litTokens.put("-", TokenType.SUBTRACT); litTokens.put("*", TokenType.MULTIPLY); @@ -68,32 +64,30 @@ public class Tokens { */ public Token lexToken(final String tok, final String raw) { if (litTokens.containsKey(tok)) { + /* Return matching literal token. */ return new Token(litTokens.get(tok), raw, this); } + /* Its a variable reference. */ return parseVRef(tok, raw); } - /* - * Parse a variable reference. - */ + /* Parse a variable reference. */ private Token parseVRef(final String tok, final String raw) { final Token tk = new Token(TokenType.VREF, raw, this); if (revSymTab.containsKey(tok)) { - /* - * Reuse the entry if it exists. - */ + /* Reuse the entry if it exists. */ tk.intValue = revSymTab.get(tok); } else { - /* - * Create a new entry. - */ + /* Create a new entry. */ tk.intValue = nextSym; + /* Record it. */ symTab.put(nextSym, tok); revSymTab.put(tok, nextSym); + /* Next ID. */ nextSym += 1; } -- cgit v1.2.3