Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            Tokenizer    T     = new Tokenizer(readFile("../../terminals.txt"));
            ShuntingYard N     = new ShuntingYard();
            string       input = "";
            int          i     = 1;

            input = Console.ReadLine();
            Console.WriteLine("Printing out the typed input: " + input);
            T.setInput(input);
            var tok = T.next();

            while (tok.Symbol != "$")
            {
                string entry = "Node" + i.ToString();
                N.addNode(entry, tok);
                if (tok.Symbol == "$")
                {
                    Console.WriteLine("Reached EOF");
                    break;
                }
                Console.WriteLine("Input:\n" + input);
                Console.WriteLine("\tok:" + tok);
                String sym = tok.Symbol;


                tok = T.next();
                i++;
            }
            Console.WriteLine("Printing Nodes:");
            foreach (TreeNode node in N.children)
            {
                Console.WriteLine(" " + node.sym + " tok.sym " + node.token.Symbol);
            }
        }
Exemplo n.º 2
0
        public void ConvertToPostFixedTest()
        {
            ShuntingYard target = new ShuntingYard();
            Tokens tokens = new Tokens("3*4 - 5*(4-3*3)");
            ReturnMessage actual = target.ConvertToPostFixed(tokens.AsList());

            ReturnMessage expected = new ReturnMessage(true,
                    new List<Token>() {
                    new Token("3", TokenType.numberLiteral),
                    new Token("4", TokenType.numberLiteral),
                    new Token("*", TokenType.operatorOrPunctuation),
                    new Token("-5", TokenType.numberLiteral),
                    new Token("4", TokenType.numberLiteral),
                    new Token("-3", TokenType.numberLiteral),
                    new Token("3", TokenType.numberLiteral),
                    new Token("*", TokenType.operatorOrPunctuation),
                    new Token("+", TokenType.operatorOrPunctuation),
                    new Token("*", TokenType.operatorOrPunctuation),
                    new Token("+", TokenType.operatorOrPunctuation),
                    });
            List<Token> returnedTokens = (List<Token>)actual.ReturnValue;
            List<Token> expectedTokens = (List<Token>)expected.ReturnValue;
            for(int i=0;i < returnedTokens.Count;i++){
                Assert.AreEqual<string>(returnedTokens[i].TokenString, expectedTokens[i].TokenString);
                Assert.AreEqual(returnedTokens[i].TokenType, expectedTokens[i].TokenType);
            }
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            Tokenizer    T     = new Tokenizer(readFile("../../terminals.txt"));
            ShuntingYard N     = new ShuntingYard();
            string       input = "";
            int          i     = 1;

            input = Console.ReadLine();
            Console.WriteLine("Printing out the typed input: " + input);
            T.setInput(input);
            var tok = T.next();

            while (tok.Symbol != "$")
            {
                //i need to turn entry into precedence
                i = ShuntingYard.precedence(tok.Symbol);
                string precedence = i.ToString();
                N.addNode(precedence, tok);
                if (tok.Symbol == "$")
                {
                    Console.WriteLine("Reached EOF");
                    break;
                }
                tok = T.next();
            }
            Console.WriteLine("Printing Nodes:");
            foreach (TreeNode node in N.children)
            {
                Console.WriteLine(" " + node.sym + " tok.sym " + node.token.Symbol);
            }
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            Tokenizer T = new Tokenizer(readFile("../../../terminals.txt"));

            string input = Console.ReadLine();

            ShuntingYard N = new ShuntingYard(T, input);
        }
Exemplo n.º 5
0
        public void AddListOfTokensTest()
        {
            ShuntingYard sy = new ShuntingYard();
            Tokens tokens = new Tokens("Tan(3*4 - 5*(4-3*3))");
            List<Token> postFixed = (List<Token>)sy.ConvertToPostFixed(tokens.AsList()).ReturnValue;

            ParseTree actual = (ParseTree)new ParseTree().AddListOfTokens(
                                postFixed).ReturnValue;

            Debug.Print(actual.Visualize());
            //Assert.Inconclusive("Check the output window and see if the result is correct");
        }