Exemple #1
0
        public BoolExpr(BoolToken token, IEnv env)
            : base(env)
        {
            if (token == null)
            {
                throw new ArgumentNullException(nameof(token));
            }

            base.Token = token;
        }
Exemple #2
0
    private bool ShouldUnstack(BoolToken boolToken, Token topOperator)
    {
        if (topOperator == null ||
            topOperator is TargetToken ||
            topOperator is OpenParenthesisToken
            )
        {
            return(false);
        }
        if (!(topOperator is BoolToken))
        {
            throw new LexingException("Somehow an invalid Token type ended up on the operators stack. Good job Connor.");
        }

        // Not bothering with an actual precedence as there are only two operators
        return(!(boolToken.value == BoolToken.Type.AND && (topOperator as BoolToken).value == BoolToken.Type.OR));
    }
Exemple #3
0
        }//Done

        protected ValueToken CompareOps()
        {
            ValueToken left = PlusMinusOps();

            while ((CurrentToken.GetTokenType == TokenType.MORE) || (CurrentToken.GetTokenType == TokenType.LESS) || (CurrentToken.GetTokenType == TokenType.EQUAL_BOOL) || (CurrentToken.GetTokenType == TokenType.NOT_EQUAL))
            {
                if (CurrentToken.GetTokenType == TokenType.MORE)
                {
                    Eat(TokenType.MORE);
                    ValueToken right = PlusMinusOps();
                    if (left is IntegerToken)
                    {
                        if (right is IntegerToken)
                        {
                            left = new BoolToken((left as IntegerToken) > (right as IntegerToken));
                        }
                        else if (right is DoubleToken)
                        {
                            left = new BoolToken((left as IntegerToken) > (right as DoubleToken));
                        }
                        else if (right is CharToken)
                        {
                            left = new BoolToken((left as IntegerToken) > (right as CharToken));//!!!!!!!!!!!!!!!!!
                        }
                        else
                        {
                            Error("Error in CompareExpr: wrong value type");
                        }
                    }
                    else if (left is DoubleToken)
                    {
                        if (right is IntegerToken)
                        {
                            left = new BoolToken((left as DoubleToken) > (right as IntegerToken));
                        }
                        else if (right is DoubleToken)
                        {
                            left = new BoolToken((left as DoubleToken) > (right as DoubleToken));
                        }
                        else
                        {
                            Error("Error in CompareExpr: wrong value type");
                        }
                    }
                    else if (left is CharToken)
                    {
                        if (right is CharToken)
                        {
                            left = new BoolToken((left as CharToken) > (right as CharToken));
                        }
                        else if (right is IntegerToken)
                        {
                            left = new BoolToken((left as CharToken) > (right as IntegerToken));
                        }
                        else
                        {
                            Error("Error in CompareExpr: wrong value type");
                        }
                    }
                    else
                    {
                        Error("Error in CompareExpr: wrong value type");
                    }
                }
                else if (CurrentToken.GetTokenType == TokenType.LESS)
                {
                    Eat(TokenType.LESS);
                    ValueToken right = PlusMinusOps();
                    if (left is IntegerToken)
                    {
                        if (right is IntegerToken)
                        {
                            left = new BoolToken((left as IntegerToken) < (right as IntegerToken));
                        }
                        else if (right is DoubleToken)
                        {
                            left = new BoolToken((left as IntegerToken) < (right as DoubleToken));
                        }
                        else if (right is CharToken)
                        {
                            left = new BoolToken((left as IntegerToken) < (right as CharToken));
                        }
                        else
                        {
                            Error("Error in CompareExpr: wrong value type");
                        }
                    }
                    else if (left is DoubleToken)
                    {
                        if (right is IntegerToken)
                        {
                            left = new BoolToken((left as DoubleToken) < (right as IntegerToken));
                        }
                        else if (right is DoubleToken)
                        {
                            left = new BoolToken((left as DoubleToken) < (right as DoubleToken));
                        }
                        else
                        {
                            Error("Error in CompareExpr: wrong value type");
                        }
                    }
                    else if (left is CharToken)
                    {
                        if (right is CharToken)
                        {
                            left = new BoolToken((left as CharToken) > (right as CharToken));
                        }
                        else if (right is IntegerToken)
                        {
                            left = new BoolToken((left as CharToken) > (right as IntegerToken));
                        }
                        else
                        {
                            Error("Error in CompareExpr: wrong value type");
                        }
                    }
                    else
                    {
                        Error("Error in CompareExpr: wrong value type");
                    }
                }
                else if (CurrentToken.GetTokenType == TokenType.EQUAL_BOOL)
                {
                    Eat(TokenType.EQUAL_BOOL);
                    ValueToken right = PlusMinusOps();
                    if (left is IntegerToken)
                    {
                        if (right is IntegerToken)
                        {
                            left = new BoolToken((left as IntegerToken) == (right as IntegerToken));
                        }
                        else if (right is DoubleToken)
                        {
                            left = new BoolToken((left as IntegerToken) == (right as DoubleToken));
                        }
                        else if (right is CharToken)
                        {
                            left = new BoolToken((left as IntegerToken) == (right as CharToken));
                        }
                        else
                        {
                            Error("Error in CompareExpr: wrong value type");
                        }
                    }
                    else if (left is DoubleToken)
                    {
                        if (right is IntegerToken)
                        {
                            left = new BoolToken((left as DoubleToken) == (right as IntegerToken));
                        }
                        else if (right is DoubleToken)
                        {
                            left = new BoolToken((left as DoubleToken) == (right as DoubleToken));
                        }
                        else
                        {
                            Error("Error in CompareExpr: wrong value type");
                        }
                    }
                    else if (left is CharToken)
                    {
                        if (right is CharToken)
                        {
                            left = new BoolToken((left as CharToken) == (right as CharToken));
                        }
                        else if (right is IntegerToken)
                        {
                            left = new BoolToken((left as CharToken) == (right as IntegerToken));
                        }
                        else
                        {
                            Error("Error in CompareExpr: wrong value type");
                        }
                    }
                    else if (left is BoolToken)
                    {
                        if (right is BoolToken)
                        {
                            left = new BoolToken((left as BoolToken) == (right as BoolToken));
                        }
                        else
                        {
                            Error("Error in CompareExpr: wrong value type");
                        }
                    }
                    else if (left is StringToken)
                    {
                        if (right is StringToken)
                        {
                            left = new BoolToken((left as StringToken) == (right as StringToken));
                        }
                    }
                }
                else if (CurrentToken.GetTokenType == TokenType.NOT_EQUAL)
                {
                    Eat(TokenType.NOT_EQUAL);
                    ValueToken right = PlusMinusOps();
                    if (left is IntegerToken)
                    {
                        if (right is IntegerToken)
                        {
                            left = new BoolToken((left as IntegerToken) != (right as IntegerToken));
                        }
                        else if (right is DoubleToken)
                        {
                            left = new BoolToken((left as IntegerToken) != (right as DoubleToken));
                        }
                        else if (right is CharToken)
                        {
                            left = new BoolToken((left as IntegerToken) != (right as CharToken));
                        }
                        else
                        {
                            Error("Error in CompareExpr: wrong value type");
                        }
                    }
                    else if (left is DoubleToken)
                    {
                        if (right is IntegerToken)
                        {
                            left = new BoolToken((left as DoubleToken) != (right as IntegerToken));
                        }
                        else if (right is DoubleToken)
                        {
                            left = new BoolToken((left as DoubleToken) != (right as DoubleToken));
                        }
                        else
                        {
                            Error("Error in CompareExpr: wrong value type");
                        }
                    }
                    else if (left is CharToken)
                    {
                        if (right is CharToken)
                        {
                            left = new BoolToken((left as CharToken) != (right as CharToken));
                        }
                        else if (right is IntegerToken)
                        {
                            left = new BoolToken((left as CharToken) != (right as IntegerToken));
                        }
                        else
                        {
                            Error("Error in CompareExpr: wrong value type");
                        }
                    }
                    else if (left is BoolToken)
                    {
                        if (right is BoolToken)
                        {
                            left = new BoolToken((left as BoolToken) != (right as BoolToken));
                        }
                        else
                        {
                            Error("Error in CompareExpr: wrong value type");
                        }
                    }
                    else if (left is StringToken)
                    {
                        if (right is StringToken)
                        {
                            left = new BoolToken((left as StringToken) != (right as StringToken));
                        }
                    }
                }
            }
            return(left);
        }//Done
Exemple #4
0
 public BoolExpression(BoolToken boolToken, ExpressionNode lhs, ExpressionNode rhs)
 {
     this.boolToken = boolToken;
     this.lhs       = lhs;
     this.rhs       = rhs;
 }
Exemple #5
0
 public BoolAST(BoolToken token)
 {
     ReferenceToken = token;
     Bool           = (bool)token.Value;
 }
Exemple #6
0
 public ConstantBoolExpressionToken(BoolToken token)
     : base(token.StringValue)
 {
     Token = token ?? throw new ArgumentNullException(nameof(token));
 }