public static CompilerDataAllocationDirective ParseLine(string directiveLine) { var lineParts = directiveLine.Split(new char[] { ' ', '\t', ',' }, StringSplitOptions.RemoveEmptyEntries); // Ignore whitespace between the first token and the second if the second is a colon. Poorly formatted label. if (lineParts.Length > 2 && lineParts[1].Length == 1 && lineParts[1][0] == ':') { var respin = new List <string>(new string[] { lineParts.Take(2).Aggregate((c, n) => c + n) }); respin.AddRange(lineParts.Skip(2)); lineParts = respin.ToArray(); } string?label = null; if (SYMBOLS.Any(s => string.Compare(s, lineParts[0], StringComparison.InvariantCultureIgnoreCase) != 0 && SYMBOLS.Any(s => string.Compare(s, lineParts[1], StringComparison.InvariantCultureIgnoreCase) == 0))) { label = lineParts[0].TrimEnd(':'); } var labelIndex = (label == null) ? default(int?) : directiveLine.IndexOf(label); var mnemonic = labelIndex == null ? lineParts[0] : lineParts[1]; var mnemonicIndex = directiveLine.Substring(labelIndex ?? 0).IndexOf(mnemonic); var operandLine = directiveLine.Substring(mnemonicIndex + mnemonic.Length).TrimStart(' ', '\t'); var operands = AssemblerUtility.ParseOperandLine(operandLine).ToArray(); return(new CompilerDataAllocationDirective(label, mnemonic, operands)); }
public static bool TryResolveDataAllocationReference(string operandPart, Dictionary <string, IBytecodeDataSymbol> symbolOffsets, out ValueType result) { var unboxAttempt = AssemblerUtility.UnboxParsedOperand(operandPart); if (unboxAttempt is ValueType) { result = (ValueType)unboxAttempt; return(true); } else if (unboxAttempt.GetType() == typeof(string) && symbolOffsets.ContainsKey(operandPart.ToUpperInvariant())) { result = symbolOffsets[operandPart.ToUpperInvariant()].DataSegmentOffset; return(true); } result = 0; return(false); }