Example #1
0
        public void Visit(FunctionInvocationNode functionInvocationNode)
        {
            functionInvocationNode.Function.CurrentSymbolTable = CurrentScope;
            FunctionSymbolTableEntry entry = new FunctionSymbolTableEntry(functionInvocationNode.ReturnType, functionInvocationNode.Parameters);

            CurrentScope.AddOrUpdateSymbol(functionInvocationNode.Identifier, entry);
        }
Example #2
0
        public void Visit(AssignmentNode assignmentNode)
        {
            SymbolType expressionType = new ExpressionTypeChecker(CurrentScope).GetType(assignmentNode.Expression);
            ValueNode  expressionValue;

            switch (expressionType)
            {
            case SymbolType.Null:
                expressionValue = null;
                break;

            case SymbolType.Float:
                var floatEval = new ExpressionEvaluator <float>(new FloatCalculator(assignmentNode.Token));
                assignmentNode.Expression.Accept(floatEval);
                expressionValue = new FloatValueNode()
                {
                    Value = floatEval.Result
                };
                break;

            case SymbolType.String:
                var stringEval = new ExpressionEvaluator <string>(new StringOperations(assignmentNode.Token));
                assignmentNode.Expression.Accept(stringEval);
                expressionValue = new StringNode()
                {
                    Value = stringEval.Result
                };
                break;

            case SymbolType.Integer:
                var intEval = new ExpressionEvaluator <int>(new IntCalculator(assignmentNode.Token));
                assignmentNode.Expression.Accept(intEval);
                expressionValue = new FloatValueNode()
                {
                    Value = intEval.Result
                };
                break;

            case SymbolType.Array:
                var arrayEval = new ExpressionEvaluator <ArrayNode>(new ArrayCalculator(assignmentNode.Token));
                assignmentNode.Expression.Accept(arrayEval);
                expressionValue = arrayEval.Result;
                break;

            case SymbolType.Exit:
                var exitEval = new ExpressionEvaluator <ExitValueNode>(new ExitValueCalculator(assignmentNode.Token));
                assignmentNode.Expression.Accept(exitEval);
                expressionValue = exitEval.Result;
                break;

            case SymbolType.Identifier:
                var idEval = new ExpressionEvaluator <ValueNode>(new NoOpCalculator <ValueNode>(assignmentNode.Token));
                assignmentNode.Expression.Accept(idEval);
                expressionValue = idEval.Result;
                break;

            case SymbolType.MemberAccess:
                expressionValue = (ValueNode)assignmentNode.Expression;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            assignmentNode.Expression = expressionValue;

            VariableSymbolTableEntry entry = new VariableSymbolTableEntry(expressionValue, expressionType);

            CurrentScope.AddOrUpdateSymbol(assignmentNode.Identifier, entry);
        }