// Lexical scanner private void Scan() { int k; while (Cradle.Look == Cradle.CR) { Cradle.Fin(); } if (Cradle.IsAlpha(Cradle.Look)) { GetName(); } else if (Cradle.IsDigit(Cradle.Look)) { GetNum(); } else if (IsOp(Cradle.Look)) { GetOp(); } else { Value = Cradle.Look.ToString(); Token = SymType.Operator; Cradle.GetChar(); } Cradle.SkipWhite(); }
// Get a number private void GetNum() { Value = ""; if (!Cradle.IsDigit(Cradle.Look)) { Cradle.Expected("Integer"); } while (Cradle.IsDigit(Cradle.Look)) { Value += Cradle.Look; Cradle.GetChar(); } Token = SymType.Number; }
// Parse and translate the first math factor private void SignedFactor() { if (Cradle.Look == '+') Cradle.GetChar(); if (Cradle.Look == '-') { Cradle.GetChar(); if (Cradle.IsDigit(Cradle.Look)) Cradle.EmitLn("MOVE #-" + Cradle.GetNum() + ",D0"); else { Factor(); Cradle.EmitLn("NEG D0"); } } else Factor(); }