コード例 #1
0
        public void AddDuplicatedLabelTest()
        {
            var table = new SymbolsTable();

            table.Add("Sym", 4);

            Assert.Throws <SymbolsException>(() => table.Add("Sym", 5));
        }
コード例 #2
0
        public void AddAndGetSymbolTest()
        {
            var table = new SymbolsTable();

            table.Add("Sym");
            Assert.Equal(16, table["Sym"]);
        }
コード例 #3
0
        public void AddAndGetLabelTest()
        {
            var table = new SymbolsTable();

            table.Add("Sym", 5);
            Assert.Equal(5, table["Sym"]);
        }
コード例 #4
0
        public void GetUndeclaredAndAddTest()
        {
            var table = new SymbolsTable();

            Assert.Equal(16, table.Get("Sym1"));
            table.Add("Sym1", 5);
            Assert.Equal(5, table.Get("Sym1"));
        }
コード例 #5
0
ファイル: Compressor.cs プロジェクト: ptorchilov/Cryptography
        private void CreateCodesTabel()
        {
            var unicode = 'а';

            for (var i = 0; i < 32; i++)
            {
                var code = Convert.ToString(i, 2);

                var codeLength = code.Length;

                if (codeLength < 5)
                {
                    for (var j = 0; j < 5 - codeLength; j++)
                    {
                        code = "0" + code;
                    }
                }

                SymbolsTable.Add((char)(unicode + i), code);
                CodesTable.Add(code, (char)(unicode + i));
            }
        }
コード例 #6
0
        public void Analysis(string inputText)
        {
            inputText = deleteReturnCorret(inputText);
            int lineCount  = 1;
            int spaceCount = 0;

            for (int i = 0; i < inputText.Length;)
            {
                while (i < inputText.Length && inputText[i] == ' ' && inputText[i] == '\t')
                {
                    spaceCount++;
                    if (inputText[i] == '\t')
                    {
                        spaceCount += 3;
                    }
                    i++;
                }

                if (Char.IsLetter(inputText[i]) || inputText[i] == '_')
                {
                    string temp = "";
                    while (i < inputText.Length && !symbols.ContainsKey(inputText[i]))
                    {
                        temp += inputText[i];
                        ++i;
                    }
                    if (words.ContainsKey(temp))
                    {
                        TokensTable.Add(new Token(Token.TokenType.WORD, temp, lineCount, spaceCount));
                    }
                    else
                    {
                        SymbolsTable.Add(new Symbol(temp));
                        TokensTable.Add(new Token(Token.TokenType.ID, (SymbolsTable.Count - 1).ToString(), lineCount, spaceCount));
                    }
                }
                else if (Char.IsDigit(inputText[i]))
                {
                    string temp = "";
                    while (i < inputText.Length && !symbols.ContainsKey(inputText[i]))
                    {
                        temp += inputText[i];
                        ++i;
                    }
                    TokensTable.Add(new Token(Token.TokenType.CONST, temp, lineCount, spaceCount));
                    if (temp.Contains('.'))
                    {
                        TokensTable[TokensTable.Count - 1].ConstType = Symbol.SymType.FLOAT;
                    }
                }
                else if (symbols.ContainsKey(inputText[i]))
                {
                    if (symbols[inputText[i]] == Symbols.QMARK || symbols[inputText[i]] == Symbols.QQMARK)
                    {
                        i++;
                        string temp = "";
                        while (i < inputText.Length && symbols[inputText[i]] != Symbols.QMARK && symbols[inputText[i]] != Symbols.QQMARK)
                        {
                            temp += inputText[i];
                            i++;
                        }
                        TokensTable.Add(new Token(Token.TokenType.CONST, temp, lineCount, spaceCount, Symbol.SymType.STRING));
                        i++;
                        spaceCount = 0;
                        continue;
                    }

                    if (symbols[inputText[i]] == Symbols.SRET)
                    {
                        lineCount++;
                    }
                    TokensTable.Add(new Token(Token.TokenType.SYMBOL, inputText[i].ToString(), lineCount, spaceCount));
                    i++;
                }
                else
                {
                    ErrorsTable.Add(new ErrorMessage($"Unexpected symbol: {inputText[i]}", lineCount));
                    return;
                }
                spaceCount = 0;
            }
        }