public TinyValue invoke(List <TinyUnityParser.ExpressionContext> args, Dictionary <string, TinyFunction> functions, Scope scope) { if (args == null) { return(invokeEmpty(functions, scope)); } if (args.Count() != this.parameters.Count()) { throw new ArgumentException("Attempted to call function with invalid arguments"); } Scope functionScope = new Scope(null); EvalVisitor evisitor = new EvalVisitor(scope, functions); for (int i = 0; i < this.parameters.Count(); i++) { TinyValue val = evisitor.Visit(args[i]); functionScope.assignParam(this.parameters[i].GetText(), val); } EvalVisitor evisitorNext = new EvalVisitor(functionScope, functions); //Do stuff TinyValue ret = TinyValue.NULL; try { evisitorNext.Visit(this.functionBlock); } catch (ReturnValue returnValue) { ret = returnValue.val; } return(ret); }
public TinyValue invokeEmpty(Dictionary <string, TinyFunction> functions, Scope scope) { Scope functionScope = new Scope(null); EvalVisitor evisitorNext = new EvalVisitor(functionScope, functions); //Do stuff TinyValue ret = TinyValue.NULL; try { evisitorNext.Visit(this.functionBlock); } catch (ReturnValue returnValue) { ret = returnValue.val; } return(ret); }
public void init(AntlrInputStream istream) { inputStream = istream; lexer = new TinyUnityLexer(inputStream); parser = new TinyUnityParser(new CommonTokenStream(lexer)); var ParseTree = parser.parse(); Scope globalScope = new Scope(); Dictionary <string, TinyFunction> functions = new Dictionary <string, TinyFunction>(); SymbolVisitor symVisitor = new SymbolVisitor(functions); symVisitor.Visit(ParseTree); EvalVisitor evalVisitor = new EvalVisitor(globalScope, functions); evalVisitor.Visit(ParseTree); }