public TranslatorRetval Translate(string program) { int lineNumber = 1; TranslatorRetval retval = new TranslatorRetval(); program = program + _crLf; _functions.Clear(); AddFunction(Functions.FuncInit); StartInitCode(); string[] lines = program.Replace('\r', '\n').Replace("\n\n", "\n").Split('\n'); Output = Output + "TheBasicStart nop" + _crLf; foreach (string line in lines) { if (string.IsNullOrEmpty(line) || string.IsNullOrEmpty(line.Trim())) { lineNumber++; continue; } TranslatorRetval lineRetval = TranslateLine(line, true); if (lineRetval.HasErrors) { retval.HasErrors = true; retval.ErrorLineNumber = lineNumber; retval.ErrorMessage = retval.ErrorMessage; return(retval); } lineNumber++; } Output = Output + " jmp TheBasicEnd" + _crLf; Output = Output + _functions.Aggregate("", (current, ss) => current + Routines.GetRoutine(ss)); Output = Output + "TheBasicEnd end TheBasicStart"; return(retval); }
private void btnTranslate_Click(object sender, EventArgs e) { txtAssembly.Text = ""; _variables.Clear(); var translator = new Translator(_variables); string[] lines = txtBasicProgram.Text.Replace('\r', '\n').Replace("\n\n", "\n").Split('\n'); string assembly = "TheBasicStart call TheBasicInit" + Environment.NewLine; _initcode = ""; SetupInitializationCode(); foreach (string line in lines) { if (string.IsNullOrEmpty(line) || string.IsNullOrEmpty(line.Trim())) { continue; } AssemblyRetVal retval = translator.TranslateLine(line, ref _initcode, true); _initcode = _initcode + retval.InitializationCode; assembly = assembly + retval.AssemblyCode; } assembly = assembly + " jmp TheBasicEnd" + Environment.NewLine; txtAssembly.Text = _initcode + GetVariablesInitializationCode() + assembly + translator.Functions.Aggregate("", (current, ss) => current + Routines.GetRoutine(ss)) + Routines.GetRoutine(Functions.FuncInit) + @"TheBasicEnd end TheBasicStart"; }