public object VisitCall(AST.Call Node) { string subname = (string)Node.SubroutineName.Value; if (!this.Subroutines.Keys.Contains(subname)) { this.Error( String.Format(Messages.UNDEFINED_FUNC, subname), Node.SubroutineName.Token.Position); } return(this.VisitSubroutineDeclaration(this.Subroutines[subname], Node)); }
public object VisitSubroutineDeclaration(AST.SubroutineDeclaration Node, AST.Call Call = null) { StackFrame sf = new StackFrame( (string)Node.SubroutineName.Value, this.CallStack.Peek().Level + 1, Node.Params, this.CallStack.Peek()); if (null != Call) { for (int i = 0; i < Call.Params.Count; i++) { string varname = (string)Node.Params[i].VariableNode.Value; string vartype = (string)Node.Params[i].TypeNode.Value; object value = this.ConvertAppr(this.Visit(Call.Params[i]), vartype); sf.Assign(varname, value); } } this.CallStack.Push(sf); this.VisitCompound(Node.Body); if (null == this.CallStack.Peek().ret) { this.Error( String.Format(Messages.MISSING_RETURN_STMT, Node.SubroutineName.Value), Node.SubroutineName.Token.Position); } object ret = (this.CallStack.Pop()).ret; string rettype = (string)Node.ReturnType.Value; return(this.ConvertAppr(ret, rettype)); }