public static byte[] Tokenize(BASICProgram program, ref CompilerSettings compilerSettings) { var NextLineAddress = compilerSettings.BaseAddress; var output = new List <byte> { (byte)(NextLineAddress & 0x00ff), (byte)((NextLineAddress & 0xff00) >> 8) }; foreach (var line in program.Lines) { var bytes = TokenizeLine(line); NextLineAddress = NextLineAddress + bytes.Count; output.Add((byte)(NextLineAddress & 0x00ff)); output.Add((byte)((NextLineAddress & 0xff00) >> 8)); foreach (var b in bytes) { output.Add(b); } } //Pad end output.Add(0x00); output.Add(0x00); return(output.ToArray()); }
/// <summary> /// Tokenizes an entire BASIC program /// </summary> /// <returns>The tokenize.</returns> /// <param name="program">Program.</param> /// <param name="compilerSettings">Compiler settings.</param> public static byte[] Tokenize(BASICProgram program, ref CompilerSettings compilerSettings) { Output = new List <byte>(); Lines = new List <OptimizedBASICLine>(); NextLineAddress = compilerSettings.BaseAddress; ThisLineAddress = NextLineAddress; //Adding our load address, essentially Output.Add((byte)(NextLineAddress & 0x00ff)); Output.Add((byte)((NextLineAddress & 0xff00) >> 8)); //Process every line in the file to an optimizedBASIC Line. foreach (var line in program.Lines) { CurrentLine = new OptimizedBASICLine() { OriginalLine = line, BaseAddress = ThisLineAddress, LineNumber = line.Line_Number }; //Get tokenized bytes for this line var tokenizedLineBytes = TokenizeLine(line); CurrentLine.Tokenized = tokenizedLineBytes; //Build the line header (pointer to the next line) NextLineAddress = NextLineAddress + tokenizedLineBytes.Count; Output.Add((byte)(NextLineAddress & 0x00ff)); Output.Add((byte)((NextLineAddress & 0xff00) >> 8)); //Now add our tokenized line Output.AddRange(tokenizedLineBytes); Lines.Add(CurrentLine); ThisLineAddress = NextLineAddress; } var serializedLines = JsonConvert.SerializeObject(Lines); File.WriteAllText("test.json", serializedLines); //Pad end with zeroes Output.Add(0x00); Output.Add(0x00); return(Output.ToArray()); }
public BASICProgram PreProcess(List <string> prgLines, ref CompilerSettings CompilerSettings) { //Stash our settings compilerSettings = CompilerSettings; //First pass, just put them in a list with sourcefileLne var pass0Lines = ProcessStringList(prgLines); //Do compiler macros, settings, tags var pass1Lines = HandleCompilerTagsAndMacros(pass0Lines); //Strip out comments var pass2Lines = StripComments(pass1Lines); var basicProgram = HandleRemainingTags(pass2Lines); if (InjectLineNumbers(ref basicProgram)) { //This needs to be revisited - if you remove a line with REM //And a goto refers to it, the goto needs to be updated. //Because of this, removeREM should probably happen AFTER line-numberization. if (compilerSettings.RemoveREM) { //Strip anything after REM in this line // lineText = Utils.StripREM(lineText); } //Are we crunching? Figure out which lines can be crunched if (compilerSettings.Crunch) { var crunchedProgram = Crunch(basicProgram); basicProgram = crunchedProgram; } } return(basicProgram); }