Beispiel #1
0
        public void ParseAddressWithOffset()
        {
            var t_Rule = new RulePatternRule(new List <IParseRule>
            {
                new IdentifierRule(),
                new PlusOperatorRule(),
                new NumericalLiteralRule()
            });

            var t_Expression = t_Rule.Match(CreateState(
                                                new Token(TokenType.Identifier, "RAM"),
                                                new Token(TokenType.Operator, "+"),
                                                new Token(TokenType.Literal, "4")));

            t_Expression
            .HasError()
            .Should()
            .BeFalse();

            var t_Expressions = t_Expression.Value.Expressions;

            t_Expressions
            .Should()
            .HaveCount(3);

            t_Expressions.ToList()[0].Should()
            .BeOfType <IdentifierExpression>();
            t_Expressions.ToList()[1].Should()
            .BeOfType <PlusOperatorExpression>();
            t_Expressions.ToList()[2].Should()
            .BeOfType <NumericalLiteralExpression>();
        }
Beispiel #2
0
        public void ParseInvalidAddressWithOffset()
        {
            var t_Rule = new RulePatternRule(new List <IParseRule>
            {
                new IdentifierRule(),
                new PlusOperatorRule(),
                new NumericalLiteralRule()
            });

            var t_Expression = t_Rule.Match(CreateState(
                                                new Token(TokenType.Identifier, "RAM"),
                                                new Token(TokenType.Operator, ","),
                                                new Token(TokenType.Literal, "4")));

            t_Expression
            .HasError()
            .Should()
            .BeTrue();
        }
Beispiel #3
0
        public void ParseTrivialMathExpression()
        {
            var t_RepeatRule = new RepeatRule(new List <IParseRule>
            {
                new MultiAttemptRule(new List <IParseRule>
                {
                    new OperatorRule("+"),
                    new OperatorRule("-"),
                    new OperatorRule("*"),
                    new OperatorRule("/"),
                    new OperatorRule("^")
                }),
                new NumericalLiteralRule()
            });

            var t_PatternRule = new RulePatternRule(new List <IParseRule>
            {
                new NumericalLiteralRule(),
                t_RepeatRule
            });

            var t_Expression = t_PatternRule.Match(CreateState(
                                                       new Token(TokenType.Literal, "2"),
                                                       new Token(TokenType.Operator, "+"),
                                                       new Token(TokenType.Literal, "3"),
                                                       new Token(TokenType.Operator, "-"),
                                                       new Token(TokenType.Literal, "4"),
                                                       new Token(TokenType.Operator, "*"),
                                                       new Token(TokenType.Literal, "5"),
                                                       new Token(TokenType.Operator, "/"),
                                                       new Token(TokenType.Literal, "6")));

            t_Expression.HasError().Should().BeFalse();

            var t_Expressions = t_Expression.Value.Expressions;

            t_Expressions.Should().HaveCount(9);
        }