예제 #1
0
        public void TypeCheck_Visit_AssignNullFunctionToVariableAllowed()
        {
            AbstractSyntaxTree ast = TestAstBuilder.BuildAst(TestCode7);

            Assert.DoesNotThrow(() => TestDelegate(ast));

            List <string> variablePath = new List <string>()
            {
                "SampleScreen1", "Map", "x"
            };

            ValueNode value = EnvironmentStore.AccessMember(variablePath).ValueNode;

            Assert.That(value == null);
        }
예제 #2
0
        public void TypeCheck_Visit_IntegerPlusFloatSucceeds()
        {
            AbstractSyntaxTree ast = TestAstBuilder.BuildAst(TestCode9);

            Assert.DoesNotThrow(() => TestDelegate(ast));

            List <string> variablePathX = new List <string>()
            {
                "SampleScreen1", "Map", "x"
            };
            List <string> variablePathY = new List <string>()
            {
                "SampleScreen1", "Map", "y"
            };

            ValueNode valueX = EnvironmentStore.AccessMember(variablePathX).ValueNode;
            ValueNode valueY = EnvironmentStore.AccessMember(variablePathY).ValueNode;

            Assert.That(valueX != null, "valueX != null");
            Assert.That(valueX is FloatValueNode {
                Value: 2.5f
            }, "valueX != null");
        public override void Visit(MemberAccessNode memberAccessNode)
        {
            ValueNode member = EnvironmentStore.AccessMember(memberAccessNode).ValueNode;

            switch (member)
            {
            case ArrayNode arrayNode:
                Result = Calculator.GetValue(arrayNode);
                break;

            case IntValueNode intValueNode:
                Result = Calculator.GetValue(intValueNode.Value);
                break;

            case StringNode stringNode:
                Result = Calculator.GetValue(stringNode.Value);
                break;

            case FloatValueNode floatValueNode:
                Result = Calculator.GetValue(floatValueNode.Value);
                break;
            }
        }