public Interpreter(string input) { actionMap = new Dictionary<Statement_Types, lolAction> (); tokenList = new List<Token> (); TokenStream ts = new TokenStream (input); Token t; currentPosition = 0; variableTable = new SymbolTable (); functionTable = new FunctionTable(); lolIt = new LolIt (LOLType.NOOB, "", variableTable); variableTable.createVar ("IT", lolIt); errorFlag = false; while(!ts.end()){ t = ts.get (); MainClass.win.addLexemes (t.getValue (), t.getType ().ToString ()); if (t.getType () == TokenType.UNKNOWN) { MainClass.win.displayTextToConsole ("Unknown token: " + t.getValue ()); tokenList.Add (t); } else if ((t.getType () != TokenType.BTW && t.getType () != TokenType.OBTW)) { tokenList.Add (t); } } Parser p = new Parser (tokenList); if (!p.parse ()) { setError ("Error in parser"); }; tokToLolType = new Dictionary<TokenType, LOLType> (); tokToLolType.Add (TokenType.NUMBR_LITERAL, LOLType.NUMBR); tokToLolType.Add (TokenType.NUMBAR_LITERAL, LOLType.NUMBAR); tokToLolType.Add (TokenType.TROOF_LITERAL, LOLType.TROOF); tokToLolType.Add (TokenType.YARN_LITERAL, LOLType.YARN); addActionDefinitions (); actionList = p.getActionOrder (); }
void functionCall(int location) { LolFunction fun = functionTable.getFunction(tokenList[location + 1].getValue()); if(fun == null) { setError("Unknown function"); return; } int savePosition = currentPosition; SymbolTable saveVariable = variableTable; FunctionTable saveFunction = functionTable; List<lolValue> paramList = getActualParam(location); if(fun.parameters.Count != paramList.Count) { setError("Wrong number of parameters"); return; } variableTable = new SymbolTable (); functionTable = new FunctionTable(); for(int iii = 0; iii < paramList.Count; iii++) { variableTable.createVar(fun.parameters[iii], paramList[iii]) ; } currentPosition = fun.startLocation + 1; while(currentPosition < fun.endLocation) { actionMap [actionList[currentPosition].type] (actionList[currentPosition].location); currentPosition++; } currentPosition = savePosition; variableTable = saveVariable; functionTable = saveFunction; MainClass.win.refreshSymbol(variableTable); }