示例#1
0
文件: Program.cs 项目: zeul72/YAMEP
        static void Main(string[] args)
        {
            //var funcAST = new FunctionASTNode( new Token( Token.TokenType.Identifier, 0, "Good_Func_1"));
            //var arg = new NumberASTNode( new Token(Token.TokenType.Number,0, "5"));
            //funcAST.ArgumentNodes.Add( arg );

            var expEngine = new ExpressionEngine();

            expEngine.AddFunctions <MyFunctions>( );

            var result1 = expEngine.Evaluate("Good_Func_1( 5 )");


            var result2 = expEngine.Evaluate("Good_Func_2( 5, 5 )");
        }
示例#2
0
文件: Program.cs 项目: zeul72/YAMEP
        static void Main(string[] args)
        {
            var expression = "1 + 2 - 3 * 4 / 5";


            var lexer = new Lexer(new SourceScanner(expression));

            Console.WriteLine($"Lexing expression: {expression}");

            Token token = null;

            do
            {
                token = lexer.ReadNext( );
                Console.WriteLine($"Found Token Type {token.Type} at Position {token.Position} with a value of {token.Value}");
            } while(token.Type != Token.TokenType.EOE);


            var expressions = new string[] {
                "1 + 2",        //3
                "2 * 3",        //5
                "1 + 2 * 3",    //7
                "1",
                "1 / 2"
            };

            var expressionEngine = new ExpressionEngine();

            foreach (var e in expressions)
            {
                Console.WriteLine($"{e} = {expressionEngine.Evaluate( e )}");
            }
        }