/// <summary> /// /// </summary> /// <returns></returns> public TModule DoParse() { ProcedureBuilder p = new ProcedureBuilder("MAIN", new COMPILATION_CONTEXT()); ArrayList stmts = Parse(p); foreach (Stmt s in stmts) { p.AddStatement(s); } Procedure pc = p.GetProcedure(); prog.Add(pc); return(prog.GetProgram()); }
/// <summary> /// /// </summary> /// <returns></returns> public TModule DoParse() { try { ProcedureBuilder p = new ProcedureBuilder("MAIN", new COMPILATION_CONTEXT()); ArrayList stmts = Parse(p); foreach (Stmt s in stmts) { p.AddStatement(s); } Procedure pc = p.GetProcedure(); prog.Add(pc); return(prog.GetProgram()); } catch (Exception e) { Console.WriteLine(e.ToString()); return(null); } }
/// <summary> /// Parse A Single Function. /// </summary> /// <returns></returns> ProcedureBuilder ParseFunction() { // // Create a Procedure builder Object // ProcedureBuilder p = new ProcedureBuilder("", new COMPILATION_CONTEXT()); if (Current_Token != TOKEN.TOK_FUNCTION) { return(null); } 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)) { return(null); } //-------- 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) { return(null); } p.Name = this.last_str; // assign the name // ---------- Opening parenthesis for // the start of <paramlist> GetNext(); if (Current_Token != TOKEN.TOK_OPAREN) { return(null); } //---- Parse the Formal Parameter list FormalParameters(p); if (Current_Token != TOKEN.TOK_CPAREN) { return(null); } GetNext(); // --------- Parse the Function code ArrayList lst = StatementList(p); if (Current_Token != TOKEN.TOK_END) { throw new Exception("END expected"); } // Accumulate all statements to // Procedure builder // foreach (Stmt s in lst) { p.AddStatement(s); } return(p); }
/// <summary> /// Parse A Single Function. /// </summary> /// <returns></returns> protected ProcedureBuilder ParseFunction() { // // Create a Procedure builder Object // ProcedureBuilder p = new ProcedureBuilder("", new COMPILATION_CONTEXT()); 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 || Current_Token == TOKEN.TOK_ARRAY || Current_Token == TOKEN.TOK_MAP)) { throw new CParserException(-1, "A Legal data type expected ", SaveIndex()); } if (Current_Token == TOKEN.TOK_MAP || Current_Token == TOKEN.TOK_ARRAY) { throw new CParserException(-1, "Array / Map not supported as return value", SaveIndex()); } else { //-------- 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); }