Beispiel #1
0
        ASTNode ASSERT()
        {
            var node = new AssertNode();

            node.lexeme = Consume("assert", TokenType.KEYWORD);
            Consume("(", TokenType.SEPARATOR);
            node.condition = EXPR();
            Consume(")", TokenType.SEPARATOR);
            return(node);
        }
Beispiel #2
0
        public void VisitAssert(AssertNode an)
        {
            int    temp   = this.depth;
            string spaces = IncreaseDepth();

            this.io.WriteLine($"{spaces}Assert: (");
            an.Expression.Visit(this);
            this.io.WriteLine($"{spaces})");
            this.depth = temp;
        }
Beispiel #3
0
        public void VisitAssert(AssertNode an)
        {
            UnaryOperandNode node = an.Expression.Visit(this);

            if (node.Type == SymbolType.Boolean && node.Value == "false")
            {
                UnaryOperandNode left  = an.Expression.Left.Visit(this);
                UnaryOperandNode right = an.Expression.Right.Visit(this);
                string           op;
                string           message = "Assert was false.";
                if (right.Type != SymbolType.Invalid)
                {
                    // BinaryExpression
                    op      = an.Expression.Operator;
                    message = $"Assert was false. Received assert ({left.Value} {op} {right.Value})";
                }
                throw new Error(message, node.Token);
            }
            if (node.Type != SymbolType.Boolean)
            {
                throw new Error($"Expected Boolean value inside assert (Boolean). Instead found {node.Type}", node.Token);
            }
        }