//19. <关系表达式>—> <表达式> <关系> <表达式> TFexit relationexpression(){ Val v1 = expression(); int re = relation(); Val v2 = expression(); quadruples.push_back(Quadruple(sno++, re, v1, v2)); quadruples.push_back(Quadruple(sno++,0,Val(),Val()));//无条件跳转op=0 return TFexit(sno - 2, sno - 1); }
unsigned TopographyFile::GetSkipSteps(fixed map_scale) const { if (Quadruple(map_scale) > scale_threshold * 3) return 4; if (Double(map_scale) > scale_threshold) return 3; if (Quadruple(map_scale) > scale_threshold) return 2; return 1; }
//16.<项>—> <因子> [ *|/ <因子> ] Val Item(){ Val v1 = Factor(); while (lookahead == mutiply || lookahead == div){ int op = lookahead; if (op == mutiply) match(mutiply); else match(div); Val v2 = Factor(); quadruples.push_back(Quadruple(sno++, op == mutiply ? mutiply : div, v1, v2, temp)); //生成四元式 /*printf("%3d (%c,", sno++, op == mutiply ? '*' : '/'); if (v1.type == 1) printf("%s", GetNameByID(v1.value1)); else if (v1.type == 0) printf("%d", v1.value1); else if (v1.type == 2) printf("%lf", v1.value2); else printf("t%d", v1.value1); printf(","); if (v2.type == 1) printf("%s", GetNameByID(v2.value1)); else if (v2.type == 0) printf("%d", v2.value1); else if (v2.type == 2) printf("%lf", v2.value2); else printf("t%d", v2.value1); printf(",t%d)\n", temp);*/ v1.type = -1; v1.value1 = temp++; } return v1; }
//15.<表达式>—> <项> [ +|- <项> ] Val expression(){ Val v1 = Item(); while (lookahead == plus || lookahead == minus){ int op = lookahead; if (lookahead == plus) match(plus); else match(minus); Val v2 = Item(); quadruples.push_back(Quadruple(sno++, op == plus ? plus : minus, v1,v2,temp)); //生成四元式 /*printf("%3d (%c,", sno++, op == plus ? '+' : '-'); if (v1.type == 1) printf("%s", GetNameByID(v1.value1)); else if (v1.type == 0) printf("%d", v1.value1); else if (v1.type == 2) printf("%lf", v1.value2); else printf("t%d", v1.value1); printf(","); if (v2.type == 1) printf("%s", GetNameByID(v2.value1)); else if (v2.type == 0) printf("%d", v2.value1); else if (v2.type == 2) printf("%lf", v2.value2); else printf("t%d", v2.value1); printf(",t%d)\n", temp);*/ v1.type = -1; v1.value1 = temp++; } return v1; }
//13.<分支语句>—> if <布尔表达式> then <语句> //| if <布尔表达式> then <语句> else <语句> void switchStatement(){ if (lookahead == IF){ match(IF); TFexit tf = booleaexpression();//真假出口 match(THEN); //填真出口 BackPatch(tf.TC, sno); statementlists(); if (lookahead == ELSE){ // 1 无条件跳转 int j = sno; quadruples.push_back(Quadruple(sno++, 0,Val(),Val())); match(ELSE); //回填假出口 BackPatch(tf.FC, sno); statementlists(); //回填 1 无条件跳转 BackPatch(j, sno); } else { // 回填假出口 BackPatch(tf.FC, sno); } } else{ error(24); } }
//10.<赋值语句>—> id = <表达式> ; void assignment(){ char varname[MAXIDLEN]; strcpy(varname, token); Val v2 = Val(1, GetIdByName(varname)); match(id); if (!isexist(varname)){ strcpy(token, varname); error(46); } match(equl); Val v = expression(); match(semicolon); quadruples.push_back(Quadruple(sno++, equl, v, v2)); //生成四元式 /*printf("%3d (=,", sno++); if (v.type == 1) printf("%s", GetNameByID(v.value1)); else if (v.type == 0) printf("%d", v.value1); else if (v.type == 2) printf("%lf", v.value2); else printf("t%d", v.value1); printf(",%s)\n", varname);*/ }
void WindArrowRenderer::Draw(Canvas &canvas, const Angle screen_angle, const SpeedVector wind, const PixelPoint pos, const PixelRect rc, WindArrowStyle arrow_style) { // Draw arrow (and tail) const unsigned length = uround(Quadruple(wind.norm)); DrawArrow(canvas, pos, wind.bearing - screen_angle, length, arrow_style); // Draw wind speed label StaticString<12> buffer; buffer.Format(_T("%i"), iround(Units::ToUserWindSpeed(wind.norm))); canvas.SetTextColor(COLOR_BLACK); canvas.Select(*look.font); const unsigned offset = uround(M_SQRT2 * wind.norm); BulkPixelPoint label[] = { { 18, -26 - int(offset) }, }; PolygonRotateShift(label, ARRAY_SIZE(label), pos, wind.bearing - screen_angle); TextInBoxMode style; style.align = TextInBoxMode::Alignment::CENTER; style.vertical_position = TextInBoxMode::VerticalPosition::CENTERED; style.shape = LabelShape::OUTLINED; TextInBox(canvas, buffer, label[0].x, label[0].y, style, rc); }
void InfoBoxContentWindArrow::OnCustomPaint(Canvas &canvas, const PixelRect &rc) { const auto &info = CommonInterface::Calculated(); const RasterPoint pt = rc.GetCenter(); UPixelScalar padding = Layout::FastScale(10); UPixelScalar size = std::min(rc.right - rc.left, rc.bottom - rc.top); if (size > padding) size -= padding; // Normalize the size because the Layout::Scale is applied // by the DrawArrow() function again size = size * 100 / Layout::Scale(100); auto angle = info.wind.bearing - CommonInterface::Basic().attitude.heading; PixelScalar length = std::min(size, (UPixelScalar)std::max(10, iround(Quadruple(info.wind.norm)))); PixelScalar offset = -length / 2; auto style = CommonInterface::GetMapSettings().wind_arrow_style; WindArrowRenderer renderer(UIGlobals::GetLook().wind_arrow_info_box); renderer.DrawArrow(canvas, pt, angle, length, style, offset); }
fixed IGCWriter::GetEPE(const GPSState &gps) { /* * EPE (Estimated Position Error in meters) * based on Parkinson, Bradford W. Global Positioning System Theory and Applications Volume 1. * URE (User Range Error) is an estimate of "Signals in Space" errors, i.e., ephemeris data, * satellite clocks, ionospheric delay and tropospheric delay. These errors can be greatly * reduced by differential and multiple frequency techniques. Differential correction sources * include user provided reference stations, community base stations, governmental beacon * transmissions, FM sub-carrier transmissions and geosynchronous satellite transmissions. * UEE (User Equipment Errors) includes receiver noise, multipath, antenna orientation, * EMI/RFI. Receiver and antenna design can greatly reduce UEE error sources--usually at * substantial cost. * * Typical Error components of an autonomous (non Differential) GPS signal are: * Error Error in meters (autonomous) DGPS Type error * Ephemeris data 2.1 0 URE * Satellite clock 2.1 0 URE * Ionosphere 4 0.4 URE * Troposphere 0.7 0.2 URE * Multipath 1.4 1.4 UEE * Receiver measurement 0.5 0.5 UEE * * Autonomous: * EPE 2-sigma = EPE (2drms) = 2* HDOP * SQRT [URE^2 + UEE^2] = HDOP * 18.2 * * Differential: * EPE 2-sigma = EPE (2drms) = 2* HDOP * SQRT [URE^2 + UEE^2] = HDOP * 4.0 * Assumptions: XCSoar does not know any details about the hardware of the receiver, * so we assume the table above is a valid estimation. * * The WAAS function in the US does not set the DGPS flag * fix_quality * 1 = GPS fix (SPS) * 2 = DGPS fix * 3 = PPS fix * 4 = Real Time Kinematic * 5 = Float RTK * 6 = estimated (dead reckoning) (2.3 feature) * 7 = Manual input mode * 8 = Simulation mode */ switch (gps.fix_quality) { case FixQuality::GPS: return gps.hdop * fixed(18.2); case FixQuality::DGPS: return Quadruple(gps.hdop); default: return fixed(0); } }
unsigned TopographyFile::GetThinningLevel(fixed map_scale) const { if (Double(map_scale) > scale_threshold) return 3; if (map_scale * 3 > scale_threshold) return 2; if (Quadruple(map_scale) > scale_threshold) return 1; return 0; }
unsigned TopographyFile::GetMinimumPointDistance(unsigned level) const { switch (level) { case 1: return (unsigned)(Quadruple(scale_threshold) / 30); case 2: return (unsigned)(6 * scale_threshold / 30); case 3: return (unsigned)(9 * scale_threshold / 30); } return 1; }
//14.<循环语句>—> while <布尔表达式> do <语句> void loopStatement(){ match(WHILE); //int boolId = 序号全局变量 int boolId = sno; TFexit tf = booleaexpression();//真假出口 match(DO); //回填真出口 BackPatch(tf.TC, sno); statementlists(); //(j boolId) quadruples.push_back(Quadruple(sno++, 0, Val(), Val(), boolId)); //回填假出口 BackPatch(tf.FC, sno); }
void Code::generate(CodeOp op, SymbolTableEntry* arg1, SymbolTableEntry* arg2, SymbolTableEntry* result) { m_qList.push_back(Quadruple(op,arg1,arg2,result)); }