Exemplo n.º 1
0
        public List <Token> analizecCharsSequence(string charsSequence)
        {
            List <Token>    tokensList      = new List <Token>();
            CharsDictionary charsDictionary = new CharsDictionary();

            for (int index = 0; index < charsSequence.Length; index++)
            {
                string currentChar = charsSequence[index].ToString();

                if (Char.IsWhiteSpace(charsSequence[index]))
                {
                    tokensList.Add(new Token(index, TokenTypes.SPACE, currentChar));
                }
                else if (charsDictionary.lettersDictionary.ContainsKey(currentChar.ToLower()))
                {
                    tokensList.Add(new Token(index, TokenTypes.LETTER, currentChar));
                }
                else if (charsDictionary.numbersDictionary.ContainsKey(currentChar))
                {
                    tokensList.Add(new Token(index, TokenTypes.NUMBER, currentChar));
                }
                else if (charsDictionary.symbolsDictionary.ContainsKey(currentChar))
                {
                    tokensList.Add(new Token(index, TokenTypes.SYMBOL, currentChar));
                }
            }

            return(tokensList);
        }
Exemplo n.º 2
0
        public string parseToMorseCode(List <Token> tokensList)
        {
            CharsDictionary charsDictionary = new CharsDictionary();

            string morseCode = "";

            foreach (Token token in tokensList)
            {
                if (morseCode.Length > 0)
                {
                    morseCode += " ";
                }

                switch (token.type)
                {
                case TokenTypes.SPACE:
                    morseCode += "  ";
                    break;

                case TokenTypes.LETTER:
                    morseCode += charsDictionary.lettersDictionary[token.argument.ToLower()];
                    break;

                case TokenTypes.NUMBER:
                    morseCode += charsDictionary.numbersDictionary[token.argument];
                    break;

                case TokenTypes.SYMBOL:
                    morseCode += charsDictionary.symbolsDictionary[token.argument];
                    break;
                }
            }

            return(morseCode);
        }