コード例 #1
0
        static void TestIOModule()
        {
            var errorDigest = ReadErrorDigest();
            var errorTable  = new ErrorTable(errorDigest, 59);

            var    errorFile = new StreamReader(@".\errors.txt");
            string line;

            while ((line = errorFile.ReadLine()) != null)
            {
                var lineParts = line.Split();
                var row       = int.Parse(lineParts[0]);
                var position  = int.Parse(lineParts[1]);
                var code      = int.Parse(lineParts[2]);
                errorTable.Add(row - 1, new Error {
                    Position = position, Code = code, Message = errorDigest[code]
                });
            }
            errorFile.Close();

            // Прочитать файл с исходным кодом
            var  ioModule = new IOModule(errorTable, @".\1.pas", @".\listing.txt");
            char?ch;

            while ((ch = ioModule.NextCh()) != null)
            {
                // TODO: лексический анализатор
            }
        }
コード例 #2
0
        public void NextSymbol()
        {
            if (symbolQueue.Count > 0)
            {
                CurrentSymbol = symbolQueue.Dequeue();
                return;
            }

            while (currentCharacter != null && (currentCharacter == ' ' || currentCharacter == '\n'))
            {
                currentCharacter = ioModule.NextCh();
            }

            if (currentCharacter == null)
            {
                IsFinished = true;
                return;
            }

            CurrentLineNumber     = ioModule.CurrentRow;
            CurrentPositionInLine = ioModule.CurrentPosition;
            Error = null;

            ScanSymbol();

            if (Error != null)
            {
                SkipToNextSymbol();
            }

            if (currentCharacter == null)
            {
                IsFinished = true;
                return;
            }
        }