示例#1
0
        private static void StripComments(ref StringSection line)
        {
            int iComment = line.IndexOf(';');

            if (iComment >= 0)
            {
                line = line.Substring(0, iComment);
            }
            line = line.Trim();
        }
示例#2
0
        private bool ParseNamedLabels(ref StringSection line, int iParsedLine, int iSourceLine)
        {
            int iColon = line.IndexOf(':');

            if (iColon < 0)
            {
                return(false);
            }

            if ((line.Length - 1 > iColon) && (line[iColon + 1] == '='))
            {
                // := is not a label
                return(false);
            }

            var labelName = line.Substring(0, iColon).Trim();

            // Todo: should be able to validate via a 'parse symbol' func

            // Check for nonzero length and that label starts with letter or @
            if (labelName.Length == 0)
            {
                return(false);
            }
            if (!char.IsLetter(labelName[0]) && labelName[0] != '@')
            {
                return(false);
            }

            for (int i = 1; i < labelName.Length; i++)   // i = 1 because we've already checked zero
            {
                if (!char.IsLetter(labelName[i]) && !char.IsDigit(labelName[i]) && labelName[i] != '_')
                {
                    return(false);
                }
            }

            if (labelName[0] == '@')                                                 // Local label
            {
                labelName = labelName.Substring(1);                                  // Remove @
                string fullName = mostRecentNamedLabel + "." + labelName.ToString(); // example: SomeFunction.LoopTop
                assembly.Labels.Add(new Label(fullName, iParsedLine, iSourceLine, true));
            }
            else     // Normal label
            {
                var sLabelName = labelName.ToString();
                mostRecentNamedLabel = sLabelName;
                assembly.Labels.Add(new Label(sLabelName, iParsedLine, iSourceLine, false));
            }
            line = line.Substring(iColon + 1).TrimLeft();

            return(true);
        }