private String searchExpression() { FuncSymbol func; boolean flag = true; String expString = tokens[tIndex]; String tempStr = ""; tIndex++; if (tokens[tIndex].equalsIgnoreCase("from")) tokens[tIndex] = "equal to"; flag = false; while (true) { if ((tempStr = searchOperator(tIndex)) != null) { if (!tempStr.equalsIgnoreCase("plus plus") && !tempStr.equalsIgnoreCase("minus minus")) flag = true; expString = " " + tempStr; // Note: tIndex automatically incremented by searchOperator() method } else if (Controller.varSym.searchSymbol(tokens[tIndex]) != null /*|| TODO Check whether next token is number */) { if (flag == true) { flag = false; expString += " " + tokens[tIndex]; tIndex++; } else break; } else if ((func = Controller.funSym.searchSymbol(tokens[tIndex])) != null) { if (func.getParam().length == 0) { expString += (" " + tokens[tIndex]); flag = false; tIndex++; } else { int counter = 0; int index = tIndex + 1; VarSymbol var = null; expString += (" " + tokens[index] + " of"); while (counter < func.getParam().length && index < tokens.length) { if ((var = Controller.varSym.searchSymbol(tokens[index])) != null) { if (func.getParam()[counter].equals(var.getDataType())) { counter++; expString += (" " + tokens[index]); } } index++; } if (index == tokens.length) { // Error } else tIndex = index; } } // else // break; } return expString; }
private static boolean isParameter(VarSymbol var) { return (var.flags() & Flags.PARAMETER) != 0; }
/** * Make an item representing a local variable. * * @param v The represented variable. */ LocalItem makeLocalItem(VarSymbol v) { return new LocalItem(v.erasure(types), v.adr); }
private void for_loop() { VarSymbol v = null, tempVar = null; FuncSymbol f = null, tempFunc = null; int index = input.indexOf( words.get(wordLoc)); // Index in input string at which the word was encountered String expString = ""; index += (words.get(wordLoc).length() + 1); String str = input.substring(index); // Further processing will be done on this string tokens = str.split("[ ]+"); index = 0; boolean flag = false; String expression = null; String tempStr = null; String loopCounter = ""; while (true) { if ((v = Controller.varSym.searchSymbol(tokens[tIndex])) != null) /*|| (f = Controller.funSym.searchSymbol(tokens[tIndex])) != null*/ { loopCounter = v.getVarName(); // Holds the loopCounter variable expString = searchExpression(); expression = exp.generateExpression(expString); tempVar = v; } else if (tokens[tIndex].equalsIgnoreCase("to")) { // If next token is not an operator loopParams[0] = expression; tIndex++; int tempNum = NumberGenerator.stringToNum(tokens[tIndex]); // if((tempStr = String.valueOf(toNumber(tokens[tIndex++])))){ // TODO Method 'toNumber()' // to be added later if (String.valueOf(tempNum) != null) { condition = tempStr; loopParams[1] = loopCounter + "<" + condition; } else if ((v = Controller.varSym.searchSymbol(tokens[tIndex])) != null || (Controller.funSym.searchSymbol(tokens[tIndex]) != null)) { tempStr = searchExpression(); String tempString = exp.generateExpression(tempStr); int len = v.getVarName().length(); if (tempString.startsWith(loopCounter) && tempString.charAt(len) == '=') { condition = tempString.substring(len + 1); loopParams[1] = loopCounter + "<" + condition; } else { condition = tempString; loopParams[1] = condition; } } } else if (tokens[tIndex].equalsIgnoreCase("increment") || (tokens[tIndex] + tokens[tIndex + 1]).equalsIgnoreCase("plusplus") || tokens[tIndex].equalsIgnoreCase("postincrement") || tokens[tIndex].equalsIgnoreCase("preincrement")) { expression = exp.generateExpression((str.substring(str.indexOf(tokens[tIndex])))); loopParams[2] = expression; break; } else if (tokens[tIndex].equalsIgnoreCase("decrement") || (tokens[tIndex] + tokens[tIndex + 1]).equalsIgnoreCase("minus minus") || tokens[tIndex].equalsIgnoreCase("postdecrement") || tokens[tIndex].equalsIgnoreCase("predecrement")) { expression = exp.generateExpression((str.substring(str.indexOf(tokens[tIndex])))); loopParams[2] = expression; break; } /*if(searchOperator(tIndex) != -1){ //TODO Index variable missing error to be handled }*/ /* if(token is number){ number handling logic. e.g : for loop 0 to 100. } */ if ((tIndex) == tokens.length) { break; } } if (loopParams[2] == null) { loopParams[2] = loopCounter + "++"; } code.setCodeText("for(" + loopParams[0] + ";" + loopParams[1] + ";" + loopParams[2] + ")"); code.setErrCode(IErrorCodes.SUCCESS); code.setErrParam(null); }
public String toString() { return value.enclClass() + "." + value; // qualified name }
/** * Enter a constant into symbol table. * * @param name The constant's name. * @param type The constant's type. */ private VarSymbol enterConstant(String name, Type type) { VarSymbol c = new VarSymbol(PUBLIC | STATIC | FINAL, names.fromString(name), type, predefClass); c.constValue = type.constValue; predefClass.members().enter(c); return c; }