Esempio n. 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Circuit.Reset();
            string       expr   = LogicalExpression.Text;
            List <Token> tokens = new List <Token>();
            StringReader reader = new StringReader(expr);

            try
            {
                //Tokenize the expression
                Token t = null;
                do
                {
                    t = new Token(reader);
                    tokens.Add(t);
                } while (t.type != Token.TokenType.EXPR_END);

                //Use a minimal version of the Shunting Yard algorithm to transform the token list to polish notation
                List <Token> polishNotation = MyParser.TransformToPolishNotation(tokens);

                var enumerator = polishNotation.GetEnumerator();
                enumerator.MoveNext();
                exp = MyParser.Make(ref enumerator);

                exp.Paint(ct);
                //LogicalExpression.Text = exp.GetStringExp();
                var result = exp.Evaluate(ct);
                Circuit.AddLamp();
                Circuit.SwitchLamp(result);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Gabim ne shprehje: {ex.Message}");
            }
        }