public static Token LogError(string fileName, Token token, string message, int lineNo) { int col = 0; if (token != null) { col = token.Col; } else { if (LastToken != null) { if (LastToken.Next != null) { col = LastToken.Col; } else { col = LastToken.Col; } } } if (lineNo >= 0) { ErrorTable.Add(fileName, currentLine, token, message); } // OnErrorLogged(SourceDocument, new LogErrorEventArgs(token, message, col, lineNo)); if (token != null) { return(token.Next); } return(token); }
static bool EOL(Token token) { if (token == null) { return(true); } if (token.Next != null) { if (!ErrorTable.HasErrors(currentFileName)) { LogError(currentFileName, token, "Unwanted characters at end of line! " + token.Value + " " + token.Next.Value); } return(false); } return(true); }
public static Symbol Add(string fileName, int line, Token token, string name, int value) { if (Labels.Exists(x => x.FileName == fileName && x.Name == name)) { Symbol s1 = new Symbol(fileName, name, token, value, -1); s1.UsedAtLines.Add(new UsedAt(fileName, token.Line, token)); Labels.Add(s1); ErrorTable.Add(fileName, line, token, "Duplicate Label"); return(null); } Symbol label = new Symbol(fileName, name, token, value, line); Labels.Add(label); return(label); }
static bool Pass(int pass, string source) { FirstAddress = -1; //LogError(currentFileName, null,"Pass" + PassNo.ToString(), -1); maxtext = 0; sb = new StringBuilder(); bytes = new List <string>(); sourcelines = new List <string>(); IsTerminal = false; Cancelled = false; currentPass = pass; terminate = false; currentLine = 0; ProgramCounter = 0; ErrorTable.Reset(); Memory = new int[0x10000]; for (int i = 0; i < 0x10000; i++) { Memory[i] = -1; } string[] lines; if (source.Contains("\r\n")) { source = source.Replace("\r", ""); } //lines = source.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); lines = source.Split('\n'); foreach (string line in lines) { if (ProgramCounter > 0xffff) { break; } startaddress = ProgramCounter; currenttext = line; currentLine++; AssembleLine(line); if (pass == 2) { sourcelines.Add(currenttext); int length = ProgramCounter - startaddress; StringBuilder textsb = new StringBuilder(); if (length > 0) { switch (lastTokenType) { case TokenType.Directive: case TokenType.Preprocessor: textsb.Append(" " + " "); break; case TokenType.Label: case TokenType.Symbol: case TokenType.Opcode: textsb.Append(startaddress.ToString("X4") + " "); break; default: textsb.Append(startaddress.ToString("X4") + " "); break; } int newline = 0; for (int i = 0; i < length; i++) { if (newline > 15) { sourcelines.Add("{''}"); currentLine++; if (textsb.Length > maxtext) { maxtext = textsb.Length + 1; } bytes.Add(textsb.ToString()); textsb = new StringBuilder(); textsb.Append((startaddress + i).ToString("X4") + " "); newline = 0; } if (Memory[startaddress + i] != -1) { textsb.Append(Memory[startaddress + i].ToString("X2") + " "); newline++; } if (textsb.Length > maxtext) { maxtext = textsb.Length + 1; } } } bytes.Add(textsb.ToString()); OnAssembledLine(null, new AssembledLineEventArgs(ProgramCounter - length, length)); } //if (ErrorTable.HasErrors) break; if (IsTerminal) { break; } if (terminate) { break; } if (Cancelled) { break; } } return(!ErrorTable.HasErrors(currentFileName)); }