public void BuildTree_EmptyExpression_ReturnsEmptyExpressionTree()
        {
            List <Token> tokens = new List <Token>();

            EndOfTokenStreamException exception = Assert.Throws <EndOfTokenStreamException>(
                () => builder.BuildTree(new Tokens(tokens))
                );

            Assert.AreEqual("Unexpected end of token stream", exception.Message);
        }
예제 #2
0
        public static SyntaxNode ParseExpression(string expression, Environment environment)
        {
            SyntaxTreeBuilder builder = new SyntaxTreeBuilder();
            SyntaxNode        root    = builder.BuildTree(Lexer.Lex(new RawExpression(expression)));

            return(SemanticAnalyzer.Analyze(root, environment));
        }
        public void BuildTree_SimpleExpression_ReturnsIdentifierNode()
        {
            List <Token> tokens = new List <Token>
            {
                new Token(TokenType.Identifier, "a"),
            };

            SyntaxNode node = builder.BuildTree(new Tokens(tokens));

            Assert.AreEqual("a", node.ToString());
        }