Ejemplo n.º 1
0
        public void Visit(FunctionInvocationNode functionInvocationNode)
        {
            switch (functionInvocationNode.Function)
            {
            case ScreenExitFunction screenExitFunction:
            {
                if (!abstractSyntaxTree.TryRetrieveGameObject(screenExitFunction.ConnectedScreenIdentifier))
                {
                    DazelLogger.EmitError(
                        $"Screen {string.Join(".", screenExitFunction.ConnectedScreenIdentifier)} does not exist.", functionInvocationNode.Token);
                }
                break;
            }

            case ExitFunction exitFunction:
                exitFunction.MemberAccessNode.Accept(this);
                break;

            case PrintFunction printFunction:
                printFunction.Log();
                break;
            }

            foreach (ValueNode valueNode in functionInvocationNode.Parameters)
            {
                if (valueNode is MemberAccessNode memberAccessNode)
                {
                    memberAccessNode.Accept(this);
                }
            }
        }
Ejemplo n.º 2
0
        public void Visit(ExitValueNode exitValueNode)
        {
            if (exitValueNode is TileExitValueNode tileExit)
            {
                DazelLogger.EmitWarning("TileExits have not been implemented yet.", tileExit.Token);
            }

            if (exitValueNode is ScreenExitValueNode screenExit)
            {
                screenModel.ScreenExits.Add(new ScreenExitModel(screenExit.ConnectedScreenIdentifier, screenExit.ExitDirection));
            }
        }
Ejemplo n.º 3
0
        public static VariableSymbolTableEntry AccessMember(MemberAccessNode memberAccessNode)
        {
            try
            {
                return(AccessMember(memberAccessNode.Identifiers));
            }
            catch
            {
                DazelLogger.EmitError($"Member not found in {memberAccessNode}", memberAccessNode.Token);
            }

            return(null);
        }
Ejemplo n.º 4
0
        public FunctionInvocationNode Setup()
        {
            if (DazelStdLib.TryGetFunction(Identifier, out Function function) && function.NumArguments == Parameters.Count)
            {
                Function = function;
                function.GetReturnType(Parameters);

                return(this);
            }

            DazelLogger.EmitError($"{Identifier} function not found in Dazel Standard Library.", Token);
            return(null);
        }
Ejemplo n.º 5
0
        protected void InvalidArgumentsException(IEnumerable <ValueNode> parameters)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"Invalid arguments in function {GetType()}:");

            foreach (ValueNode valueNode in parameters)
            {
                sb.AppendLine($"{valueNode}");
            }

            DazelLogger.EmitError(sb.ToString(), ValueNode.Token);
        }
Ejemplo n.º 6
0
        public Vector2 ToVector2()
        {
            if (Values.Count == 2)
            {
                IntValueNode x = Values[0] as IntValueNode;
                IntValueNode y = Values[1] as IntValueNode;

                return(new Vector2(x.Value, y.Value));
            }

            DazelLogger.EmitError($"Invalid number of arguments: {Values.Count}.", Token);

            return(Vector2.Zero);
        }
Ejemplo n.º 7
0
        public void Visit(SumExpressionNode sumExpressionNode)
        {
            if (sumExpressionNode.Left == null)
            {
                DazelLogger.EmitError("Expression left operand is null", sumExpressionNode.Token);
            }

            if (sumExpressionNode.Right == null)
            {
                DazelLogger.EmitError("Expression right operand is null", sumExpressionNode.Token);
            }

            sumExpressionNode.Left.Accept(this);
            sumExpressionNode.Right.Accept(this);
        }
Ejemplo n.º 8
0
        public void Visit(ExitValueNode exitValueNode)
        {
            if (exitValueNode is TileExitValueNode tileExit)
            {
                EnvironmentStore.AccessMember(tileExit.ToExit);
            }

            if (exitValueNode is ScreenExitValueNode screenExit)
            {
                if (!abstractSyntaxTree.TryRetrieveGameObject(screenExit.ConnectedScreenIdentifier))
                {
                    DazelLogger.EmitError(
                        $"Exit {screenExit} is invalid: {screenExit.ConnectedScreenIdentifier} does not exist.", screenExit.Token);
                }
            }
        }
Ejemplo n.º 9
0
        public void Visit(ArrayNode arrayNode)
        {
            typeHandler.SetType(arrayNode.Type, arrayNode.Token);

            SymbolType valueType = arrayNode.Values[0].Type;

            foreach (ValueNode value in arrayNode.Values)
            {
                if (value.Type == valueType)
                {
                    valueType = value.Type;
                }
                else
                {
                    DazelLogger.EmitError($"Type mismatch. {value} is not {typeHandler.CurrentType}", value.Token);
                }
            }
        }
Ejemplo n.º 10
0
        public override ValueNode GetReturnType(List <ValueNode> parameters)
        {
            foreach (ValueNode valueNode in parameters)
            {
                if (valueNode.Type != SymbolType.Integer)
                {
                    DazelLogger.EmitError("Invalid type.", valueNode.Token);
                }
            }

            if (parameters[0] is IntValueNode width && parameters[1] is IntValueNode height)
            {
                Width  = width.Value;
                Height = height.Value;
            }

            return(null);
        }
Ejemplo n.º 11
0
 public void Log()
 {
     if (ValueNode is IdentifierValueNode identifierValueNode)
     {
         if (CurrentSymbolTable.symbols.TryGetValue(identifierValueNode.Identifier, out SymbolTableEntry symbolTableEntry))
         {
             DazelLogger.EmitMessage(symbolTableEntry.ToString(), ValueNode.Token);
         }
         else
         {
             DazelLogger.EmitWarning("null", ValueNode.Token);
         }
     }
     else
     {
         DazelLogger.EmitMessage(ValueNode.ToString(), ValueNode.Token);
     }
 }
Ejemplo n.º 12
0
        public void SetType(SymbolType value, IToken token)
        {
            if (CurrentType == SymbolType.Exit)
            {
                DazelLogger.EmitError("Exits cannot be used in expressions.", token);
            }

            if (CurrentType == SymbolType.Null || CurrentType == SymbolType.Integer && (value == SymbolType.Float || value == SymbolType.Integer))
            {
                CurrentType = value;
                return;
            }

            if (CurrentType == SymbolType.Float && value == SymbolType.Integer)
            {
                return;
            }

            DazelLogger.EmitError($"Type mismatch. {value} is not {CurrentType}", token);
        }
Ejemplo n.º 13
0
        public void Visit(SumExpressionNode sumExpressionNode)
        {
            sumExpressionNode.Left.Accept(this);
            T a = Result;

            sumExpressionNode.Right.Accept(this);
            T b = Result;

            switch (sumExpressionNode.OperationNode.Operator)
            {
            case Operators.AddOp:
                Result = Calculator.Add(a, b);
                break;

            case Operators.MinOp:
                Result = Calculator.Subtract(a, b);
                break;

            default:
                DazelLogger.EmitError($"Operation {sumExpressionNode.OperationNode.Operator} is not valid.", sumExpressionNode.Token);
                break;
            }
        }
Ejemplo n.º 14
0
        public void Visit(FactorExpressionNode factorExpressionNode)
        {
            factorExpressionNode.Left.Accept(this);
            T a = Result;

            factorExpressionNode.Right.Accept(this);
            T b = Result;

            switch (factorExpressionNode.OperationNode.Operator)
            {
            case Operators.MultOp:
                Result = Calculator.Multiply(a, b);
                break;

            case Operators.DivOp:
                Result = Calculator.Divide(a, b);
                break;

            default:
                DazelLogger.EmitError($"Operation {factorExpressionNode.OperationNode.Operator} is not valid.", factorExpressionNode.Token);
                break;
            }
        }
Ejemplo n.º 15
0
        public void Visit(IdentifierValueNode identifierValueNode)
        {
            SymbolTableEntry entry;

            try
            {
                entry = symbolTable.RetrieveSymbolInParentScope(identifierValueNode.Identifier);
            }
            catch (Exception e)
            {
                DazelLogger.EmitError(e.Message, identifierValueNode.Token);
                return;
            }

            if (entry is VariableSymbolTableEntry variableSymbolTableEntry)
            {
                ExpressionNode expression = variableSymbolTableEntry.ValueNode;
                SetNumericalExpression(identifierValueNode, expression, entry.Type);
            }

            SymbolTableEntry symbolTableEntry = symbolTable.RetrieveSymbolInParentScope(identifierValueNode.Identifier);

            typeHandler.SetType(symbolTableEntry.Type, identifierValueNode.Token);
        }
Ejemplo n.º 16
0
        public override string GetValue(ExitValueNode a)
        {
            DazelLogger.EmitError("Exits cannot be used as strings.", Token);

            return(null);
        }
Ejemplo n.º 17
0
        public override ExitValueNode Divide(ExitValueNode a, ExitValueNode b)
        {
            DazelLogger.EmitError("Cannot divide exits.", Token);

            return(null);
        }
Ejemplo n.º 18
0
        public override ArrayNode GetValue(string a)
        {
            DazelLogger.EmitError($"String {a} is not an array.", Token);

            return(null);
        }
Ejemplo n.º 19
0
        public override ArrayNode GetValue(ExitValueNode a)
        {
            DazelLogger.EmitError("ExitValue is not an array.", Token);

            return(null);
        }
Ejemplo n.º 20
0
        public override ArrayNode GetValue(int a)
        {
            DazelLogger.EmitError($"Integer {a} is not an array.", Token);

            return(null);
        }
Ejemplo n.º 21
0
        public override ArrayNode GetValue(float a)
        {
            DazelLogger.EmitError($"Float {a} is not an array.", Token);

            return(null);
        }
Ejemplo n.º 22
0
        public override ArrayNode Multiply(ArrayNode a, ArrayNode b)
        {
            DazelLogger.EmitError("Cannot multiply arrays.", Token);

            return(null);
        }
Ejemplo n.º 23
0
        public override ArrayNode Divide(ArrayNode a, ArrayNode b)
        {
            DazelLogger.EmitError("Cannot divide arrays.", Token);

            return(null);
        }
Ejemplo n.º 24
0
        public override ExitValueNode Subtract(ExitValueNode a, ExitValueNode b)
        {
            DazelLogger.EmitError("Cannot subtract exits.", Token);

            return(null);
        }
Ejemplo n.º 25
0
        public override ArrayNode Subtract(ArrayNode a, ArrayNode b)
        {
            DazelLogger.EmitError("Cannot subtract arrays.", Token);

            return(null);
        }
Ejemplo n.º 26
0
        public override ExitValueNode GetValue(ArrayNode a)
        {
            DazelLogger.EmitError($"Array is not an exit.", Token);

            return(null);
        }
Ejemplo n.º 27
0
        public override ExitValueNode GetValue(string a)
        {
            DazelLogger.EmitError($"String {a} is not an exit.", Token);

            return(null);
        }
Ejemplo n.º 28
0
        public override ExitValueNode GetValue(float a)
        {
            DazelLogger.EmitError($"Float {a} is not an exit.", Token);

            return(null);
        }
Ejemplo n.º 29
0
        public override ExitValueNode GetValue(int a)
        {
            DazelLogger.EmitError($"Integer {a} is not an exit.", Token);

            return(null);
        }
Ejemplo n.º 30
0
        public override ExitValueNode Multiply(ExitValueNode a, ExitValueNode b)
        {
            DazelLogger.EmitError("Cannot multiply exits.", Token);

            return(null);
        }