Esempio n. 1
0
        public void Test4()
        {
            
            Tokenizer tokenizer = new Tokenizer();

            var tokenStream = tokenizer.Tokenize(@"NOT ax -> ay");
            ExpressionParser parser = new ExpressionParser();

            var statements = parser.GenerateStatements(tokenStream).ToList();
            Assert.AreEqual(1, statements.Count);
            Assert.AreEqual(new AssignStatement(new NotExpression(16, new VariableExpression("ax")), new VariableExpression("ay")), statements[0]);
        }
Esempio n. 2
0
        public void Test3()
        {
            Tokenizer tokenizer = new Tokenizer();

            var tokenStream = tokenizer.Tokenize(@"fe -> a
le -> NOT");
            ExpressionParser parser = new ExpressionParser();

            var statements = parser.GenerateStatements(tokenStream).ToList();
            Assert.AreEqual(2, statements.Count);
            Assert.AreEqual(new AssignStatement(new VariableExpression("le"), new VariableExpression("NOT")), statements[1]);
        }
Esempio n. 3
0
        public void CreateAssignAnd()
        {
            Tokenizer tokenizer = new Tokenizer();

            var tokenStream = tokenizer.Tokenize("x AND y -> d");
            ExpressionParser parser = new ExpressionParser();

            TokenConsumer consumer = new TokenConsumer(tokenStream);

            using (var scope = consumer.BeginScope())
            {
                var expression = ExpressionParser.CreateAssignExpression(scope);

                Assert.AreEqual(new AssignStatement(new AndExpression(16, new VariableExpression("x"), new VariableExpression("y")), new VariableExpression("d")), expression);
            }
        }
Esempio n. 4
0
        public void ValueOfa()
        {
            Tokenizer tokenizer = new Tokenizer();
            using (var stream = CreateResource())
            {
                var tokens = tokenizer.Tokenize(stream);
                var parser = new ExpressionParser();
                var statements = parser.GenerateStatements(tokens).ToList();

                var treeBuilder = new ExpressionDependecyBuilder();
                var expressionTree = treeBuilder.BuildExpressionTree(statements, "a");

                int value = expressionTree.CalcTree();

                Assert.AreEqual(46065, value);
            }
        }
Esempio n. 5
0
        public void ValueOfaWithbOverrided()
        {
            Tokenizer tokenizer = new Tokenizer();
            using (var stream = CreateResource())
            {
                var tokens = tokenizer.Tokenize(stream);
                var parser = new ExpressionParser();
                var statements = parser.GenerateStatements(tokens).ToList();

                var treeBuilder = new ExpressionDependecyBuilder();
                var expressionTree = treeBuilder.BuildExpressionTree(statements, "a");
                Dictionary<string, int> wireValues = new Dictionary<string, int>();
                wireValues.Add("b", 46065);
                int value = expressionTree.CalcTree(wireValues);

                Assert.AreEqual(14134, value);
            }
        }