Exp TranslateDeclaration(FunctionDeclaration dec)
            {
                List <SymbolTable.Symbol> list = new List <SymbolTable.Symbol>();

                for (FunctionDeclaration d = dec; d != null; d = d.Next)
                {
                    if (Env.ValueEnvironment[d.Name] != null && Env.ValueEnvironment[d.Name] is StandardFunctionEntry)
                    {
                        Error.Report(d.Pos, "Function in standard libaray cannot be redefined");
                    }
                    else if (list.Contains(d.Name))
                    {
                        Error.Report(d.Pos, "Function cannot be redefined in a sequence");
                    }
                    else
                    {
                        list.Add(d.Name);
                        Types.Type      result  = d.Result == null ? Types.Type._void : TranslateType(d.Result).Actual;
                        Types.RECORD    formals = TranslateTypeFields(d.Param);
                        Label           label   = new Label(d.Name + "_" + Count++.ToString());
                        Translate.Level level   = new Translate.Level(Level, label, BoolList.BuildFromFieldList(d.Param));
                        Env.ValueEnvironment[d.Name] = new FunctionEntry(level, label, formals, result);
                    }
                }
                for (FunctionDeclaration d = dec; d != null; d = d.Next)
                {
                    FunctionEntry function = Env.ValueEnvironment[d.Name] as FunctionEntry;
                    Env.ValueEnvironment.BeginScope();
                    Env.LoopEnvironment.BeginScope();
                    Translate.Level backup = Level;
                    Level = function.Level;
                    Translate.AccessList al = Level.Formals.Tail;
                    for (FieldList field = d.Param; field != null; field = field.Tail, al = al.Tail)
                    {
                        Types.Type type = Env.TypeEnvironment[field.Type] as Types.Type;
                        if (type == null)
                        {
                            Error.Report(field.Pos, "Undefined type '" + field.Name + "'");
                        }
                        else
                        {
                            Translate.Access access = new Translate.Access(Level, al.Head.Acc);
                            Env.ValueEnvironment[field.Name] = new VariableEntry(access, type.Actual);
                        }
                    }
                    ExpressionType et = TranslateExpression(d.Body);
                    Translate.ProcessEntryExit(Level, et.Exp, !(et.Type.CoerceTo(Types.Type._void)));
                    if (!et.Type.CoerceTo((Env.ValueEnvironment[d.Name] as FunctionEntry).Result))
                    {
                        Error.Report(d.Result != null ? d.Result.Pos : d.Body.Pos, "Type mismatched for function return value");
                    }
                    Env.ValueEnvironment.EndScope();
                    Env.LoopEnvironment.EndScope();
                    Level = backup;
                }
                return(Translate.TranslateNoOp());
            }