private void printTokenList() { if (this.trace) { for (Token<?> t : this.tokenList) { System.out.print(t.getLexeme() + " "); } System.out.println(); } }
public Expression getResult() { // execute literal expression while (this.execute() > 0) {; } Map<String, Integer /* counter */> variables = new LinkedHashMap<String, Integer>(); Map<String, Integer /* counter */> methods = new HashMap<String, Integer>(); for (Token<?> token : this.tokenList) { switch (token.getType()) { case Variable: String varName = token.getLexeme(); if (!variables.containsKey(varName)) { variables.put(varName, 1); } else { variables.put(varName, variables.get(varName) + 1); } break; case Delegate: DelegateToken delegateToken = (DelegateToken) token; if (delegateToken.getDelegateTokenType() == DelegateTokenType.Method_Name) { Token<?> realToken = delegateToken.getToken(); if (realToken.getType() == TokenType.Variable) { String methodName = token.getLexeme(); if (!methods.containsKey(methodName)) { methods.put(methodName, 1); } else { methods.put(methodName, methods.get(methodName) + 1); } } } else if (delegateToken.getDelegateTokenType() == DelegateTokenType.Array) { Token<?> realToken = delegateToken.getToken(); if (realToken.getType() == TokenType.Variable) { varName = token.getLexeme(); if (!variables.containsKey(varName)) { variables.put(varName, 1); } else { variables.put(varName, variables.get(varName) + 1); } } } break; } } // call asm to generate byte codes this.callASM(variables, methods); // Last token is a literal token,then return a LiteralExpression if (this.tokenList.size() <= 1) { if (this.tokenList.isEmpty()) { return new LiteralExpression(null, new ArrayList<String>(variables.keySet())); } final Token<?> lastToken = this.tokenList.get(0); if (this.isLiteralToken(lastToken)) { return new LiteralExpression( this.getAviatorObjectFromToken(lastToken).getValue(null), new ArrayList<String>(variables.keySet())); } } // get result from asm return this.asmCodeGenerator.getResult(); }