/// <summary> /// /// </summary> /// <param name="pb"></param> /// <returns></returns> public Stmt ParseReturnStatement(ProcedureBuilder pb) { GetNext(); Exp exp = BExpr(pb); if (Current_Token != TOKEN.TOK_SEMI) { CSyntaxErrorLog.AddLine("; expected"); CSyntaxErrorLog.AddLine(GetCurrentLine(SaveIndex())); throw new CParserException(-100, " ; expected", -1); } pb.TypeCheck(exp); return(new ReturnStatement(exp)); }
/// <summary> /// /// </summary> /// <param name="pb"></param> /// <returns></returns> public Stmt ParseIfStatement(ProcedureBuilder pb) { GetNext(); ArrayList true_part = null; ArrayList false_part = null; Exp exp = BExpr(pb); // Evaluate Expression if (pb.TypeCheck(exp) != TYPE_INFO.TYPE_BOOL) { throw new Exception("Expects a boolean expression"); } if (Current_Token != TOKEN.TOK_THEN) { CSyntaxErrorLog.AddLine(" Then Expected"); CSyntaxErrorLog.AddLine(GetCurrentLine(SaveIndex())); throw new CParserException(-100, "Then Expected", SaveIndex()); } GetNext(); true_part = StatementList(pb); if (Current_Token == TOKEN.TOK_ENDIF) { return(new IfStatement(exp, true_part, false_part)); } if (Current_Token != TOKEN.TOK_ELSE) { throw new Exception("ELSE expected"); } GetNext(); false_part = StatementList(pb); if (Current_Token != TOKEN.TOK_ENDIF) { throw new Exception("END IF EXPECTED"); } return(new IfStatement(exp, true_part, false_part)); }
/// <summary> /// /// </summary> /// <param name="pb"></param> /// <returns></returns> public Stmt ParseWhileStatement(ProcedureBuilder pb) { GetNext(); Exp exp = BExpr(pb); if (pb.TypeCheck(exp) != TYPE_INFO.TYPE_BOOL) { throw new Exception("Expects a boolean expression"); } ArrayList body = StatementList(pb); if ((Current_Token != TOKEN.TOK_WEND)) { CSyntaxErrorLog.AddLine("Wend Expected"); CSyntaxErrorLog.AddLine(GetCurrentLine(SaveIndex())); throw new CParserException(-100, "Wend Expected", SaveIndex()); } return(new WhileStatement(exp, body)); }