/// <summary> /// Parse A Single Function. /// </summary> /// <returns></returns> ProcedureBuilder ParseFunction2() { COMPILATION_CONTEXT cnt = new COMPILATION_CONTEXT(); foreach (KeyValuePair <string, SYMBOL_INFO> temp in _rules) { cnt.TABLE.Add(temp.Value); } // // Create a Procedure builder Object // We are passing the method "CollectSymbols" functions as parameters // All the Symbol Table Lookup in the ProcedureBuilder will be // captured by CollectSymbols // ProcedureBuilder p = new ProcedureBuilder("", cnt, CollectSymbols); if (Current_Token != TOKEN.TOK_FUNCTION) { throw new CParserException(-1, "FUNCTION expected ", SaveIndex()); } GetNext(); // return type of the Procedure ought to be // Boolean , Numeric or String if (!(Current_Token == TOKEN.TOK_VAR_BOOL || Current_Token == TOKEN.TOK_VAR_NUMBER || Current_Token == TOKEN.TOK_VAR_STRING)) { throw new CParserException(-1, "A Legal data type expected ", SaveIndex()); } //-------- Assign the return type p.TYPE = (Current_Token == TOKEN.TOK_VAR_BOOL) ? TYPE_INFO.TYPE_BOOL : (Current_Token == TOKEN.TOK_VAR_NUMBER) ? TYPE_INFO.TYPE_NUMERIC : TYPE_INFO.TYPE_STRING; // Parse the name of the Function call GetNext(); if (Current_Token != TOKEN.TOK_UNQUOTED_STRING) { throw new CParserException(-1, "Function name expected ", SaveIndex()); } p.Name = this.last_str; // assign the name // ---------- Opening parenthesis for // the start of <paramlist> GetNext(); if (Current_Token != TOKEN.TOK_OPAREN) { throw new CParserException(-1, "Opening Parenthesis expected", SaveIndex()); } //---- Parse the Formal Parameter list FormalParameters(p); if (Current_Token != TOKEN.TOK_CPAREN) { throw new CParserException(-1, "Closing Parenthesis expected", SaveIndex()); } GetNext(); // --------- Parse the Function code ArrayList lst = StatementList(p); if (Current_Token != TOKEN.TOK_END) { throw new CParserException(-1, "END expected", SaveIndex()); } // Accumulate all statements to // Procedure builder // foreach (Stmt s in lst) { p.AddStatement(s); } return(p); }