コード例 #1
0
 public void Visit(NotExpr node)
 {
     VisitChildren (node.Children [0]);
     string type = TypeStack.Pop ();
     if (type != "Bool") {
         throw new SemanticError ("Operator " + node.Name + " can not be applied to operand of type: " +
             type, node.Children [0].Row, node.Children [0].Column);
     }
 }
コード例 #2
0
        public void Visit(NotExpr node)
        {
            VisitChildren (node.Children [0]);
            StackValue boolean = ValueStack.Pop ();

            // change true to false and false to true and push it to the stack
            if (boolean.Value == "true") {
                boolean.Value = "false";
            } else {
                boolean.Value = "true";
            }

            ValueStack.Push (boolean);
        }
コード例 #3
0
        private Expression Expr()
        {
            Expression expr = new Expression ("expr", currentToken.Row, currentToken.Column);
            if ((Token.Types)currentToken.Type == Token.Types.LeftParenthesis ||
                (Token.Types)currentToken.Type == Token.Types.IntLiteral ||
                (Token.Types)currentToken.Type == Token.Types.StringLiteral ||
                (Token.Types)currentToken.Type == Token.Types.Identifier ||
                (Token.Types)currentToken.Type == Token.Types.BoolLiteral) {

                Expression left = Conjuct ();
                Expression right = ExprLogical ();

                if (right.Name != null) {
                    right.AddChild (left);
                    expr.AddChild (right);
                    return expr;
                } else {
                    expr.AddChild (left);
                    return expr;
                }
            } else if ((Token.Types)currentToken.Type == Token.Types.Not) {
                NotExpr notExpr = new NotExpr ("!", currentToken.Row, currentToken.Column);
                Match (Token.Types.Not);
                notExpr.AddChild (Expr ());
                return notExpr;
            }

            throw new SyntaxError ("invalid token to start expression " + currentToken.Type,
            currentToken.Row, currentToken.Column);
        }